01: /***
02: * jwma Java WebMail
03: * Copyright (c) 2000-2003 jwma team
04: *
05: * jwma is free software; you can distribute and use this source
06: * under the terms of the BSD-style license received along with
07: * the distribution.
08: ***/package dtw.webmail.plugin.std;
09:
10: import dtw.webmail.model.JwmaException;
11: import dtw.webmail.util.CastorDatabase;
12: import org.apache.log4j.Logger;
13: import org.exolab.castor.jdo.Database;
14: import org.exolab.castor.jdo.PersistenceException;
15:
16: import java.util.HashMap;
17:
18: //import dtw.webmail.JwmaKernel;
19:
20: /**
21: * Class extending the abstract CastorDatabase class,
22: * to specialize it for the jwma database.
23: * It caches and reuses queries used within jwma.
24: *
25: * @author Dieter Wimberger
26: * @version 0.9.7 07/02/2003
27: */
28: public class JwmaDatabase extends CastorDatabase {
29:
30: //logging
31: private static Logger log = Logger.getLogger(JwmaDatabase.class);
32:
33: public JwmaDatabase() {
34: }
35:
36: /**
37: * Creates a new instance with a prepared amount
38: * of slots for queries.
39: * This denotes a size for a hashmap, add 30% more
40: * then you really want to use for good performance.
41: */
42: private JwmaDatabase(Database db, int queries) {
43: m_Database = db;
44: m_Queries = new HashMap(queries);
45: }//constructor
46:
47: public CastorDatabase createCastorDatabase() throws JwmaException {
48:
49: CastorDatabase newdb = new JwmaDatabase(CastorHelper
50: .getReference().getJDODatabase(), 5);
51: //add prepared queries
52: //1. preferences instance query
53: try {
54: newdb.putQuery(PREFINSTANCE_BYUSERID, newdb
55: .getOQLQuery(PREFINSTANCE_BYUSERID_QUERY));
56: log.debug("Set new Query");
57: } catch (PersistenceException pex) {
58: throw new JwmaException("").setException(pex);
59: }
60: return newdb;
61: }//createCastorDatabase
62:
63: /**
64: * Defines the identifier of the query for a preferences instance
65: * by user identity.
66: */
67: public static final String PREFINSTANCE_BYUSERID = "preferencesbyuserid";
68:
69: private static final String PREFINSTANCE_BYUSERID_QUERY = "SELECT p FROM dtw.webmail.plugin.std.CastorPreferences p WHERE UserIdentity=$1";
70:
71: }//JwmaDatabase
|