Many small fixes

This commit is contained in:
Ziver Koc 2013-12-17 19:18:14 +00:00
parent 8a930b361d
commit 9a0142c06c
18 changed files with 376 additions and 499 deletions

View file

@ -22,6 +22,9 @@
package zutil.db;
import zutil.converters.Converter;
import zutil.io.MultiPrintStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -30,31 +33,28 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;
import zutil.converters.Converter;
import zutil.io.MultiPrintStream;
/**
* This class creates a queue that stors the
* This class creates a queue that stores the
* data in a mysql table.
* The table should look like this:
* <PRE>
* CREATE TABLE `queue` (
* `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
* `data` BINARY NOT NULL
* );
* </PRE>
* @author Ziver
*
*/
public class DBQueue<E> implements Queue<E>{
// GO TO KNOW = SELECT LAST_INSERT_ID() as pos_id
private DBConnection db;
private String table;
/**
* Initiates the queue.<br>
* <b>WARNING!!<b> this will erase all rows in the table
*
* @param db is the connection to the DB
* @param table is the name of the table
* @param db is the connection to the DB
* @param table is the name of the table
*/
public DBQueue(DBConnection db, String table){
this.db = db;
@ -63,8 +63,9 @@ public class DBQueue<E> implements Queue<E>{
public boolean add(Object arg0){
try {
PreparedStatement sql = db.getPreparedStatement("INSERT INTO "+table+" (data) VALUES(?)");
sql.setObject(1, arg0);
PreparedStatement sql = db.getPreparedStatement("INSERT INTO ? (data) VALUES(?)");
sql.setObject(1, table);
sql.setObject(2, arg0);
DBConnection.exec(sql);
} catch (Exception e) {
e.printStackTrace(MultiPrintStream.out);
@ -81,7 +82,6 @@ public class DBQueue<E> implements Queue<E>{
return add(arg0);
}
@SuppressWarnings("unchecked")
public synchronized E peek() {
try {
return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler<E>(){
@ -101,7 +101,6 @@ public class DBQueue<E> implements Queue<E>{
return null;
}
@SuppressWarnings("unchecked")
public synchronized E poll() {
try {
return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler<E>(){
@ -207,7 +206,6 @@ public class DBQueue<E> implements Queue<E>{
return null;
}
@SuppressWarnings("unchecked")
public E[] toArray(Object[] arg0) {
// TODO Auto-generated method stub
return null;

View file

@ -42,7 +42,7 @@ import zutil.db.bean.DBBean.DBLinkTable;
import zutil.log.LogUtil;
public class DBBeanSQLResultHandler<T> implements SQLResultHandler<T>{
public static final Logger logger = LogUtil.getLogger();
private static final Logger logger = LogUtil.getLogger();
/** This is the time to live for the cached items **/
public static final long CACHE_TTL = 1000*60*5; // 5 min in ms
/** A cache for detecting recursion **/