⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indextable.java

📁 iiitAccessServer是一个用Java编写的基于规则的企业鉴别系统。它作为一个服务器工作
💻 JAVA
字号:
/******************************************************************************* * Copyright (C) 2002, 2003 * ingenieurbuero fuer innovative informationstechnik (iiit) * Dipl.-Ing. Joerg Beckmann, Dortmund, Germany * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * version $Id: IndexTable.java,v 1.13 2003/04/13 20:16:42 joerg Exp $ ******************************************************************************/package de.iiit.access.server.util.db.cachedb;import de.iiit.jdbc.*;import java.util.*;/** For every expression or group found in the LDAP database there will be exactly * on table in the cache database. The cache tables are numbered consecutively when * they are created. The index table holds the relation between the name of the * expression or group - represented by its MD5 checksum - and the table containig * the data. */public class IndexTable{    /** CVS Version Tag */    private static final String vcid = "$Id: IndexTable.java,v 1.13 2003/04/13 20:16:42 joerg Exp $";    private static final String indexTable = "indextable";    private static final String createStmt =         "create table " + indexTable + "("         +            "exprkey      char(33) primary key, "   +             "tablename    char(20),"                +            "creationtime bigint)";        private static final String searchStmt =         "select count(*) " +             "from " + indexTable + " " +             "where exprkey = ?";        private static final String searchStmt2 =         "select count(*) " +             "from " + indexTable + " " +             "where tablename = ?";        private static final String selectStmt =         "select exprkey, tablename, "   +             "creationtime "             +             "from " + indexTable + " "  +            "where exprkey = ?";        private static final String selectStmt2 =         "select tablename "   +             "from " + indexTable;        private static final String insertStmt =         "insert into " + indexTable + " " +             "(exprkey, tablename, creationtime) " +             " values (?, ?, ?)";    private static final String updateStmt =         "update " + indexTable + " "    +             "set tableName = ?, "       +             "creationTime = ? "         +            "where exprKey = ?";        private static final String deleteStmt =         "delete from " + indexTable + " " +             "where exprKey = ?";        private String exprKey;    private String tableName;    private long   creationTime;        /** Creates a new instance of IndexTable */    private IndexTable()    {    }    /** Creates a new instance of IndexTable     * @param exprKey the MD5 sum of the name of the expression or group     * @param tableName the name of the table     * @param creationTime the creation time of the cache table in milliseconds since January, 1st 1970.     */        public IndexTable(String exprKey, String tableName, long creationTime)    {        this.exprKey = exprKey;        this.tableName = tableName;        this.creationTime = creationTime;    }    /** Creates a new database table todolist.     * Returns     * @param pool The database handle to use     * @throws JdbcException if a JDBC error occurs     * @return true if table had to be created, false is table was already there     */    public static boolean createIndexTable(JdbcConnectionPool pool) throws JdbcException    {        boolean result = false;                JdbcDatabaseMetaData md = pool.getMetaData();        JdbcResultSet rs = md.getTables(null, null, indexTable, new String[] { "TABLE" });        if (! rs.next())        {            result = true;            JdbcStatement stmt = pool.createStatement();            stmt.execute(createStmt);                        stmt.close();        }                rs.close();        return result;    }        /** Searches the index for a name of an expression or group     * @param pool The database handle to use     * @param expressionName The name to search for     * @throws JdbcException if a JDBC error occurs     * @return True if the name was found or false if not.     */        public static boolean searchIndex(JdbcConnectionPool pool, String expressionName) throws JdbcException    {        JdbcPreparedStatement search = pool.prepareStatement(searchStmt);                    search.setString(1, expressionName);                    JdbcResultSet rs = search.executeQuery();                                    rs.first();        int count = rs.getInt(1);        rs.close();        search.close();        return (count != 0);    }    /** Searches the index for a name of a cache table     * @param pool The database handle to use     * @param tablename The name to search for     * @throws JdbcException if a JDBC error occurs     * @return True if the name was found or false if not.     */        public static boolean searchIndex2(JdbcConnectionPool pool, String tablename) throws JdbcException    {        JdbcPreparedStatement search = pool.prepareStatement(searchStmt2);                    search.setString(1, tablename);                    JdbcResultSet rs = search.executeQuery();                                    rs.first();        int count = rs.getInt(1);        rs.close();        search.close();        return (count != 0);    }    /** Reads one record from the index table     * @param pool The database handle to use     * @param name The name to search for     * @throws JdbcException if a JDBC error occurs     * @return The read record or null if there was no one found.     */        public static IndexTable selectIndex(JdbcConnectionPool pool, String name) throws JdbcException    {        IndexTable result = null;        JdbcPreparedStatement select = pool.prepareStatement(selectStmt);                    select.setString(1, name);        JdbcResultSet rs = select.executeQuery();                                    if (rs.first())        {            result = new IndexTable();                        result.setExprKey(rs.getString(1));            result.setTableName(rs.getString(2));            result.setCreationTime(rs.getLong(3));        }        rs.close();        select.close();        return result;    }    /** Reads all table names from the index table     * @param pool The database handle to use     * @throws JdbcException if a JDBC error occurs     * @return All table names contained in the index table     */        public static Set selectAllTableNames(JdbcConnectionPool pool) throws JdbcException    {        HashSet result = new HashSet();                JdbcPreparedStatement select = pool.prepareStatement(selectStmt2);                    JdbcResultSet rs = select.executeQuery();                while (rs.next())        {            result.add(rs.getString(1));        }                rs.close();        select.close();        return result;    }        /** Inserts the current object into the index table     * @param pool The database handle to use     * @throws JdbcException if a JDBC error occurs     */        public void insertIndex(JdbcConnectionPool pool) throws JdbcException    {        JdbcPreparedStatement insert = pool.prepareStatement(insertStmt);                insert.setString(1, exprKey);        insert.setString(2, tableName);        insert.setLong  (3, creationTime);        insert.executeUpdate();        insert.close();    }    /** Writes the content of the current object back to the database     * @param pool The database handle to use     * @throws JdbcException if a JDBC error occurs     */        public void updateIndex(JdbcConnectionPool pool) throws JdbcException    {        JdbcPreparedStatement update = pool.prepareStatement(updateStmt);        update.setString(1, tableName);        update.setLong  (2, creationTime);        update.setString(3, exprKey);        update.executeUpdate();        update.close();    }    /** Deletes the current object from the database.     * @param pool The database handle to use     * @throws JdbcException if a JDBC error occurs     */        public void deleteIndex(JdbcConnectionPool pool) throws JdbcException    {        JdbcPreparedStatement delete = pool.prepareStatement(deleteStmt);                delete.setString(1, exprKey);        delete.executeUpdate();        delete.close();    }    /** Writes the content of the current object back to the database.     * If it is new it will be inserted, otherwise the record will be updated.     * @param pool The database handle to use     * @throws JdbcException if a JDBC error occurs     */        public void writeIndex(JdbcConnectionPool pool) throws JdbcException    {        if (! searchIndex(pool, exprKey))            insertIndex(pool);        else            updateIndex(pool);    }    /** Sets the exprkey-field of the current object.     * @param exprKey the MD5 sum of the name of the expression or group     */        public void setExprKey(String exprKey)    {        this.exprKey = exprKey;    }        /** Sets the tablename-field of the current object.     * @param tableName the name of the cache table     */        public void setTableName(String tableName)    {        this.tableName = tableName;    }        /** Sets the creationtime-field of the current object     * @param creationTime the creation time of the cache table in milliseconds since January, 1st 1970.     */        public void setCreationTime(long creationTime)    {        this.creationTime = creationTime;    }                /** Retrieves the exprkey-field of the current object.     * @return the MD5 sum of the name of the expression or group     */        public String getExprKey()    {        return exprKey;    }        /** Retrieves the tablename-field of the current object.     * @return the name of the cache table     */        public String getTableName()    {        return tableName;    }        /** Retrieves the creationtime-field of the current object     * @return the creation time of the cache table in milliseconds since January, 1st 1970.     */        public long getCreationTime()    {        return creationTime;    }}/** * $Log: IndexTable.java,v $ * Revision 1.13  2003/04/13 20:16:42  joerg * Package structure modified * * Revision 1.12  2003/01/01 21:04:18  joerg * Copyright-Statement aktualisiert * * Revision 1.11  2002/12/23 11:28:23  joerg * no message * * Revision 1.10  2002/12/21 19:55:04  joerg * Nicht mehr benoetigte Methoden entfernt, interne Methoden auf * private oder protected geaendert. * JavaDoc Kommentare ergaenzt. * * Revision 1.9  2002/12/19 15:54:33  joerg * Paket umbenannt in iiitLdapPlugin * * Revision 1.8  2002/12/08 16:09:46  joerg * Paket-Struktur ueberarbeitet * * Revision 1.7  2002/11/21 21:49:45  joerg * Umstellung auf JdbcConnectionPool * * Revision 1.6  2002/11/21 09:11:53  joerg * Neue Methode selectAllTableNames() * * Revision 1.5  2002/11/20 20:41:29  joerg * Klassen fuer das HAndling der DB-Tabellen in Packages * de.iiit.AccessServer.db.* verschoben * * Revision 1.4  2002/11/20 20:24:12  joerg * Reste der Spalte 'inverted' entfernt * * Revision 1.3  2002/11/20 12:42:07  joerg * Spalte 'inverted' entfernt * * Revision 1.2  2002/11/18 22:09:00  joerg * CacheManager ausgelagert als PlugIn * * Revision 1.1  2002/11/18 10:17:49  joerg * Klassen des CacheManagers in eigenes Package verschoben * * Revision 1.1  2002/11/17 22:03:26  joerg * Neue Klassen fuer 2nd-level Cache * */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -