first cut of merge of STABLE-pre1_0 into HEAD. I won't even guarantee that it
[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   public static DatabaseMedia getInstance() throws StorageObjectException {
26     if (instance == null) {
27       instance = new DatabaseMedia();
28       instance.myselfDatabase = instance;
29     }
30     return instance;
31   }
32
33   private DatabaseMedia() throws StorageObjectException
34   {
35     super();
36     //this.cache = new DatabaseCache(100);
37     this.hasTimestamp = false;
38     this.theTable="media";
39     relationMediaType = new EntityRelation("to_media_type", "id", 
40                         DatabaseMediaType.getInstance(), EntityRelation.TO_ONE);
41     try {
42       this.theEntityClass = Class.forName("mircoders.entity.EntityMedia");
43     }
44     catch (Exception e) {
45       throw new StorageObjectException(e.toString());
46     }
47   }
48
49   // methods
50
51
52   /**
53    * returns the comments that belong to the article (via entityrelation)
54    * where db-flag is_published is true
55    */
56   public Entity getMediaType(Entity ent) throws StorageObjectException {
57     Entity type=null;
58     try {
59       type = relationMediaType.getOne(ent);
60     }
61     catch (StorageObjectException e) {
62       theLog.printError("DatabaseMedia :: failed to get media_type");
63       throw new StorageObjectException("DatabaseMedia :"+e.toString());
64     }
65     return type;
66   }
67
68 }