public class DatabaseMedia extends Database implements StorageObject{
private static DatabaseMedia instance;
+ private static EntityRelation relationMediaType;
- public static DatabaseMedia getInstance() throws StorageObjectException {
+ // 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 DatabaseMedia getInstance()
+ throws StorageObjectException {
if (instance == null) {
instance = new DatabaseMedia();
instance.myselfDatabase = instance;
private DatabaseMedia() throws StorageObjectException
{
super();
- this.cache = new HashMap();
+ //this.cache = new DatabaseCache(100);
this.hasTimestamp = false;
- this.theTable="media*";
+ this.theTable="media";
+ relationMediaType = new EntityRelation("to_media_type", "id",
+ DatabaseMediaType.getInstance(), EntityRelation.TO_ONE);
try {
this.theEntityClass = Class.forName("mircoders.entity.EntityMedia");
}
}
}
+ // methods
+
+
+ /**
+ * returns the comments that belong to the article (via entityrelation)
+ * where db-flag is_published is true
+ */
+ public Entity getMediaType(Entity ent) throws StorageObjectException {
+ Entity type=null;
+ try {
+ type = relationMediaType.getOne(ent);
+ }
+ catch (StorageObjectException e) {
+ theLog.printError("DatabaseMedia :: failed to get media_type");
+ throw new StorageObjectException("DatabaseMedia :"+e.toString());
+ }
+ return type;
+ }
}