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.rawstoredrivers;
009:
010: import com.uwyn.rife.cmf.Content;
011: import com.uwyn.rife.cmf.dam.ContentDataUser;
012: import com.uwyn.rife.cmf.dam.contentstores.DatabaseRawStore;
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: import java.sql.Blob;
024:
025: public class generic extends DatabaseRawStore {
026: protected CreateTable mCreateTableContentInfo = null;
027: protected CreateTable mCreateTableContentChunk = null;
028: protected DropTable mDropTableContentInfo = null;
029: protected DropTable mDropTableContentChunk = null;
030: protected Insert mStoreContentInfo = null;
031: protected Delete mDeleteContentInfo = null;
032: protected Select mRetrieveSize = null;
033: protected Select mHasContentData = null;
034: protected Insert mStoreContentChunk = null;
035: protected Delete mDeleteContentChunk = null;
036: protected Select mRetrieveContentChunks = null;
037:
038: public generic(Datasource datasource) {
039: super (datasource);
040:
041: mCreateTableContentInfo = new CreateTable(getDatasource())
042: .table(RifeConfig.Cmf.getTableContentStoreRawInfo())
043: .column("contentId", int.class, CreateTable.NOTNULL)
044: .column(getContentSizeColumnName(), int.class,
045: CreateTable.NOTNULL).primaryKey(
046: ("PK_" + RifeConfig.Cmf
047: .getTableContentStoreRawInfo())
048: .toUpperCase(), "contentId")
049: .foreignKey(
050: ("FK_" + RifeConfig.Cmf
051: .getTableContentStoreRawInfo())
052: .toUpperCase(),
053: RifeConfig.Cmf.getTableContentInfo(),
054: "contentId", "contentId");
055:
056: mCreateTableContentChunk = new CreateTable(getDatasource())
057: .table(RifeConfig.Cmf.getTableContentStoreRawChunk())
058: .column("contentId", int.class, CreateTable.NOTNULL)
059: .column("ordinal", int.class, CreateTable.NOTNULL)
060: .column("chunk", Blob.class).primaryKey(
061: ("PK_" + RifeConfig.Cmf
062: .getTableContentStoreRawChunk())
063: .toUpperCase(),
064: new String[] { "contentId", "ordinal" })
065: .foreignKey(
066: ("FK_" + RifeConfig.Cmf
067: .getTableContentStoreRawChunk())
068: .toUpperCase(),
069: RifeConfig.Cmf.getTableContentInfo(),
070: "contentId", "contentId");
071:
072: mDropTableContentInfo = new DropTable(getDatasource())
073: .table(RifeConfig.Cmf.getTableContentStoreRawInfo());
074:
075: mDropTableContentChunk = new DropTable(getDatasource())
076: .table(RifeConfig.Cmf.getTableContentStoreRawChunk());
077:
078: mStoreContentInfo = new Insert(getDatasource()).into(
079: RifeConfig.Cmf.getTableContentStoreRawInfo())
080: .fieldParameter("contentId").fieldParameter(
081: getContentSizeColumnName());
082:
083: mDeleteContentInfo = new Delete(getDatasource()).from(
084: RifeConfig.Cmf.getTableContentStoreRawInfo())
085: .whereParameter("contentId", "=");
086:
087: mRetrieveSize = new Select(getDatasource()).from(
088: RifeConfig.Cmf.getTableContentStoreRawInfo()).field(
089: getContentSizeColumnName()).whereParameter("contentId",
090: "=");
091:
092: mHasContentData = new Select(getDatasource()).from(
093: RifeConfig.Cmf.getTableContentStoreRawInfo()).field(
094: "contentId").whereParameter("contentId", "=").whereAnd(
095: getContentSizeColumnName(), "!=", 0);
096:
097: mStoreContentChunk = new Insert(getDatasource()).into(
098: RifeConfig.Cmf.getTableContentStoreRawChunk())
099: .fieldParameter("contentId").fieldParameter("ordinal")
100: .fieldParameter("chunk");
101:
102: mDeleteContentChunk = new Delete(getDatasource()).from(
103: RifeConfig.Cmf.getTableContentStoreRawChunk())
104: .whereParameter("contentId", "=");
105:
106: mRetrieveContentChunks = new Select(getDatasource()).from(
107: RifeConfig.Cmf.getTableContentStoreRawChunk()).field(
108: "chunk").whereParameter("contentId", "=").orderBy(
109: "ordinal");
110: }
111:
112: public boolean install() throws ContentManagerException {
113: return _install(mCreateTableContentInfo,
114: mCreateTableContentChunk);
115: }
116:
117: public boolean remove() throws ContentManagerException {
118: return _remove(mDropTableContentInfo, mDropTableContentChunk);
119: }
120:
121: public boolean storeContentData(int id, Content content,
122: ContentTransformer transformer)
123: throws ContentManagerException {
124: return _storeContentData(mStoreContentInfo, mStoreContentChunk,
125: id, content, transformer);
126: }
127:
128: public boolean deleteContentData(int id)
129: throws ContentManagerException {
130: return _deleteContentData(mDeleteContentInfo,
131: mDeleteContentChunk, id);
132: }
133:
134: public <ResultType> ResultType useContentData(int id,
135: ContentDataUser user) throws ContentManagerException {
136: return (ResultType) _useContentData(mRetrieveContentChunks, id,
137: user);
138: }
139:
140: public int getSize(int id) throws ContentManagerException {
141: return _getSize(mRetrieveSize, id);
142: }
143:
144: public boolean hasContentData(int id)
145: throws ContentManagerException {
146: return _hasContentData(mHasContentData, id);
147: }
148:
149: public void serveContentData(ElementSupport element, int id)
150: throws ContentManagerException {
151: _serveContentData(mRetrieveContentChunks, element, id);
152: }
153: }
|