package mircoders.entity;
+import mir.entity.AbstractEntity;
+import mir.storage.DatabaseFailure;
+import mircoders.storage.DatabaseContentToMedia;
+
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.HashMap;
-import java.util.Map;
-
-import mir.entity.Entity;
-import mir.entity.EntityList;
-import mir.log.LoggerWrapper;
-import mir.storage.StorageObject;
-import mir.storage.StorageObjectExc;
-import mir.storage.StorageObjectFailure;
-import mircoders.storage.DatabaseContent;
-import mircoders.storage.DatabaseContentToMedia;
-import mircoders.storage.DatabaseContentToTopics;
/**
* this class implements mapping of one line of the database table content
* to a java object
*
- * @version $Id: EntityContent.java,v 1.19.2.2 2003/09/03 17:49:39 zapata Exp $
+ * @version $Id: EntityContent.java,v 1.19.2.13 2007/12/15 00:24:43 zapata Exp $
* @author mir-coders group
*
*/
-public class EntityContent extends Entity
-{
-
- String mirconf_extLinkName = configuration.getString("Producer.ExtLinkName");
- String mirconf_intLinkName = configuration.getString("Producer.IntLinkName");
- String mirconf_mailLinkName = configuration.getString("Producer.MailLinkName");
- String mirconf_imageRoot = configuration.getString("Producer.ImageRoot");
-
- //this should always be transient i.e it can never be stored in the db
- //or ObjectStore. (so the ObjectStore should only be caching what comes
- //directly out of the DB. @todo confirm this with rk. -mh
- Map _entCache = new HashMap();
- Boolean _hasMedia = null;
-
- // constructors
-
- public EntityContent()
- {
- super();
-
- logger = new LoggerWrapper("Entity.Content");
- }
-
- public EntityContent(StorageObject theStorage) {
- this();
-
- setStorage(theStorage);
- }
-
- //
- // methods
-
+public class EntityContent extends AbstractEntity {
/**
* set is_produced flag for the article
*/
-
- public void setProduced(boolean yesno) throws StorageObjectFailure
- {
+ public void setProduced(boolean yesno) throws DatabaseFailure {
String value = (yesno) ? "1":"0";
- if (value.equals( getValue("is_produced") )) return;
+ if (value.equals( getFieldValue("is_produced") )) return;
Connection con=null;Statement stmt=null;
String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
try {
- con = theStorageObject.getPooledCon();
- /** @todo should be preparedStatement: faster!! */
+ con = database.obtainConnection();
+ /** todo should be preparedStatement: faster!! */
stmt = con.createStatement();
- theStorageObject.executeUpdate(stmt,sql);
+ database.executeUpdate(stmt,sql);
}
- catch (StorageObjectFailure e) {
- throwStorageObjectFailure(e, "\n -- set produced failed");
+ catch (DatabaseFailure e) {
+ throw e;
}
catch (SQLException e) {
- throwStorageObjectFailure(e, "\n -- set produced failed");
+ throw new DatabaseFailure(e);
}
finally {
- theStorageObject.freeConnection(con,stmt);
+ database.freeConnection(con,stmt);
}
}
*
* @param anArticleId
* @param aMediaId
- * @throws StorageObjectFailure
+ * @throws DatabaseFailure
*/
- public void dettach(String anArticleId, String aMediaId) throws StorageObjectFailure
- {
+ public void dettach(String anArticleId, String aMediaId) throws DatabaseFailure {
if (aMediaId!=null){
- try{
- DatabaseContentToMedia.getInstance().delete(anArticleId, aMediaId);
- }
- catch (Exception e){
- throwStorageObjectFailure(e, "\n -- failed to get instance");
- }
+ DatabaseContentToMedia.getInstance().delete(anArticleId, aMediaId);
setProduced(false);
}
}
/**
- * Attaches media to an article
- *
- * @param mid
- * @throws StorageObjectFailure
+ * Attaches media to the article
*/
- public void attach(String aMediaId) throws StorageObjectFailure
- {
- if (aMediaId!=null) {
- try{
- DatabaseContentToMedia.getInstance().addMedia(getId(),aMediaId);
- }
- catch(StorageObjectFailure e){
- throwStorageObjectFailure(e, "attach: could not get the instance");
- }
+ public void attach(String aMediaId) throws DatabaseFailure {
+ if (aMediaId != null) {
+ DatabaseContentToMedia.getInstance().addMedia(getId(),aMediaId);
setProduced(false);
}
else {
- logger.error("EntityContent: attach without mid");
- }
- }
-
- /**
- * overridden method setValues to patch creator_main_url
- */
- public void setValues(Map theStringValues) {
- if (theStringValues != null) {
- if (theStringValues.containsKey("creator_main_url")){
- if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
- theStringValues.remove("creator_main_url");
- }
- else if (!((String)theStringValues.get("creator_main_url")).startsWith("http://")){
- theStringValues.put("creator_main_url","http://"+((String)theStringValues.get("creator_main_url")));
- }
- }
- }
- super.setValues(theStringValues);
- }
-
- private boolean hasMedia() throws StorageObjectFailure
- {
- if (_hasMedia == null) {
- try {
- _hasMedia =
- new Boolean(DatabaseContentToMedia.getInstance().hasMedia(this));
- } catch (StorageObjectExc e) {
- throw new StorageObjectFailure(e);
- }
+ getLogger().error("EntityContent: attach without mid");
}
- return _hasMedia.booleanValue();
}
}