some db code rewriting
[mir.git] / source / mircoders / storage / DatabaseContent.java
index cf0258f..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.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  {
 
   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 ) {
@@ -60,11 +49,10 @@ public class DatabaseContent extends Database  {
     return instance;
   }
 
-  private DatabaseContent() throws StorageObjectFailure {
+  private DatabaseContent() throws DatabaseFailure {
 
     super();
     mainTable="content";
-    primaryKeySequence="media_id_seq";
     logger = new LoggerWrapper("Database.Content");
 
     entityClass = mircoders.entity.EntityContent.class;
@@ -76,7 +64,7 @@ public class DatabaseContent extends Database  {
    * 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;
@@ -94,15 +82,7 @@ public class DatabaseContent extends Database  {
     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);
@@ -110,4 +90,7 @@ public class DatabaseContent extends Database  {
     return super.delete(id);
   }
 
+  protected String getPrimaryKeySequence() {
+    return "media_id_seq";
+  }
 }