changeset 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 7f8d6b49afad
children 55529f586962
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java
diffstat 2 files changed, 60 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java	Wed Apr 03 10:56:57 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java	Wed Apr 03 12:54:34 2013 +0200
@@ -29,6 +29,7 @@
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 
+import de.intevation.flys.backend.SedDBSessionHolder;
 import de.intevation.flys.backend.SessionHolder;
 
 import de.intevation.artifactdatabase.data.StateData;
@@ -41,6 +42,12 @@
  */
 public class Recommendations
 {
+    public static final String CONNECTION_USER   = "user";
+    public static final String CONNECTION_SYSTEM = "system";
+    public static final String CONNECTION_SEDDB  = "seddb";
+
+    public static final String DEFAULT_CONNECTION_NAME = CONNECTION_SYSTEM;
+
     private static Logger log = Logger.getLogger(Recommendations.class);
 
     private static final boolean DEVELOPMENT_MODE =
@@ -198,44 +205,68 @@
         final Map<String, Object> parameters,
         final String              userId,
         final Node                result,
-        Session                   session
+        Session                   systemSession
     ) {
-        session.doWork(new Work() {
+        systemSession.doWork(new Work() {
             @Override
-            public void execute(Connection systemConnection)
+            public void execute(final Connection systemConnection)
             throws SQLException
             {
-                List<Builder.NamedConnection> connections =
-                    new ArrayList<Builder.NamedConnection>(2);
-
-                Connection userConnection = userId != null
-                    ? DBConfig
-                        .getInstance()
-                        .getDBConnection()
-                        .getDataSource()
-                        .getConnection()
-                    : null;
-
-                try {
-                    if (userConnection != null) {
-                        connections.add(new Builder.NamedConnection(
-                            Builder.CONNECTION_USER, userConnection, false));
+                SedDBSessionHolder.HOLDER.get().doWork(new Work() {
+                    @Override
+                    public void execute(Connection sedDBConnection)
+                    throws SQLException
+                    {
+                        recommend(
+                            parameters, userId, result,
+                            systemConnection,
+                            sedDBConnection);
                     }
-
-                    connections.add(new Builder.NamedConnection(
-                        Builder.CONNECTION_SYSTEM, systemConnection, true));
-
-                    getBuilder().build(connections, result, parameters);
-                }
-                finally {
-                    if (userConnection != null) {
-                        userConnection.close();
-                    }
-                }
+                });
             }
         });
     }
 
+    public void recommend(
+        Map<String, Object> parameters,
+        String              userId,
+        Node                result,
+        Connection          systemConnection,
+        Connection          seddbConnection
+    ) throws SQLException
+    {
+        List<Builder.NamedConnection> connections =
+            new ArrayList<Builder.NamedConnection>(3);
+
+        Connection userConnection = userId != null
+            ? DBConfig
+                .getInstance()
+                .getDBConnection()
+                .getDataSource()
+                .getConnection()
+            : null;
+
+        try {
+            connections.add(new Builder.NamedConnection(
+                CONNECTION_SYSTEM, systemConnection, true));
+
+            connections.add(new Builder.NamedConnection(
+                CONNECTION_SEDDB, seddbConnection, true));
+
+            if (userConnection != null) {
+                connections.add(new Builder.NamedConnection(
+                    CONNECTION_USER, userConnection, false));
+            }
+
+
+            getBuilder().build(connections, result, parameters);
+        }
+        finally {
+            if (userConnection != null) {
+                userConnection.close();
+            }
+        }
+    }
 
     /** Get singleton instance. */
     public static synchronized Recommendations getInstance() {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java	Wed Apr 03 10:56:57 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java	Wed Apr 03 12:54:34 2013 +0200
@@ -40,10 +40,6 @@
 {
     private static Logger log = Logger.getLogger(Builder.class);
 
-    public static final String CONNECTION_USER   = "user";
-    public static final String CONNECTION_SYSTEM = "system";
-    public static final String DEFAULT_CONNECTION_NAME = CONNECTION_SYSTEM;
-
     public static final Pattern STRIP_LINE_INDENT =
         Pattern.compile("\\s*\\r?\\n\\s*");
 
@@ -833,22 +829,6 @@
         return document != null ? document : (Document)node;
     }
 
-    private static final List<NamedConnection> wrap(Connection connection) {
-        List<NamedConnection> list = new ArrayList<NamedConnection>(1);
-        list.add(new NamedConnection(DEFAULT_CONNECTION_NAME, connection));
-        return list;
-    }
-
-    public void build(
-        Connection          connection,
-        Node                output,
-        Map<String, Object> parameters
-    )
-    throws SQLException
-    {
-        build(wrap(connection), output, parameters);
-    }
-
     public void build(
         List<NamedConnection> connections,
         Node                  output,

http://dive4elements.wald.intevation.org