some db code rewriting
[mir.git] / source / mircoders / storage / DatabaseContent.java
index 8d5e809..bf14742 100755 (executable)
 
 package mircoders.storage;
 
-import java.sql.Connection;
-import java.sql.Statement;
-
 import mir.log.LoggerWrapper;
 import mir.storage.Database;
-import mir.storage.StorageObject;
-import mir.storage.StorageObjectFailure;
+import mir.storage.DatabaseFailure;
 
-/**
- * <b>this class implements the access to the content-table</b>
- *
- *
- */
+import java.sql.Connection;
+import java.sql.Statement;
 
-public class DatabaseContent extends Database implements StorageObject {
+public class DatabaseContent extends Database  {
 
   private static DatabaseContent      instance;
 
-  // Contructors / Singleton
-
-  // the following *has* to be sychronized cause this static method
-  // could get preemted and we could end up with 2 instances of DatabaseFoo.
-  // see the "Singletons with needles and thread" article at JavaWorld -mh
   public synchronized static DatabaseContent getInstance() {
 
     if (instance == null ) {
@@ -61,14 +49,13 @@ public class DatabaseContent extends Database implements StorageObject {
     return instance;
   }
 
-  private DatabaseContent() throws StorageObjectFailure {
+  private DatabaseContent() throws DatabaseFailure {
 
     super();
     mainTable="content";
-    primaryKeySequence="media_id_seq";
     logger = new LoggerWrapper("Database.Content");
 
-    theEntityClass = mircoders.entity.EntityContent.class;
+    entityClass = mircoders.entity.EntityContent.class;
   }
 
   // methods
@@ -77,13 +64,13 @@ public class DatabaseContent extends Database implements StorageObject {
    * sets the database flag is_produced to unproduced
    */
 
-  public void setUnproduced(String where) throws StorageObjectFailure
+  public void setUnproduced(String where) throws DatabaseFailure
   {
     Connection con=null;Statement stmt=null;
     String sql = "update content set is_produced='0' where " + where;
     logger.debug("set unproduced: "+where);
     try {
-      con = getPooledCon();
+      con = obtainConnection();
       // should be a preparedStatement because is faster
       stmt = con.createStatement();
       executeUpdate(stmt,sql);
@@ -95,15 +82,7 @@ public class DatabaseContent extends Database implements StorageObject {
     finally { freeConnection(con,stmt);}
   }
 
-  /**
-   *
-   * @param id
-   * @return
-   * @throws StorageObjectFailure
-   */
-
-  public boolean delete(String id) throws StorageObjectFailure
-  {
+  public boolean delete(String id) throws DatabaseFailure {
     DatabaseComment.getInstance().deleteByContentId(id);
     DatabaseContentToTopics.getInstance().deleteByContentId(id);
     DatabaseContentToMedia.getInstance().deleteByContentId(id);
@@ -111,4 +90,7 @@ public class DatabaseContent extends Database implements StorageObject {
     return super.delete(id);
   }
 
+  protected String getPrimaryKeySequence() {
+    return "media_id_seq";
+  }
 }