diff artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 26:83a059c204f8

Connected /create with artifact db. artifacts/trunk@61 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 10 Sep 2009 12:29:57 +0000
parents d5dc2900392f
children 75bdaf900473
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Sep 10 09:23:53 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Sep 10 12:29:57 2009 +0000
@@ -176,9 +176,14 @@
         Long ttl = factory.timeToLiveUntouched(
             artifact, context);
 
-        int id = insertDatabase(uuid, ttl);
-
-        return new ArtifactProxy(artifact, id, true);
+        try {
+            int id = insertDatabase(uuid, ttl);
+            return new ArtifactProxy(artifact, id, true);
+        }
+        catch (Exception e) {
+            logger.error(e.getLocalizedMessage(), e);
+        }
+        return null;
     }
 
     protected Artifact getArtifactByUUID(UUID uuid) {
@@ -345,73 +350,87 @@
     }
 
     public void touch(ArtifactProxy proxy) {
-        logger.info("touch: " + proxy);
+
         if (proxy.isUnwritten()) {
             store(proxy);
             return;
         }
-        Connection        connection  = null;
-        PreparedStatement stmnt_touch = null;
-        DataSource        dataSource  = DBConnection.getDataSource();
+
         try {
-            connection = dataSource.getConnection();
+            Connection        connection  = null;
+            PreparedStatement stmnt_touch = null;
+            DataSource        dataSource  = DBConnection.getDataSource();
             try {
-                connection.setAutoCommit(false);
-                stmnt_touch = connection.prepareStatement(SQL_UPDATE);
-                stmnt_touch.setInt(1, proxy.getId());
-                stmnt_touch.execute();
-                connection.commit();
+                connection = dataSource.getConnection();
+                try {
+                    connection.setAutoCommit(false);
+                    stmnt_touch = connection.prepareStatement(SQL_UPDATE);
+                    stmnt_touch.setInt(1, proxy.getId());
+                    stmnt_touch.execute();
+                    connection.commit();
+                }
+                catch (SQLException sqle) {
+                    connection.rollback();
+                }
             }
             catch (SQLException sqle) {
-                connection.rollback();
+                logger.error(sqle.getLocalizedMessage(), sqle);
+            }
+            finally {
+                if (stmnt_touch != null) {
+                    try { stmnt_touch.close(); }
+                    catch (SQLException sqle) {}
+                }
+                if (connection != null) {
+                    try { connection.close(); }
+                    catch (SQLException sqle) {}
+                }
             }
         }
-        catch (SQLException sqle) {
-            logger.error(sqle.getLocalizedMessage(), sqle);
-        }
-        finally {
-            if (stmnt_touch != null) {
-                try { stmnt_touch.close(); }
-                catch (SQLException sqle) {}
-            }
-            if (connection != null) {
-                try { connection.close(); }
-                catch (SQLException sqle) {}
-            }
+        catch (Exception e) {
+            logger.error(e.getLocalizedMessage(), e);
         }
     }
 
     public void store(ArtifactProxy proxy) {
-        logger.info("store: " + proxy);
-        Connection        connection   = null;
-        PreparedStatement stmnt_update = null;
-        DataSource        dataSource   = DBConnection.getDataSource();
+
         try {
-            connection = dataSource.getConnection();
+            Connection        connection   = null;
+            PreparedStatement stmnt_update = null;
+            DataSource        dataSource   = DBConnection.getDataSource();
             try {
-                connection.setAutoCommit(false);
-                stmnt_update = connection.prepareStatement(SQL_UPDATE);
-                stmnt_update.setInt(1, proxy.getId());
-                stmnt_update.setBytes(2, proxy.toBytes());
-                stmnt_update.execute();
-                connection.commit();
+                connection = dataSource.getConnection();
+                try {
+                    connection.setAutoCommit(false);
+                    stmnt_update = connection.prepareStatement(SQL_UPDATE);
+                    stmnt_update.setInt(2, proxy.getId());
+
+                    byte [] bytes = proxy.toBytes();
+
+                    stmnt_update.setBytes(1, bytes);
+                    stmnt_update.execute();
+                    connection.commit();
+                }
+                catch (SQLException sqle) {
+                    connection.rollback();
+                }
             }
             catch (SQLException sqle) {
-                connection.rollback();
+                logger.error(sqle.getLocalizedMessage(), sqle);
+            }
+            finally {
+                if (stmnt_update != null) {
+                    try { stmnt_update.close(); }
+                    catch (SQLException sqle) {}
+                }
+                if (connection != null) {
+                    try { connection.close(); }
+                    catch (SQLException sqle) {}
+                }
             }
         }
-        catch (SQLException sqle) {
-            logger.error(sqle.getLocalizedMessage(), sqle);
-        }
-        finally {
-            if (stmnt_update != null) {
-                try { stmnt_update.close(); }
-                catch (SQLException sqle) {}
-            }
-            if (connection != null) {
-                try { connection.close(); }
-                catch (SQLException sqle) {}
-            }
+        catch (Exception e) {
+            logger.error(e.getLocalizedMessage(), e);
         }
     }
 

http://dive4elements.wald.intevation.org