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.authentication.remembermanagers.databasedrivers;
009:
010: import com.uwyn.rife.authentication.exceptions.RememberManagerException;
011: import com.uwyn.rife.authentication.remembermanagers.DatabaseRemember;
012: import com.uwyn.rife.config.RifeConfig;
013: import com.uwyn.rife.database.Datasource;
014: import com.uwyn.rife.database.queries.CreateTable;
015: import com.uwyn.rife.database.queries.Delete;
016: import com.uwyn.rife.database.queries.DropTable;
017: import com.uwyn.rife.database.queries.Insert;
018: import com.uwyn.rife.database.queries.Select;
019:
020: public class generic extends DatabaseRemember {
021: protected CreateTable mCreateRemember = null;
022: protected String mCreateRememberMomentIndex = null;
023: protected DropTable mRemoveRemember = null;
024: protected String mRemoveRememberMomentIndex = null;
025: protected Insert mCreateRememberId = null;
026: protected Delete mEraseRememberId = null;
027: protected Delete mEraseUserRememberIds = null;
028: protected Delete mEraseAllRememberIds = null;
029: protected Select mGetRememberedUserId = null;
030: protected Delete mPurgeRememberIds = null;
031:
032: public generic(Datasource datasource) {
033: super (datasource);
034:
035: mCreateRemember = new CreateTable(getDatasource()).table(
036: RifeConfig.Authentication.getTableRemember()).column(
037: "rememberId", String.class, 32, CreateTable.NOTNULL)
038: .column("userId", long.class, CreateTable.NOTNULL)
039: .column("moment", long.class, CreateTable.NOTNULL)
040: .primaryKey(
041: RifeConfig.Authentication.getTableRemember()
042: .toUpperCase()
043: + "_PK", "rememberId");
044:
045: mCreateRememberMomentIndex = "CREATE INDEX "
046: + RifeConfig.Authentication.getTableRemember()
047: + "_moment_IDX ON "
048: + RifeConfig.Authentication.getTableRemember()
049: + " (moment)";
050:
051: mRemoveRemember = new DropTable(getDatasource())
052: .table(mCreateRemember.getTable());
053:
054: mRemoveRememberMomentIndex = "DROP INDEX "
055: + RifeConfig.Authentication.getTableRemember()
056: + "_moment_IDX";
057:
058: mCreateRememberId = new Insert(getDatasource()).into(
059: mCreateRemember.getTable())
060: .fieldParameter("rememberId").fieldParameter("userId")
061: .fieldParameter("moment");
062:
063: mEraseRememberId = new Delete(getDatasource()).from(
064: mCreateRemember.getTable()).whereParameter(
065: "rememberId", "=");
066:
067: mEraseUserRememberIds = new Delete(getDatasource()).from(
068: mCreateRemember.getTable()).whereParameter("userId",
069: "=");
070:
071: mEraseAllRememberIds = new Delete(getDatasource())
072: .from(mCreateRemember.getTable());
073:
074: mGetRememberedUserId = new Select(getDatasource()).field(
075: "userId").from(mCreateRemember.getTable())
076: .whereParameter("rememberId", "=");
077:
078: mPurgeRememberIds = new Delete(getDatasource()).from(
079: mCreateRemember.getTable()).whereParameter("moment",
080: "<=");
081: }
082:
083: public boolean install() throws RememberManagerException {
084: return _install(mCreateRemember, mCreateRememberMomentIndex);
085: }
086:
087: public boolean remove() throws RememberManagerException {
088: return _remove(mRemoveRemember, mRemoveRememberMomentIndex);
089: }
090:
091: public String createRememberId(long userId, String hostIp)
092: throws RememberManagerException {
093: return _createRememberId(mCreateRememberId, userId, hostIp);
094: }
095:
096: public boolean eraseRememberId(String rememberId)
097: throws RememberManagerException {
098: return _eraseRememberId(mEraseRememberId, rememberId);
099: }
100:
101: public boolean eraseUserRememberIds(long userId)
102: throws RememberManagerException {
103: return _eraseUserRememberIds(mEraseUserRememberIds, userId);
104: }
105:
106: public void eraseAllRememberIds() throws RememberManagerException {
107: _eraseAllRememberIds(mEraseAllRememberIds);
108: }
109:
110: public long getRememberedUserId(String rememberId)
111: throws RememberManagerException {
112: return _getRememberedUserId(mGetRememberedUserId, rememberId);
113: }
114:
115: public void purgeRememberIds() throws RememberManagerException {
116: _purgeRememberIds(mPurgeRememberIds);
117: }
118: }
|