merged 1.1 branch into head
[mir.git] / source / mir / entity / AbstractEntity.java
index ec6d9b0..ab76726 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2005 The Mir-coders group
  *
  * This file is part of Mir.
  *
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two.  You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries.  If you modify this file, you may extend this
+ * the code of this program with  any library licensed under the Apache Software License.
+ * You must obey the GNU General Public License in all respects for all of the code used
+ * other than the above mentioned libraries.  If you modify this file, you may extend this
  * exception to your version of the file, but you are not obligated to do so.
  * If you do not wish to do so, delete this exception statement from your version.
  */
@@ -35,44 +32,30 @@ import java.util.List;
 import java.util.Map;
 
 import mir.config.MirPropertiesConfiguration;
-import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
 import mir.log.LoggerWrapper;
-import mir.storage.StorageObject;
-import mir.storage.StorageObjectExc;
-import mir.storage.StorageObjectFailure;
+import mir.storage.DatabaseExc;
+import mir.storage.DatabaseFailure;
+import mir.storage.Database;
 
 /**
  * Base class the entities are derived from. Provides base functionality of
  * an entity.
  *
- * @version $Id: AbstractEntity.java,v 1.9 2004/11/06 19:18:12 idfx Exp $
+ * @version $Id: AbstractEntity.java,v 1.10 2007/04/08 21:46:44 idfx Exp $
  */
 
 public class AbstractEntity implements Entity {
   protected static MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
 
   protected Map values;
-  protected StorageObject storageObject;
-  protected LoggerWrapper logger;
+  protected Database database;
 
   public AbstractEntity() {
-    logger = new LoggerWrapper("Entity");
-
     values = new HashMap();
   }
 
-  /**
-   * Constructor
-   * @param StorageObject The StorageObject of the Entity.
-   */
-  public AbstractEntity(StorageObject StorageObject) {
-    this();
-
-    setStorage(StorageObject);
-  }
-
-  public void setStorage(StorageObject storage) {
-    this.storageObject = storage;
+  public void setStorage(Database aDatabase) {
+    database = aDatabase;
   }
 
   /** {@inheritDoc} */
@@ -91,28 +74,28 @@ public class AbstractEntity implements Entity {
 
   /** {@inheritDoc} */
   public String getId() {
-    return getFieldValue(storageObject.getIdName());
+    return getFieldValue(database.getIdFieldName());
   }
 
   /** {@inheritDoc} */
   public void setId(String id) {
-    setFieldValue(storageObject.getIdName(), id);
+    setFieldValue(database.getIdFieldName(), id);
   }
 
   /** {@inheritDoc} */
-  public String insert() throws StorageObjectExc {
-    logger.debug("Entity: trying to insert ...");
+  public String insert() throws DatabaseExc {
+    getLogger().debug("Entity: trying to insert ...");
 
-    if (storageObject != null) {
-      return storageObject.insert(this);
+    if (database != null) {
+      return database.insert(this);
     }
-    else
-      throw new StorageObjectExc("storageObject == null!");
+
+    throw new DatabaseExc("database == null!");
   }
 
   /** {@inheritDoc} */
-  public void update() throws StorageObjectFailure {
-    storageObject.update(this);
+  public void update() throws DatabaseFailure {
+    database.update(this);
   }
 
   /** {@inheritDoc} */
@@ -135,30 +118,34 @@ public class AbstractEntity implements Entity {
    * supplied was not found in the Entity.
    * @param theProp The field name whose value has to be set
    * @param theValue The new value of the field
-   * @exception StorageObjectFailure
+   * @exception DatabaseFailure
    */
-  public void setFieldValue(String theProp, String theValue) throws StorageObjectFailure {
+  public void setFieldValue(String theProp, String theValue) throws DatabaseFailure {
     if (hasField(theProp))
       values.put(theProp, theValue);
     else {
-      logger.warn("Entity.setFieldValue: Property not found: " + theProp + " (" + theValue + ")");
+      getLogger().warn("Entity.setFieldValue: Property not found: " + theProp + " (" + theValue + ")");
     }
   }
 
   /**
    * Returns the field names of the Entity
    */
-  public List getFieldNames() throws StorageObjectFailure {
-    return storageObject.getFields();
+  public List getFieldNames() throws DatabaseFailure {
+    return database.getFieldNames();
   }
 
   /** Returns whether fieldName is a valid field name of this Entity.
    * @param fieldName
    * @return true in case fieldName is a field name, else false.
-   * @exception StorageObjectFailure
+   * @exception DatabaseFailure
    */
-  public boolean hasField(String fieldName) throws StorageObjectFailure {
+  public boolean hasField(String fieldName) throws DatabaseFailure {
     return getFieldNames().contains(fieldName);
   }
+
+  protected LoggerWrapper getLogger() {
+    return new LoggerWrapper("Entity");
+  }
 }