comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java @ 5531:ac48ab9e1715

Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 03 Apr 2013 12:54:34 +0200
parents cbd0fafcb26b
children 3e8f7b4bdf20
comparison
equal deleted inserted replaced
5530:7f8d6b49afad 5531:ac48ab9e1715
27 import de.intevation.artifacts.common.utils.XMLUtils; 27 import de.intevation.artifacts.common.utils.XMLUtils;
28 import de.intevation.artifacts.common.utils.StringUtils; 28 import de.intevation.artifacts.common.utils.StringUtils;
29 29
30 import de.intevation.flys.artifacts.FLYSArtifact; 30 import de.intevation.flys.artifacts.FLYSArtifact;
31 31
32 import de.intevation.flys.backend.SedDBSessionHolder;
32 import de.intevation.flys.backend.SessionHolder; 33 import de.intevation.flys.backend.SessionHolder;
33 34
34 import de.intevation.artifactdatabase.data.StateData; 35 import de.intevation.artifactdatabase.data.StateData;
35 36
36 import de.intevation.flys.artifacts.datacage.templating.Builder; 37 import de.intevation.flys.artifacts.datacage.templating.Builder;
39 /** 40 /**
40 * Also accessible as Singleton with getInstance(). 41 * Also accessible as Singleton with getInstance().
41 */ 42 */
42 public class Recommendations 43 public class Recommendations
43 { 44 {
45 public static final String CONNECTION_USER = "user";
46 public static final String CONNECTION_SYSTEM = "system";
47 public static final String CONNECTION_SEDDB = "seddb";
48
49 public static final String DEFAULT_CONNECTION_NAME = CONNECTION_SYSTEM;
50
44 private static Logger log = Logger.getLogger(Recommendations.class); 51 private static Logger log = Logger.getLogger(Recommendations.class);
45 52
46 private static final boolean DEVELOPMENT_MODE = 53 private static final boolean DEVELOPMENT_MODE =
47 Boolean.getBoolean("flys.datacage.recommendations.development"); 54 Boolean.getBoolean("flys.datacage.recommendations.development");
48 55
196 203
197 public void recommend( 204 public void recommend(
198 final Map<String, Object> parameters, 205 final Map<String, Object> parameters,
199 final String userId, 206 final String userId,
200 final Node result, 207 final Node result,
201 Session session 208 Session systemSession
202 ) { 209 ) {
203 session.doWork(new Work() { 210 systemSession.doWork(new Work() {
204 @Override 211 @Override
205 public void execute(Connection systemConnection) 212 public void execute(final Connection systemConnection)
206 throws SQLException 213 throws SQLException
207 { 214 {
208 List<Builder.NamedConnection> connections = 215 SedDBSessionHolder.HOLDER.get().doWork(new Work() {
209 new ArrayList<Builder.NamedConnection>(2); 216 @Override
210 217 public void execute(Connection sedDBConnection)
211 Connection userConnection = userId != null 218 throws SQLException
212 ? DBConfig 219 {
213 .getInstance() 220 recommend(
214 .getDBConnection() 221 parameters, userId, result,
215 .getDataSource() 222 systemConnection,
216 .getConnection() 223 sedDBConnection);
217 : null;
218
219 try {
220 if (userConnection != null) {
221 connections.add(new Builder.NamedConnection(
222 Builder.CONNECTION_USER, userConnection, false));
223 } 224 }
224 225 });
225 connections.add(new Builder.NamedConnection(
226 Builder.CONNECTION_SYSTEM, systemConnection, true));
227
228 getBuilder().build(connections, result, parameters);
229 }
230 finally {
231 if (userConnection != null) {
232 userConnection.close();
233 }
234 }
235 } 226 }
236 }); 227 });
237 } 228 }
238 229
230 public void recommend(
231 Map<String, Object> parameters,
232 String userId,
233 Node result,
234 Connection systemConnection,
235 Connection seddbConnection
236 ) throws SQLException
237 {
238 List<Builder.NamedConnection> connections =
239 new ArrayList<Builder.NamedConnection>(3);
240
241 Connection userConnection = userId != null
242 ? DBConfig
243 .getInstance()
244 .getDBConnection()
245 .getDataSource()
246 .getConnection()
247 : null;
248
249 try {
250 connections.add(new Builder.NamedConnection(
251 CONNECTION_SYSTEM, systemConnection, true));
252
253 connections.add(new Builder.NamedConnection(
254 CONNECTION_SEDDB, seddbConnection, true));
255
256 if (userConnection != null) {
257 connections.add(new Builder.NamedConnection(
258 CONNECTION_USER, userConnection, false));
259 }
260
261
262 getBuilder().build(connections, result, parameters);
263 }
264 finally {
265 if (userConnection != null) {
266 userConnection.close();
267 }
268 }
269 }
239 270
240 /** Get singleton instance. */ 271 /** Get singleton instance. */
241 public static synchronized Recommendations getInstance() { 272 public static synchronized Recommendations getInstance() {
242 if (INSTANCE == null) { 273 if (INSTANCE == null) {
243 INSTANCE = createRecommendations(); 274 INSTANCE = createRecommendations();

http://dive4elements.wald.intevation.org