fa09f08d12b9b4830cb2351d66f2047b9b7e2898
[mir.git] / source / mircoders / storage / DatabaseMedia.java
1 package mircoders.storage;
2
3 import java.lang.*;
4 import java.sql.*;
5 import java.io.*;
6 import java.util.*;
7
8 import freemarker.template.*;
9
10 import mir.storage.*;
11 import mir.entity.*;
12 import mir.misc.*;
13
14 /**
15  * <b>Diese Klasse implementiert die Datenbankverbindung zur MetaObjekt-Tabelle
16  *
17  *
18  */
19
20 public class DatabaseMedia extends Database implements StorageObject{
21
22   private static DatabaseMedia instance;
23   private static EntityRelation         relationMediaType;
24
25   // the following *has* to be sychronized cause this static method
26   // could get preemted and we could end up with 2 instances of DatabaseFoo..
27   // see the "Singletons with needles and thread" article at JavaWorld -mh
28   public synchronized static DatabaseMedia getInstance() 
29     throws StorageObjectException {
30     if (instance == null) {
31       instance = new DatabaseMedia();
32       instance.myselfDatabase = instance;
33     }
34     return instance;
35   }
36
37   private DatabaseMedia() throws StorageObjectException
38   {
39     super();
40     //this.cache = new DatabaseCache(100);
41     this.hasTimestamp = false;
42     this.theTable="media";
43     relationMediaType = new EntityRelation("to_media_type", "id", 
44                         DatabaseMediaType.getInstance(), EntityRelation.TO_ONE);
45     try {
46       this.theEntityClass = Class.forName("mircoders.entity.EntityMedia");
47     }
48     catch (Exception e) {
49       throw new StorageObjectException(e.toString());
50     }
51   }
52
53   // methods
54
55
56   /**
57    * returns the comments that belong to the article (via entityrelation)
58    * where db-flag is_published is true
59    */
60   public Entity getMediaType(Entity ent) throws StorageObjectException {
61     Entity type=null;
62     try {
63       type = relationMediaType.getOne(ent);
64     }
65     catch (StorageObjectException e) {
66       theLog.printError("DatabaseMedia :: failed to get media_type");
67       throw new StorageObjectException("DatabaseMedia :"+e.toString());
68     }
69     return type;
70   }
71
72 }