// theLog.printDebugInfo("--trying to deliver..."+id);
list(req,res);
//deliver(req, res, mainModule.getById(id), templateObjektString);
+ } catch (Exception e) {
+ throw new ServletModuleException(e.toString());
}
- catch (Exception e) { throw new ServletModuleException(e.toString());}
}
/**
protected int[] metadataTypes;
protected Class theEntityClass;
protected StorageObject myselfDatabase;
- protected HashMap cache;
+ protected DatabaseCache cache;
protected SimpleList popupCache=null;
protected boolean hasPopupCache = false;
protected SimpleHash hashCache=null;
if (id==null||id.equals(""))
throw new StorageObjectException("id war null");
- if (cache != null && cache.containsKey(id))
+ if (cache != null && (cache.containsKey(id) > -1))
return (Entity)cache.get(id); // wenn cache gesetzt, evtl. kein roundtrip zur Datenbank
Statement stmt=null;Connection con=getPooledCon();
if (rs.next())
count = rs.getInt(1);
rs.close();
- }
- else
+ } else {
theLog.printError("Mh. Konnte nicht zaehlen: " + countSql);
+ }
+ }
+ //nothing in the table: return null
+ if(count<=0){
+ return null;
}
// hier select
rs = executeSql(stmt, selectSql.toString());
theResultHash.put(metadataFields.get(i), theResult);
}
}
- if (cache != null && theResultHash.containsKey(thePKeyName) && cache.containsKey((String)theResultHash.get(thePKeyName))) {
+ if (cache != null && theResultHash.containsKey(thePKeyName) &&
+ (cache.containsKey((String)theResultHash.get(thePKeyName)) > -1)) {
//theLog.printDebugInfo("CACHE: (out) "+ theResultHash.get(thePKeyName)+ " :"+theTable);
returnEntity = (Entity)cache.get((String)theResultHash.get(thePKeyName));
}
void throwStorageObjectException (String message) throws StorageObjectException {
_throwStorageObjectException(null, message);
}
+
}
--- /dev/null
+package mir.storage;
+
+import java.util.*;
+
+public class DatabaseCache {
+ private final ArrayList _cache;
+ private int _counter;
+ private final int _max;
+
+ public DatabaseCache(int i_max){
+ _counter = 0;
+ _max = i_max;
+ _cache = new ArrayList(_max);
+ }
+
+ public DatabaseCache(){
+ _counter = -1;
+ _max = 100;
+ _cache = new ArrayList(_max);
+ }
+
+ public synchronized void put(String key, Object value){
+ if(_counter >=_max){
+ _cache.remove(0);
+ _cache.trimToSize();
+ _counter --;
+ System.out.println("put: remove " + _counter);
+ }
+ _cache.add(new Entry(key,value));
+ _counter ++;
+ System.out.println("put: put " + _counter);
+ }
+
+ public synchronized void clear(){
+ _cache.clear();
+ }
+
+ public int containsKey(String key){
+ for(int i = 0; i<_cache.size(); i++){
+ if( ((Entry)_cache.get(i)).getKey().equals(key) )
+ return i;
+ }
+ return -1;
+ }
+
+ public int containsValue(Object o){
+ for(int i = 0; i<_cache.size(); i++){
+ if(((Entry)_cache.get(i)).getValue().equals(o) )
+ return i;
+ }
+ return -1;
+ }
+
+ public Object get(String key){
+ for(int i = 0; i<_cache.size(); i++){
+ if( ((Entry)_cache.get(i)).getKey(key).equals(key) )
+ ((Entry)_cache.get(i)).getValue();
+ }
+ return null;
+ }
+
+ public synchronized boolean remove(String key){
+ int i = containsKey(key);
+ if(i==-1){
+ return false;
+ }
+ _cache.remove(i);
+ _cache.trimToSize();
+ _counter --;
+ return true;
+ }
+
+ public int size(){
+ return _counter;
+ }
+
+ private class Entry {
+ private String _key;
+ private Object _value;
+
+ public Entry(String i_key, Object i_value){
+ _key = i_key;
+ _value = i_value;
+ }
+
+ public void put(String i_key, Object i_value){
+ _key = i_key;
+ _value = i_value;
+ }
+
+ public Object getValue(String i_key){
+ if(i_key.equals(_key)){
+ return _value;
+ } else {
+ return null;
+ }
+ }
+
+ public Object getValue(){
+ return _value;
+ }
+
+ public String getKey(Object i_o){
+ if(i_o.equals(_value)){
+ return _key;
+ } else {
+ return null;
+ }
+ }
+
+ public String getKey(){
+ return _key;
+ }
+ }//Entry
+
+}
+
+
public class DatabaseBreaking extends Database implements StorageObject{
- private static DatabaseBreaking instance;
-
- public static DatabaseBreaking getInstance() throws StorageObjectException {
- if (instance == null) {
- instance = new DatabaseBreaking();
- instance.myselfDatabase = instance;
- }
- return instance;
- }
-
- private DatabaseBreaking() throws StorageObjectException
- {
- super();
- this.cache = new HashMap();
- this.theTable="breaking";
- try {
- this.theEntityClass = Class.forName("mircoders.entity.EntityBreaking");
- }
- catch (Exception e) { throw new StorageObjectException(e.toString()); }
- }
+ private static DatabaseBreaking instance;
+
+ public static DatabaseBreaking getInstance() throws StorageObjectException {
+ if (instance == null) {
+ instance = new DatabaseBreaking();
+ instance.myselfDatabase = instance;
+ }
+ return instance;
+ }
+
+ private DatabaseBreaking() throws StorageObjectException
+ {
+ super();
+ this.cache = new DatabaseCache(4);
+ this.theTable="breaking";
+ try {
+ this.theEntityClass = Class.forName("mircoders.entity.EntityBreaking");
+ }
+ catch (Exception e) { throw new StorageObjectException(e.toString()); }
+ }
}
super();
this.theTable="content";
this.theCoreTable="media";
+
relationComments = new EntityRelation("id", "to_media", DatabaseComment.getInstance(), EntityRelation.TO_MANY);
relationFeature = new EntityRelation("id", "to_feature", DatabaseFeature.getInstance(), EntityRelation.TO_ONE);
try { this.theEntityClass = Class.forName("mircoders.entity.EntityContent"); }
public class DatabaseFeature extends Database implements StorageObject{
- private static DatabaseFeature instance;
-
- public static DatabaseFeature getInstance() throws StorageObjectException {
- if (instance == null) {
- instance = new DatabaseFeature();
- instance.myselfDatabase = instance;
- }
- return instance;
- }
-
- private DatabaseFeature() throws StorageObjectException
- {
- super();
- this.cache = new HashMap();
- this.hasTimestamp = false;
- this.theTable="feature";
-
- try {
- this.theEntityClass = Class.forName("mircoders.entity.EntityFeature");
- }
- catch (Exception e) {
- throw new StorageObjectException(e.toString());
- }
- }
-
- public SimpleList getPopupData() throws StorageObjectException {
- return getPopupData("title",true);
- }
+ private static DatabaseFeature instance;
+
+ public static DatabaseFeature getInstance() throws StorageObjectException {
+ if (instance == null) {
+ instance = new DatabaseFeature();
+ instance.myselfDatabase = instance;
+ }
+ return instance;
+ }
+
+ private DatabaseFeature() throws StorageObjectException
+ {
+ super();
+ this.cache = new DatabaseCache(10);
+ this.hasTimestamp = false;
+ this.theTable="feature";
+
+ try {
+ this.theEntityClass = Class.forName("mircoders.entity.EntityFeature");
+ }
+ catch (Exception e) {
+ throw new StorageObjectException(e.toString());
+ }
+ }
+
+ public SimpleList getPopupData() throws StorageObjectException {
+ return getPopupData("title",true);
+ }
}
private DatabaseMedia() throws StorageObjectException
{
super();
- this.cache = new HashMap();
+ this.cache = new DatabaseCache(100);
this.hasTimestamp = false;
this.theTable="media*";
relationMediaType = new EntityRelation("to_media_type", "id", DatabaseMediaType.getInstance(), EntityRelation.TO_ONE);
{
super();
this.hasTimestamp = false;
- this.cache = new HashMap();
+ this.cache = new DatabaseCache(20);
this.theTable="media_type";
try {
this.theEntityClass = Class.forName("mir.entity.GenericEntity");
public class DatabaseMediafolder extends Database implements StorageObject{
- private static DatabaseMediafolder instance;
-
- public static DatabaseMediafolder getInstance() throws StorageObjectException {
- if (instance == null) {
- instance = new DatabaseMediafolder();
- instance.myselfDatabase = instance;
- }
- return instance;
- }
-
- private DatabaseMediafolder() throws StorageObjectException
- {
- super();
- this.hasTimestamp = false;
- this.cache = new HashMap();
- this.theTable="media_folder";
- }
-
- public SimpleList getPopupData() throws StorageObjectException {
- return getPopupData("name",true);
- }
+ private static DatabaseMediafolder instance;
+
+ public static DatabaseMediafolder getInstance() throws StorageObjectException {
+ if (instance == null) {
+ instance = new DatabaseMediafolder();
+ instance.myselfDatabase = instance;
+ }
+ return instance;
+ }
+
+ private DatabaseMediafolder() throws StorageObjectException
+ {
+ super();
+ this.hasTimestamp = false;
+ this.cache = new DatabaseCache(20);
+ this.theTable="media_folder";
+ }
+
+ public SimpleList getPopupData() throws StorageObjectException {
+ return getPopupData("name",true);
+ }
}
public class DatabaseMessages extends Database implements StorageObject{
- private static DatabaseMessages instance;
-
- public static DatabaseMessages getInstance() throws StorageObjectException {
- if (instance == null) {
- instance = new DatabaseMessages();
- instance.myselfDatabase = instance;
- }
- return instance;
- }
-
- private DatabaseMessages() throws StorageObjectException
- {
- super();
- this.cache = new HashMap();
- this.theTable="messages";
- }
+ private static DatabaseMessages instance;
+
+ public static DatabaseMessages getInstance() throws StorageObjectException {
+ if (instance == null) {
+ instance = new DatabaseMessages();
+ instance.myselfDatabase = instance;
+ }
+ return instance;
+ }
+
+ private DatabaseMessages() throws StorageObjectException
+ {
+ super();
+ this.cache = new DatabaseCache(10);
+ this.theTable="messages";
+ }
}
public class DatabaseTopics extends Database implements StorageObject{
- private static DatabaseTopics instance;
-
- public static DatabaseTopics getInstance() throws StorageObjectException {
- if (instance == null) {
- instance = new DatabaseTopics();
- instance.myselfDatabase = instance;
- }
- return instance;
- }
-
- private DatabaseTopics() throws StorageObjectException
- {
+ private static DatabaseTopics instance;
+
+ public static DatabaseTopics getInstance() throws StorageObjectException {
+ if (instance == null) {
+ instance = new DatabaseTopics();
+ instance.myselfDatabase = instance;
+ }
+ return instance;
+ }
+
+ private DatabaseTopics() throws StorageObjectException
+ {
super();
- this.cache = new HashMap();
- this.hasTimestamp = false;
- this.theTable="topic";
- try {
- this.theEntityClass = Class.forName("mircoders.entity.EntityTopics");
- }
- catch (Exception e) {
- throw new StorageObjectException(e.toString());
- }
-
- }
-
- public SimpleList getPopupData() throws StorageObjectException {
- return getPopupData("title",true);
- }
+ this.cache = new DatabaseCache(20);
+ this.hasTimestamp = false;
+ this.theTable="topic";
+ try {
+ this.theEntityClass = Class.forName("mircoders.entity.EntityTopics");
+ }
+ catch (Exception e) {
+ throw new StorageObjectException(e.toString());
+ }
+
+ }
+
+ public SimpleList getPopupData() throws StorageObjectException {
+ return getPopupData("title",true);
+ }