Skip to contentMethod: TransactionalProcessor()
1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.thesefoolishthings.examples.dci.persistable.jpa;
28:
29: import javax.annotation.Nonnull;
30: import java.util.List;
31: import java.util.Optional;
32: import javax.transaction.Transactional;
33: import it.tidalwave.util.AsExtensions;
34: import it.tidalwave.util.Id;
35: import it.tidalwave.thesefoolishthings.examples.person.Person;
36: import lombok.experimental.ExtensionMethod;
37: import static it.tidalwave.thesefoolishthings.examples.dci.persistable.jpa.role.Findable._Findable_;
38: import static it.tidalwave.role.io.Persistable._Persistable_;
39:
40: /***********************************************************************************************************************
41: *
42: * @author Fabrizio Giudici
43: *
44: **********************************************************************************************************************/
45: @ExtensionMethod(AsExtensions.class)
46: public class TransactionalProcessor
47: {
48: @Transactional
49: public void persistPeople (@Nonnull final Iterable<Person> persons)
50: throws Exception
51: {
52: persons.forEach(person -> person.as(_Persistable_).persist());
53: }
54:
55: // @Transactional
56: // public void removePeople (@Nonnull final Iterable<Person> persons)
57: // throws Exception
58: // {
59: // persons.forEach(_r(person -> person.as(_Removable_).remove()));
60: // }
61:
62: @Transactional @Nonnull
63: public List<Person> retrievePeople()
64: {
65: return Person.prototype().as(_Findable_).findAll();
66: }
67:
68: @Transactional @Nonnull
69: public Optional<Person> retrievePerson (@Nonnull final Id id)
70: {
71: return Person.prototype().as(_Findable_).findById(id);
72: }
73: }