X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fentity%2FAbstractEntity.java;h=108f4247cfd47b657ad7ef53a1f276bdd408eafc;hb=f2c82f962d2da630470760b0cadbcef91dec680d;hp=925ff8d19d7cb52c01af7bc122b54f1c3a037895;hpb=d1fe8297d584e69a5d2bed84cc979d8bdd13cb31;p=mir.git diff --git a/source/mir/entity/AbstractEntity.java b/source/mir/entity/AbstractEntity.java index 925ff8d1..108f4247 100755 --- a/source/mir/entity/AbstractEntity.java +++ b/source/mir/entity/AbstractEntity.java @@ -35,58 +35,34 @@ 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.8.2.1 2004/01/18 17:30:56 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; + protected static MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance(); protected Map values; - protected StorageObject storageObject; - protected LoggerWrapper logger; - - static { - try { - configuration = MirPropertiesConfiguration.instance(); - } - catch (PropertiesConfigExc e) { - throw new RuntimeException(e.getMessage()); - } - } + 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} */ - public void setValues(Map aMap) { + public void setFieldValues(Map aMap) { if (aMap!=null) { Iterator i = aMap.entrySet().iterator(); synchronized(this) { @@ -101,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} */ @@ -145,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.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"); + } }