X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fentity%2FAbstractEntity.java;h=108f4247cfd47b657ad7ef53a1f276bdd408eafc;hb=f2c82f962d2da630470760b0cadbcef91dec680d;hp=5cfd8292029db2217f7716e42f33432dcf7d5354;hpb=213122e7c65211f549722f05aa8e0135f15af35c;p=mir.git diff --git a/source/mir/entity/AbstractEntity.java b/source/mir/entity/AbstractEntity.java index 5cfd8292..108f4247 100755 --- a/source/mir/entity/AbstractEntity.java +++ b/source/mir/entity/AbstractEntity.java @@ -36,32 +36,29 @@ import java.util.Map; import mir.config.MirPropertiesConfiguration; 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.8.2.4 2005/01/09 20:37:07 zapata Exp $ + * @version $Id: AbstractEntity.java,v 1.8.2.8 2005/10/30 00:46:57 zapata 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(); } - public void setStorage(StorageObject aStorageObject) { - storageObject = aStorageObject; + public void setStorage(Database aDatabase) { + database = aDatabase; } /** {@inheritDoc} */ @@ -80,28 +77,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} */ @@ -124,30 +121,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.getFieldNames(); + 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"); + } }