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.imagestoredrivers;
009:
010: import com.uwyn.rife.cmf.Content;
011: import com.uwyn.rife.cmf.dam.ContentDataUser;
012: import com.uwyn.rife.cmf.dam.contentstores.DatabaseImageStore;
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 DatabaseImageStore {
026: protected CreateTable mCreateTableContent = null;
027: protected DropTable mDropTableContent = null;
028: protected Insert mStoreContentData = null;
029: protected Delete mDeleteContentData = null;
030: protected Select mRetrieveContent = null;
031: protected Select mRetrieveSize = null;
032: protected Select mHasContentData = null;
033:
034: public generic(Datasource datasource) {
035: super (datasource);
036:
037: mCreateTableContent = new CreateTable(getDatasource()).table(
038: RifeConfig.Cmf.getTableContentStoreImage()).column(
039: "contentId", int.class, CreateTable.NOTNULL).column(
040: getContentSizeColumnName(), int.class,
041: CreateTable.NOTNULL).column("content", Blob.class)
042: .primaryKey(
043: ("PK_" + RifeConfig.Cmf
044: .getTableContentStoreImage())
045: .toUpperCase(), "contentId")
046: .foreignKey(
047: ("FK_" + RifeConfig.Cmf
048: .getTableContentStoreImage())
049: .toUpperCase(),
050: RifeConfig.Cmf.getTableContentInfo(),
051: "contentId", "contentId");
052:
053: mDropTableContent = new DropTable(getDatasource())
054: .table(RifeConfig.Cmf.getTableContentStoreImage());
055:
056: mStoreContentData = new Insert(getDatasource()).into(
057: RifeConfig.Cmf.getTableContentStoreImage())
058: .fieldParameter("contentId").fieldParameter(
059: getContentSizeColumnName()).fieldParameter(
060: "content");
061:
062: mDeleteContentData = new Delete(getDatasource()).from(
063: RifeConfig.Cmf.getTableContentStoreImage())
064: .whereParameter("contentId", "=");
065:
066: mRetrieveContent = new Select(getDatasource()).from(
067: RifeConfig.Cmf.getTableContentStoreImage()).field(
068: "content").field(getContentSizeColumnName())
069: .whereParameter("contentId", "=");
070:
071: mRetrieveSize = new Select(getDatasource()).from(
072: RifeConfig.Cmf.getTableContentStoreImage()).field(
073: getContentSizeColumnName()).whereParameter("contentId",
074: "=");
075:
076: mHasContentData = new Select(getDatasource()).from(
077: RifeConfig.Cmf.getTableContentStoreImage()).field(
078: "contentId").whereParameter("contentId", "=").whereAnd(
079: getContentSizeColumnName(), "!=", 0);
080: }
081:
082: public boolean install() throws ContentManagerException {
083: return _install(mCreateTableContent);
084: }
085:
086: public boolean remove() throws ContentManagerException {
087: return _remove(mDropTableContent);
088: }
089:
090: public boolean storeContentData(int id, Content content,
091: ContentTransformer transformer)
092: throws ContentManagerException {
093: return _storeContentData(mStoreContentData, id, content,
094: transformer);
095: }
096:
097: public boolean deleteContentData(int id)
098: throws ContentManagerException {
099: return _deleteContentData(mDeleteContentData, id);
100: }
101:
102: public <ResultType> ResultType useContentData(int id,
103: ContentDataUser user) throws ContentManagerException {
104: return (ResultType) _useContentData(mRetrieveContent, id, user);
105: }
106:
107: public int getSize(int id) throws ContentManagerException {
108: return _getSize(mRetrieveSize, id);
109: }
110:
111: public boolean hasContentData(int id)
112: throws ContentManagerException {
113: return _hasContentData(mHasContentData, id);
114: }
115:
116: public void serveContentData(ElementSupport element, int id)
117: throws ContentManagerException {
118: _serveContentData(mRetrieveContent, element, id);
119: }
120: }
|