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

📄 propertytable.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: PropertyTable.java,v 1.11 2003/04/13 20:16:42 joerg Exp $ ******************************************************************************/package de.iiit.access.server.util.db;import de.iiit.jdbc.*;/** Every database controlled by the cache manager will contain a property table. * These table can be used like property files, they contain records with pairs of * key and values. Until now they will be used only to store the number of the next * cache table to create. */public class PropertyTable{    /** CVS Version Tag */    private static final String vcid = "$Id: PropertyTable.java,v 1.11 2003/04/13 20:16:42 joerg Exp $";    private static final String propertyTable = "properties";    private static final String createStmt =         "create table " + propertyTable + "("       +            "property   varchar(255) primary key, " +            "value      varchar(255))";        private static final String selectStmt =         "select value " +             "from " + propertyTable + " " +             "where property = ?";        private static final String searchStmt =         "select count(*) " +             "from " + propertyTable + " " +             "where property = ?";        private static final String insertStmt =         "insert into " + propertyTable + " " +             "(property, value) " +             "values (?, ?)";        private static final String updateStmt =         "update " + propertyTable + " " +             "set value = ? " +             "where property = ?";        /** Creates a new instance of PropertyTable */    private PropertyTable()    {    }    /** Creates a new property table     * @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 createPropertyTable(JdbcConnectionPool pool) throws JdbcException    {        boolean result = false;                JdbcDatabaseMetaData md = pool.getMetaData();        JdbcResultSet rs = md.getTables(null, null, propertyTable, new String[] { "TABLE" });        if (! rs.next())        {            result = true;            JdbcStatement stmt = pool.createStatement();            stmt.execute(createStmt);            stmt.close();        }                rs.close();        return result;    }        /** Retrieves one property record     * @param pool The database handle to use     * @param property The name of the property to search for     * @throws JdbcException if a JDBC error occurs     * @return the value of the property or null if no property with the given name was found.     */        public static String selectProperty(JdbcConnectionPool pool, String property) throws JdbcException    {        String result = null;        JdbcPreparedStatement select = pool.prepareStatement(selectStmt);                    select.setString(1, property);        JdbcResultSet rs = select.executeQuery();                                    if (rs.first())            result = rs.getString(1);        rs.close();        select.close();        return result;    }    /** Retrieves one property record     * @param pool The database handle to use     * @param property The name of the property to search for     * @param defaultValue a default value.     * @throws JdbcException if a JDBC error occurs     * @return the value of the property or null if no property with the given name was found.     */        public static String selectProperty(JdbcConnectionPool pool, String property, String defaultValue) throws JdbcException    {        String result = selectProperty(pool, property);                if (result == null)            result = defaultValue;        return result;    }    /** Test whether a property with a given name is there     * @param pool The database handle to use     * @param property The name of the property to search for     * @throws JdbcException if a JDBC error occurs     * @return True if the property was found, false if not.     */        public static boolean searchProperty(JdbcConnectionPool pool, String property) throws JdbcException    {        JdbcPreparedStatement search = pool.prepareStatement(searchStmt);                       search.setString(1, property);                    JdbcResultSet rs = search.executeQuery();                                    rs.first();        int count = rs.getInt(1);        rs.close();        search.close();        return (count != 0);    }    /** Inserts a new record into the property table     * @param pool The database handle to use     * @param property The name of the property     * @param value The value of the property     * @throws JdbcException if a JDBC error occurs     */        public static void insertProperty(JdbcConnectionPool pool, String property, String value) throws JdbcException    {        JdbcPreparedStatement insert = pool.prepareStatement(insertStmt);                insert.setString(1, property);        insert.setString(2, value);        insert.executeUpdate();        insert.close();    }    /** Updates a record in the property table     * @param pool The database handle to use     * @param property The name of the property     * @param value The value of the property     * @throws JdbcException if a JDBC error occurs     */        public static void updateProperty(JdbcConnectionPool pool, String property, String value) throws JdbcException    {        JdbcPreparedStatement update = pool.prepareStatement(updateStmt);                update.setString(1, value);        update.setString(2, property);        update.executeUpdate();        update.close();    }    /** Writes a record into the property table. If a record with the given name is     * already there, it will be updated. Otherwise a new record will be inserted.     * @param pool The database handle to use     * @param property The name of the property     * @param value The value of the property     * @throws JdbcException if a JDBC error occurs     */        public static void writeProperty(JdbcConnectionPool pool, String property, String value) throws JdbcException    {        if (! searchProperty(pool, property))            insertProperty(pool, property, value);        else            updateProperty(pool, property, value);    }}/** * $Log: PropertyTable.java,v $ * Revision 1.11  2003/04/13 20:16:42  joerg * Package structure modified * * Revision 1.10  2003/01/01 21:04:18  joerg * Copyright-Statement aktualisiert * * Revision 1.9  2002/12/27 16:39:33  joerg * Neue Methode selectProperty(pool, property, defaultValue) * * Revision 1.8  2002/12/23 11:28:23  joerg * no message * * Revision 1.7  2002/12/21 19:55:03  joerg * Nicht mehr benoetigte Methoden entfernt, interne Methoden auf * private oder protected geaendert. * JavaDoc Kommentare ergaenzt. * * Revision 1.6  2002/12/19 15:54:33  joerg * Paket umbenannt in iiitLdapPlugin * * Revision 1.5  2002/12/08 16:09:46  joerg * Paket-Struktur ueberarbeitet * * Revision 1.4  2002/11/21 21:49:45  joerg * Umstellung auf JdbcConnectionPool * * 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 + -