1 | |
package org.jtheque.primary.services.impl; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.core.managers.persistence.able.DataListener; |
20 | |
import org.jtheque.primary.dao.able.IDaoCountries; |
21 | |
import org.jtheque.primary.od.able.Country; |
22 | |
import org.jtheque.primary.services.able.ICountriesService; |
23 | |
import org.springframework.stereotype.Service; |
24 | |
import org.springframework.transaction.annotation.Transactional; |
25 | |
|
26 | |
import javax.annotation.Resource; |
27 | |
import java.util.Collection; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
@Service |
35 | 0 | public final class CountriesService implements ICountriesService { |
36 | |
private Country defaultCountry; |
37 | |
|
38 | |
@Resource |
39 | |
private IDaoCountries daoCountries; |
40 | |
|
41 | |
@Override |
42 | |
public Country getDefaultCountry() { |
43 | 0 | if (defaultCountry == null) { |
44 | 0 | defaultCountry = daoCountries.getCountry("USA"); |
45 | |
|
46 | 0 | if (defaultCountry == null) { |
47 | 0 | createDefaultCountry(); |
48 | |
} |
49 | |
} |
50 | |
|
51 | 0 | return defaultCountry; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@Transactional |
58 | |
private void createDefaultCountry() { |
59 | 0 | defaultCountry = daoCountries.createCountry(); |
60 | 0 | defaultCountry.setName("USA"); |
61 | 0 | daoCountries.create(defaultCountry); |
62 | 0 | } |
63 | |
|
64 | |
@Override |
65 | |
@Transactional |
66 | |
public void save(Country country) { |
67 | 0 | daoCountries.save(country); |
68 | 0 | } |
69 | |
|
70 | |
@Override |
71 | |
@Transactional |
72 | |
public void create(Country country) { |
73 | 0 | daoCountries.create(country); |
74 | 0 | } |
75 | |
|
76 | |
@Override |
77 | |
@Transactional |
78 | |
public boolean delete(Country country) { |
79 | 0 | return daoCountries.delete(country); |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public Collection<Country> getCountries() { |
84 | 0 | return daoCountries.getCountries(); |
85 | |
} |
86 | |
|
87 | |
@Override |
88 | |
public Country getCountry(String name) { |
89 | 0 | return daoCountries.getCountry(name); |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
@Transactional |
94 | |
public void createAll(Iterable<Country> countries) { |
95 | 0 | for (Country country : countries) { |
96 | 0 | daoCountries.create(country); |
97 | |
} |
98 | 0 | } |
99 | |
|
100 | |
@Override |
101 | |
public boolean exist(Country country) { |
102 | 0 | return daoCountries.exist(country); |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public Country getEmptyCountry() { |
107 | 0 | return daoCountries.createCountry(); |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
public boolean exist(String name) { |
112 | 0 | return getCountry(name) != null; |
113 | |
} |
114 | |
|
115 | |
@Override |
116 | |
public Collection<Country> getDatas() { |
117 | 0 | return getCountries(); |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public void addDataListener(DataListener listener) { |
122 | 0 | daoCountries.addDataListener(listener); |
123 | 0 | } |
124 | |
|
125 | |
@Override |
126 | |
@Transactional |
127 | |
public void clearAll() { |
128 | 0 | daoCountries.clearAll(); |
129 | 0 | } |
130 | |
|
131 | |
@Override |
132 | |
public String getDataType() { |
133 | 0 | return DATA_TYPE; |
134 | |
} |
135 | |
} |