📄 todolist.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: ToDoList.java,v 1.10 2003/04/13 20:16:42 joerg Exp $ ******************************************************************************/package de.iiit.access.server.util.db.admindb;import de.iiit.jdbc.*;import java.util.*;/** Implements a wrapper for the database table "todolist" * This table holds names of expression or group definition which * have changed in the LDAP database and therefore must be updated * in the cache database. */public class ToDoList{ /** CVS Version Tag */ private static final String vcid = "$Id: ToDoList.java,v 1.10 2003/04/13 20:16:42 joerg Exp $"; private static final String toDoTable = "todolist"; private static final String createStmt = "create table " + toDoTable + " (" + "expression varchar(255), " + "touchtime bigint, " + "locked char(1), " + "index idx1 (expression), " + "index idx2 (touchtime))"; private static final String insertStmt = "insert into " + toDoTable + " " + "(expression, touchtime, locked) " + "values (?, ?, ?)"; private static final String searchStmt = "select count(*) " + "from " + toDoTable + " " + "where expression = ? and locked = 0"; private static final String selectStmt = "select expression, touchtime, locked " + "from " + toDoTable + " " + "order by touchtime limit 1"; private static final String updateStmt = "update " + toDoTable + " " + "set locked = ? " + "where expression = ? and touchtime = ?"; private static final String deleteStmt = "delete from " + toDoTable + " " + "where expression = ? and touchtime = ?"; private String expression; private long touchTime; private boolean locked; /** Creates a new instance of ToDoList */ private ToDoList() { } /** Creates a new instance of ToDoList * @param expression The name of the expression or group definition * @param touchTime The time when the change was recognized in milliseconds since January, 1st 1970 * @param locked Before the update of the cache db starts this field will be set to '1'. * This flag is used for optimization. If another change of the * same expression or group is recognized, it will not be added * to the todolist if this flag is still zero. */ public ToDoList(String expression, long touchTime, boolean locked) { this.expression = expression; this.touchTime = touchTime; this.locked = locked; } /** Creates a new database table todolist. * @param pool The database handle to use * @throws JdbcException if a JDBC error occurs * @return true if the table was created, false if it was already there. */ public static boolean createToDoList(JdbcConnectionPool pool) throws JdbcException { boolean result = false; JdbcDatabaseMetaData md = pool.getMetaData(); JdbcResultSet rs = md.getTables(null, null, toDoTable, new String[] { "TABLE" }); if (! rs.next()) { result = true; JdbcStatement stmt = pool.createStatement(); stmt.execute(createStmt); stmt.close(); } rs.close(); return result; } /** Inserts a list of names into the database * @param pool The database handle to use * @param values The names to insert * @throws JdbcException if a JDBC error occurs */ public static void fillToDoList(JdbcConnectionPool pool, Set values) throws JdbcException { JdbcPreparedStatement pstmt = pool.prepareStatement(insertStmt); Iterator i = values.iterator(); while (i.hasNext()) { pstmt.clearBatch(); pstmt.clearWarnings(); pstmt.setString(1, (String) i.next()); pstmt.setLong(2, System.currentTimeMillis()); pstmt.setString(3, "0"); pstmt.executeUpdate(); } pstmt.close(); } /** Searches for a name * @param pool The database handle to use * @param cn the name to search for * @throws JdbcException if a JDBC error occurs * @return true if such a record was found, false if not. */ public static boolean searchToDo(JdbcConnectionPool pool, String cn) throws JdbcException { JdbcPreparedStatement stmt = pool.prepareStatement(searchStmt); stmt.setString(1, cn); JdbcResultSet rs = stmt.executeQuery(); rs.first(); int count = rs.getInt(1); rs.close(); stmt.close(); return (count != 0); } /** Inserts a the current object into the database * @param pool The database handle to use * @throws JdbcException if a JDBC error occurs */ public void insertToDo(JdbcConnectionPool pool) throws JdbcException { if (! searchToDo(pool, expression)) { JdbcPreparedStatement stmt = pool.prepareStatement(insertStmt); stmt.setString(1, expression); stmt.setLong (2, touchTime); stmt.setString(3, locked ? "1" : "0"); stmt.executeUpdate(); stmt.close(); } } /** Reads and returns the first record out of the todolist. * @param pool The database handle to use * @throws JdbcException if a JDBC error occurs * @return The read record or null if there is no one to read. */ public static ToDoList selectToDo(JdbcConnectionPool pool) throws JdbcException { ToDoList result = null; JdbcPreparedStatement stmt = pool.prepareStatement(selectStmt); JdbcResultSet rs = stmt.executeQuery(); if (rs.first()) { result = new ToDoList(); result.setExpression(rs.getString(1)); result.setTouchTime (rs.getLong(2)); result.setLocked ((rs.getInt(3) == 1)); } rs.close(); stmt.close(); return result; } /** 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 updateToDo(JdbcConnectionPool pool) throws JdbcException { JdbcPreparedStatement update = pool.prepareStatement(updateStmt); update.setString(1, locked ? "1" : "0"); update.setString(2, expression); update.setLong (3, touchTime); 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 deleteToDo(JdbcConnectionPool pool) throws JdbcException { JdbcPreparedStatement delete = pool.prepareStatement(deleteStmt); delete.setString(1, expression); delete.setLong (2, touchTime); delete.executeUpdate(); delete.close(); } /** Sets the expression field of the current object * @param expression the expression */ public void setExpression(String expression) { this.expression = expression; } /** Sets the touchtime field of the current object * @param touchTime the time in milliseconds since January, 1st 1970 */ public void setTouchTime(long touchTime) { this.touchTime = touchTime; } /** Sets the lock field of the current object * @param locked true if the record should be locked, false otherwise */ public void setLocked(boolean locked) { this.locked = locked; } /** Retrieves the expression field of the current object * @return the expression * */ public String getExpression() { return expression; } /** Retrieves the touchtime field of the current object * @return the time in milliseconds since January, 1st 1970 */ public long getTouchTime() { return touchTime; } /** Retrieves the lock field of the current object * @return true if the record is locked, false otherwise */ public boolean getLocked() { return locked; }}/** * $Log: ToDoList.java,v $ * Revision 1.10 2003/04/13 20:16:42 joerg * Package structure modified * * Revision 1.9 2003/01/01 21:04:18 joerg * Copyright-Statement aktualisiert * * Revision 1.8 2002/12/23 11:28:23 joerg * no message * * Revision 1.7 2002/12/21 19:55:04 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.2 2002/11/18 10:13:18 joerg * CacheManager ist jetzt vollstaendig implementiert * * 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 + -