📄 cachetable.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: CacheTable.java,v 1.15 2003/04/13 20:16:42 joerg Exp $ ******************************************************************************/package de.iiit.access.server.util.db.cachedb;import de.iiit.jdbc.*;import org.apache.log4j.Logger;import java.util.*;/** A cache table holds the complete result set of the expression or group it * belongs to. Later on, when we want to know whether someone is member of the * group described described by the expression, we are only interested in fact * whether there is a record with the name of the user or not. We will never need * the record itself. */public class CacheTable{ /** CVS Version Tag */ private static final String vcid = "$Id: CacheTable.java,v 1.15 2003/04/13 20:16:42 joerg Exp $"; private static Logger logger = Logger.getLogger("CacheTable"); /** Creates a new instance of CacheTable */ private CacheTable() { } /** Creates a new empty cache table * @param pool The database handle to use * @param name The name of the table to create. * @throws JdbcException if a JDBC error occurs */ public static void createCacheTable(JdbcConnectionPool pool, String name) throws JdbcException { JdbcStatement stmt = pool.createStatement(); stmt.execute("create table " + name + " (" + "user varchar(255) primary key)"); stmt.close(); } /** Drops a cache table which is no longer needed. * @param pool The database handle to use * @param name The name of the table to drop. * @throws JdbcException if a JDBC error occurs */ public static void dropCacheTable(JdbcConnectionPool pool, String name) throws JdbcException { JdbcStatement stmt = pool.createStatement(); stmt.execute("drop table " + name); stmt.close(); } /** Inserts a list of names into an already existing cache table. * @param pool The database handle to use * @param name The name of the table to fill * @param set the names to insert into the table * @param toLower forces all data to be converted to lower case if its value is true * @throws JdbcException if a JDBC error occurs */ public static void insertCacheTable(JdbcConnectionPool pool, String name, Set set, boolean toLower) throws JdbcException { JdbcPreparedStatement insert = pool.prepareStatement("insert into " + name + " values (?)"); Iterator i = set.iterator(); while (i.hasNext()) { String s = (String) i.next(); if (toLower) s = s.toLowerCase(); insert.setString(1, s); insert.executeUpdate(); } insert.close(); } /** Searches a cache table for the name of an user. * @param pool The database handle to use * @param name The name of the table to search in * @param user The name of the user to search for * @throws JdbcException if a JDBC error occurs * @return true if the table contains the name, false if not. */ public static boolean searchCacheTable(JdbcConnectionPool pool, String name, String user) throws JdbcException { JdbcPreparedStatement search = pool.prepareStatement("select count(*) from " + name + " where user = ?"); search.setString(1, user); JdbcResultSet rs = search.executeQuery(); rs.first(); int count = rs.getInt(1); rs.close(); search.close(); return (count != 0); } /** Searches for cache tables not contained in the index table. All found tables * will be dropped. * @param pool The database handle to use * @throws JdbcException if a JDBC error occurs */ public static void dropLostTables(JdbcConnectionPool pool) throws JdbcException { JdbcDatabaseMetaData md = pool.getMetaData(); JdbcResultSet rs = md.getTables(null, null, "T%", new String[] { "TABLE" }); Set tableNames = IndexTable.selectAllTableNames(pool); while (rs.next()) { String t = rs.getString(3); if (! tableNames.contains(t)) { logger.info("Dropping lost table = <" + t + ">"); dropCacheTable(pool, t); } } rs.close(); }}/** * $Log: CacheTable.java,v $ * Revision 1.15 2003/04/13 20:16:42 joerg * Package structure modified * * Revision 1.14 2003/01/16 21:47:46 joerg * no message * * Revision 1.13 2003/01/04 17:15:43 joerg * Zus鋞zliche Config-Option IgnoreCase * * 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:37:33 joerg * Aufraeumungsarbeiten nach dem grossen Umbau * * Revision 1.7 2002/12/08 16:09:46 joerg * Paket-Struktur ueberarbeitet * * Revision 1.6 2002/11/21 21:49:45 joerg * Umstellung auf JdbcConnectionPool * * Revision 1.5 2002/11/21 09:13:05 joerg * Verlorene Tabellen werden jetzt nicht mehr einzeln in der * IndexTabelle gesucht sondern mit den vorab daraus geldenenen * Tabellen-Namen verglichen. * * Revision 1.4 2002/11/21 08:35:46 joerg * Neue Methode searchCacheTable() * * Revision 1.3 2002/11/20 20:41:29 joerg * Klassen fuer das HAndling der DB-Tabellen in Packages * de.iiit.AccessServer.db.* verschoben * * 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 + -