001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: generic.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.cmf.dam.contentstores.textstoredrivers;
009:
010: import com.uwyn.rife.cmf.Content;
011: import com.uwyn.rife.cmf.dam.ContentDataUser;
012: import com.uwyn.rife.cmf.dam.contentstores.DatabaseTextStore;
013: import com.uwyn.rife.cmf.dam.exceptions.ContentManagerException;
014: import com.uwyn.rife.cmf.transform.ContentTransformer;
015: import com.uwyn.rife.config.RifeConfig;
016: import com.uwyn.rife.database.Datasource;
017: import com.uwyn.rife.database.queries.CreateTable;
018: import com.uwyn.rife.database.queries.Delete;
019: import com.uwyn.rife.database.queries.DropTable;
020: import com.uwyn.rife.database.queries.Insert;
021: import com.uwyn.rife.database.queries.Select;
022: import com.uwyn.rife.engine.ElementSupport;
023:
024: public class generic extends DatabaseTextStore {
025: protected CreateTable mCreateTableContent = null;
026: protected DropTable mDropTableContent = null;
027: protected Insert mStoreContentData = null;
028: protected Delete mDeleteContentData = null;
029: protected Select mRetrieveContent = null;
030: protected Select mRetrieveSize = null;
031: protected Select mHasContentData = null;
032:
033: public generic(Datasource datasource) {
034: super (datasource);
035:
036: mCreateTableContent = new CreateTable(getDatasource()).table(
037: RifeConfig.Cmf.getTableContentStoreText()).column(
038: "contentId", int.class, CreateTable.NOTNULL).column(
039: getContentSizeColumnName(), int.class,
040: CreateTable.NOTNULL).column("content", String.class)
041: .primaryKey(
042: ("PK_" + RifeConfig.Cmf
043: .getTableContentStoreText())
044: .toUpperCase(), "contentId")
045: .foreignKey(
046: ("FK_" + RifeConfig.Cmf
047: .getTableContentStoreText())
048: .toUpperCase(),
049: RifeConfig.Cmf.getTableContentInfo(),
050: "contentId", "contentId");
051:
052: mDropTableContent = new DropTable(getDatasource())
053: .table(RifeConfig.Cmf.getTableContentStoreText());
054:
055: mStoreContentData = new Insert(getDatasource()).into(
056: RifeConfig.Cmf.getTableContentStoreText())
057: .fieldParameter("contentId").fieldParameter(
058: getContentSizeColumnName()).fieldParameter(
059: "content");
060:
061: mDeleteContentData = new Delete(getDatasource()).from(
062: RifeConfig.Cmf.getTableContentStoreText())
063: .whereParameter("contentId", "=");
064:
065: mRetrieveContent = new Select(getDatasource()).from(
066: RifeConfig.Cmf.getTableContentStoreText()).field(
067: "content").field(getContentSizeColumnName())
068: .whereParameter("contentId", "=");
069:
070: mRetrieveSize = new Select(getDatasource()).from(
071: RifeConfig.Cmf.getTableContentStoreText()).field(
072: getContentSizeColumnName()).whereParameter("contentId",
073: "=");
074:
075: mHasContentData = new Select(getDatasource()).from(
076: RifeConfig.Cmf.getTableContentStoreText()).field(
077: "contentId").whereParameter("contentId", "=").whereAnd(
078: getContentSizeColumnName(), "!=", 0);
079: }
080:
081: public boolean install() throws ContentManagerException {
082: return _install(mCreateTableContent);
083: }
084:
085: public boolean remove() throws ContentManagerException {
086: return _remove(mDropTableContent);
087: }
088:
089: public boolean storeContentData(int id, Content content,
090: ContentTransformer transformer)
091: throws ContentManagerException {
092: return _storeContentData(mStoreContentData, id, content,
093: transformer);
094: }
095:
096: public boolean deleteContentData(int id)
097: throws ContentManagerException {
098: return _deleteContentData(mDeleteContentData, id);
099: }
100:
101: public <ResultType> ResultType useContentData(int id,
102: ContentDataUser user) throws ContentManagerException {
103: return (ResultType) _useContentData(mRetrieveContent, id, user);
104: }
105:
106: public int getSize(int id) throws ContentManagerException {
107: return _getSize(mRetrieveSize, id);
108: }
109:
110: public boolean hasContentData(int id)
111: throws ContentManagerException {
112: return _hasContentData(mHasContentData, id);
113: }
114:
115: public void serveContentData(ElementSupport element, int id)
116: throws ContentManagerException {
117: _serveContentData(mRetrieveContent, element, id);
118: }
119: }
|