001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/email/tags/sakai_2-4-1/email-impl/impl/src/java/org/sakaiproject/email/impl/DbDigestService.java $
003: * $Id: DbDigestService.java 7315 2006-04-01 19:59:15Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.email.impl;
021:
022: import java.util.List;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.sakaiproject.db.api.SqlService;
027: import org.sakaiproject.email.api.Digest;
028: import org.sakaiproject.email.api.DigestEdit;
029: import org.sakaiproject.util.BaseDbSingleStorage;
030: import org.sakaiproject.util.StorageUser;
031:
032: /**
033: * <p>
034: * DbDigestService is an extension of the BaseDigestService with database storage.
035: * </p>
036: */
037: public abstract class DbDigestService extends BaseDigestService {
038: /** Our logger. */
039: private static Log M_log = LogFactory.getLog(DbDigestService.class);
040:
041: /** Table name for realms. */
042: protected String m_tableName = "SAKAI_DIGEST";
043:
044: /** If true, we do our locks in the remote database, otherwise we do them here. */
045: protected boolean m_locksInDb = true;
046:
047: /**********************************************************************************************************************************************************************************************************************************************************
048: * Dependencies
049: *********************************************************************************************************************************************************************************************************************************************************/
050:
051: /**
052: * @return the MemoryService collaborator.
053: */
054: protected abstract SqlService sqlService();
055:
056: /**********************************************************************************************************************************************************************************************************************************************************
057: * Configuration
058: *********************************************************************************************************************************************************************************************************************************************************/
059:
060: /**
061: * Configuration: set the table name
062: *
063: * @param path
064: * The table name.
065: */
066: public void setTableName(String name) {
067: m_tableName = name;
068: }
069:
070: /**
071: * Configuration: set the locks-in-db
072: *
073: * @param value
074: * The locks-in-db value.
075: */
076: public void setLocksInDb(String value) {
077: m_locksInDb = new Boolean(value).booleanValue();
078: }
079:
080: /** Configuration: to run the ddl on init or not. */
081: protected boolean m_autoDdl = false;
082:
083: /**
084: * Configuration: to run the ddl on init or not.
085: *
086: * @param value
087: * the auto ddl value.
088: */
089: public void setAutoDdl(String value) {
090: m_autoDdl = new Boolean(value).booleanValue();
091: }
092:
093: /**********************************************************************************************************************************************************************************************************************************************************
094: * Init and Destroy
095: *********************************************************************************************************************************************************************************************************************************************************/
096:
097: /**
098: * Final initialization, once all dependencies are set.
099: */
100: public void init() {
101: try {
102: // if we are auto-creating our schema, check and create
103: if (m_autoDdl) {
104: sqlService().ddl(this .getClass().getClassLoader(),
105: "sakai_digest");
106: }
107:
108: super .init();
109:
110: M_log.info("init(): table: " + m_tableName
111: + " locks-in-db: " + m_locksInDb);
112: } catch (Throwable t) {
113: M_log.warn("init(): ", t);
114: }
115: }
116:
117: /**********************************************************************************************************************************************************************************************************************************************************
118: * BaseDigestService extensions
119: *********************************************************************************************************************************************************************************************************************************************************/
120:
121: /**
122: * Construct a Storage object.
123: *
124: * @return The new storage object.
125: */
126: protected Storage newStorage() {
127: return new DbStorage(this );
128: }
129:
130: /**********************************************************************************************************************************************************************************************************************************************************
131: * Storage implementation
132: *********************************************************************************************************************************************************************************************************************************************************/
133:
134: /**
135: * Covers for the BaseXmlFileStorage, providing Digest and DigestEdit parameters
136: */
137: protected class DbStorage extends BaseDbSingleStorage implements
138: Storage {
139: /**
140: * Construct.
141: *
142: * @param realm
143: * The StorageUser class to call back for creation of Resource and Edit objects.
144: */
145: public DbStorage(StorageUser user) {
146: super (m_tableName, "DIGEST_ID", null, m_locksInDb,
147: "digest", user, sqlService());
148: }
149:
150: public boolean check(String id) {
151: return super .checkResource(id);
152: }
153:
154: public Digest get(String id) {
155: return (Digest) super .getResource(id);
156: }
157:
158: public List getAll() {
159: return super .getAllResources();
160: }
161:
162: public DigestEdit put(String id) {
163: return (DigestEdit) super .putResource(id, null);
164: }
165:
166: public DigestEdit edit(String id) {
167: return (DigestEdit) super .editResource(id);
168: }
169:
170: public void commit(DigestEdit edit) {
171: super .commitResource(edit);
172: }
173:
174: public void cancel(DigestEdit edit) {
175: super .cancelResource(edit);
176: }
177:
178: public void remove(DigestEdit edit) {
179: super.removeResource(edit);
180: }
181: }
182: }
|