1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.openr66.dao;
22
23 import org.waarp.common.database.ConnectionFactory;
24 import org.waarp.openr66.dao.database.DBDAOFactory;
25 import org.waarp.openr66.dao.exception.DAOConnectionException;
26 import org.waarp.openr66.dao.xml.XMLDAOFactory;
27
28 import javax.xml.XMLConstants;
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import javax.xml.parsers.ParserConfigurationException;
31 import javax.xml.stream.XMLInputFactory;
32
33
34
35
36 public abstract class DAOFactory {
37
38 private static DAOFactory instance;
39
40 public static void initialize() {
41 if (instance == null) {
42 instance = new XMLDAOFactory();
43 }
44 }
45
46 public static void initialize(final ConnectionFactory factory) {
47 if (instance == null) {
48 instance = new DBDAOFactory(factory);
49 }
50 }
51
52 public static DAOFactory getInstance() {
53 return instance;
54 }
55
56
57
58
59
60
61 public static void setInstanceTestOnly(DAOFactory daoFactory) {
62 instance = daoFactory;
63 }
64
65
66
67
68
69
70 public static DocumentBuilderFactory getDocumentBuilderFactory() {
71 final DocumentBuilderFactory factory =
72 DocumentBuilderFactory.newInstance();
73
74 try {
75 factory.setFeature(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
76 Boolean.FALSE);
77 } catch (final ParserConfigurationException ignored) {
78
79 } catch (final AbstractMethodError ignored) {
80
81 }
82 try {
83 factory.setFeature(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
84 } catch (final ParserConfigurationException ignored) {
85
86 } catch (final AbstractMethodError ignored) {
87
88 }
89 try {
90 factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
91 } catch (final ParserConfigurationException ignored) {
92
93 } catch (final AbstractMethodError ignored) {
94
95 }
96 return factory;
97 }
98
99
100
101
102
103
104 public static void closeDAO(final AbstractDAO<?> dao) {
105 if (dao != null) {
106 dao.close();
107 }
108 }
109
110
111
112
113 public int getMaxConnections() {
114 return 1000;
115 }
116
117
118
119
120
121
122
123
124
125
126 public abstract BusinessDAO getBusinessDAO(final boolean isCacheable)
127 throws DAOConnectionException;
128
129
130
131
132
133
134
135
136
137
138 public abstract HostDAO getHostDAO(final boolean isCacheable)
139 throws DAOConnectionException;
140
141
142
143
144
145
146
147
148
149
150 public abstract LimitDAO getLimitDAO(final boolean isCacheable)
151 throws DAOConnectionException;
152
153
154
155
156
157
158
159
160
161
162 public abstract MultipleMonitorDAO getMultipleMonitorDAO(
163 final boolean isCacheable) throws DAOConnectionException;
164
165
166
167
168
169
170
171
172
173
174 public abstract RuleDAO getRuleDAO(final boolean isCacheable)
175 throws DAOConnectionException;
176
177
178
179
180
181
182
183
184 public abstract TransferDAO getTransferDAO() throws DAOConnectionException;
185
186
187
188
189
190
191
192
193 public abstract String getLimitRequest(final String request, final int limit,
194 final int offset);
195 }