Skip to contentPackage: Main
Main
Coverage
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.jpafinderexample;
28:
29: import javax.annotation.Nonnull;
30: import java.util.List;
31: import it.tidalwave.util.As;
32: import it.tidalwave.util.AsExtensions;
33: import it.tidalwave.thesefoolishthings.examples.jpafinderexample.impl.JpaPersonRegistry;
34: import it.tidalwave.thesefoolishthings.examples.jpafinderexample.role.Findable;
35: import it.tidalwave.thesefoolishthings.examples.person.Person;
36: import it.tidalwave.thesefoolishthings.examples.person.PersonRegistryHelper;
37: import lombok.experimental.ExtensionMethod;
38: import lombok.extern.slf4j.Slf4j;
39: import static it.tidalwave.thesefoolishthings.examples.jpafinderexample.PersonRegistry3.*;
40: import static it.tidalwave.thesefoolishthings.examples.jpafinderexample.role.Findable._Findable_;
41: import static it.tidalwave.util.Finder.SortDirection.DESCENDING;
42:
43: /***********************************************************************************************************************
44: *
45: * @author Fabrizio Giudici
46: *
47: **********************************************************************************************************************/
48: @ExtensionMethod(AsExtensions.class)
49: @Slf4j
50: public class Main
51: {
52: private static final As.Type<Findable<Person>> _Findable_of_Person_ = As.type(_Findable_);
53:
54: public static void main (@Nonnull final String... args)
55: throws Exception
56: {
57: try (final TxManager txManager = TxManager.getInstance())
58: {
59: final PersonRegistry3 registry = new JpaPersonRegistry(txManager);
60: PersonRegistryHelper.populate(registry);
61:
62: final List<? extends Person> p1 = registry.findPerson().results();
63: log.info("******** All: {}", p1);
64:
65: final int n1 = registry.findPerson().count();
66: log.info("******** Count: {}", n1);
67:
68: final List<? extends Person> p2 = registry.findPerson().from(3).max(2).results();
69: log.info("******** wo persons from the 3rd position: {}", p2);
70:
71: final List<? extends Person> p3 = registry.findPerson().sort(BY_FIRST_NAME).results();
72: log.info("******** All, sorted by first name: {}", p3);
73:
74: final List<? extends Person> p4 = registry.findPerson().sort(BY_LAST_NAME, DESCENDING).results();
75: log.info("******** All, sorted by last name, descending: {}", p4);
76:
77: final List<? extends Person> p5 =
78: Person.prototype().as(_Findable_of_Person_).find()
79: .sort(BY_LAST_NAME, DESCENDING)
80: .from(2)
81: .max(3)
82: .results();
83: log.info("******** Three persons from the 2nd position, with Person.as(): {}", p5);
84: }
85: }
86: }