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.resources.databasedrivers;
009:
010: import com.uwyn.rife.database.queries.*;
011:
012: import com.uwyn.rife.config.RifeConfig;
013: import com.uwyn.rife.database.Datasource;
014: import com.uwyn.rife.resources.DatabaseResources;
015: import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
016: import com.uwyn.rife.resources.exceptions.ResourceWriterErrorException;
017: import com.uwyn.rife.tools.InnerClassException;
018: import com.uwyn.rife.tools.InputStreamUser;
019: import java.net.URL;
020:
021: public class generic extends DatabaseResources {
022: protected CreateTable mCreateTable = null;
023: protected DropTable mDropTable = null;
024: protected Insert mAddResource = null;
025: protected Update mUpdateResource = null;
026: protected Delete mRemoveResource = null;
027: protected Select mHasResource = null;
028: protected Select mGetResourceContent = null;
029: protected Select mGetResourceModified = null;
030:
031: public generic(Datasource datasource) {
032: super (datasource);
033:
034: String table = RifeConfig.Resources.getTableResources();
035:
036: mCreateTable = new CreateTable(getDatasource()).table(table)
037: .column(COLUMN_NAME, String.class, 255,
038: CreateTable.NOTNULL).column(COLUMN_CONTENT,
039: String.class).column(COLUMN_MODIFIED,
040: java.sql.Timestamp.class).primaryKey(
041: COLUMN_NAME);
042:
043: mDropTable = new DropTable(getDatasource()).table(table);
044:
045: mAddResource = new Insert(getDatasource()).into(table)
046: .fieldParameter(COLUMN_NAME).fieldParameter(
047: COLUMN_CONTENT).fieldParameter(COLUMN_MODIFIED);
048:
049: mUpdateResource = new Update(getDatasource()).table(table)
050: .fieldParameter(COLUMN_CONTENT).fieldParameter(
051: COLUMN_MODIFIED).whereParameter(COLUMN_NAME,
052: "=");
053:
054: mRemoveResource = new Delete(getDatasource()).from(table)
055: .whereParameter(COLUMN_NAME, "=");
056:
057: mHasResource = new Select(getDatasource()).from(table).field(
058: COLUMN_NAME).whereParameter(COLUMN_NAME, "=");
059:
060: mGetResourceContent = new Select(getDatasource()).from(table)
061: .field(COLUMN_CONTENT).whereParameter(COLUMN_NAME, "=");
062:
063: mGetResourceModified = new Select(getDatasource()).from(table)
064: .field(COLUMN_MODIFIED)
065: .whereParameter(COLUMN_NAME, "=");
066: }
067:
068: public boolean install() throws ResourceWriterErrorException {
069: return _install(mCreateTable);
070: }
071:
072: public boolean remove() throws ResourceWriterErrorException {
073: return _remove(mDropTable);
074: }
075:
076: public void addResource(String name, String content)
077: throws ResourceWriterErrorException {
078: _addResource(mAddResource, name, content);
079: }
080:
081: public boolean updateResource(String name, String content)
082: throws ResourceWriterErrorException {
083: return _updateResource(mUpdateResource, name, content);
084: }
085:
086: public boolean removeResource(String name)
087: throws ResourceWriterErrorException {
088: return _removeResource(mRemoveResource, name);
089: }
090:
091: public URL getResource(String name) {
092: return _getResource(mHasResource, name);
093: }
094:
095: public <ResultType> ResultType useStream(URL resource,
096: InputStreamUser user) throws ResourceFinderErrorException,
097: InnerClassException {
098: return (ResultType) _useStream(mGetResourceContent, resource,
099: user);
100: }
101:
102: public String getContent(URL resource, String encoding)
103: throws ResourceFinderErrorException {
104: return _getContent(mGetResourceContent, resource, encoding);
105: }
106:
107: public long getModificationTime(URL resource)
108: throws ResourceFinderErrorException {
109: return _getModificationTime(mGetResourceModified, resource);
110: }
111: }
|