# HG changeset patch # User Sascha L. Teichmann # Date 1364986474 -7200 # Node ID ac48ab9e1715f84a21d0c6a639dd35a95f5b4b36 # Parent 7f8d6b49afadea5f6aaf81882b84c9675fdb02af Datacage: Added connection to SedDB. Use to use it. diff -r 7f8d6b49afad -r ac48ab9e1715 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java --- 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 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 connections = - new ArrayList(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 parameters, + String userId, + Node result, + Connection systemConnection, + Connection seddbConnection + ) throws SQLException + { + List connections = + new ArrayList(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() { diff -r 7f8d6b49afad -r ac48ab9e1715 flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java --- 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 wrap(Connection connection) { - List list = new ArrayList(1); - list.add(new NamedConnection(DEFAULT_CONNECTION_NAME, connection)); - return list; - } - - public void build( - Connection connection, - Node output, - Map parameters - ) - throws SQLException - { - build(wrap(connection), output, parameters); - } - public void build( List connections, Node output,