Fixed some things

This commit is contained in:
Ziver Koc 2010-10-07 11:27:23 +00:00
parent b8bf1946d5
commit 985ab58235
3 changed files with 13 additions and 13 deletions

View file

@ -84,17 +84,17 @@ public class DBConnection{
/**
* @return the last inserted id or -1 if there was an error
*/
public int getLastInsertID(){
public Object getLastInsertID(){
try{
return exec("SELECT LAST_INSERT_ID()", new SQLResultHandler<Integer>(){
public Integer handle(Statement stmt, ResultSet result) throws SQLException {
return exec("SELECT LAST_INSERT_ID()", new SQLResultHandler<Object>(){
public Object handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
if(result.next())
return result.getInt(1);
return -1;
return result.getObject(1);
return null;
}
});
}catch(SQLException e){
return -1;
return null;
}
}
@ -137,7 +137,7 @@ public class DBConnection{
*/
public static int exec(PreparedStatement stmt) throws SQLException {
return exec(stmt, new SQLResultHandler<Integer>(){
public Integer handle(Statement stmt, ResultSet result) {
public Integer handleQueryResult(Statement stmt, ResultSet result) {
try {
return stmt.getUpdateCount();
} catch (SQLException e) {
@ -178,7 +178,7 @@ public class DBConnection{
ResultSet result = null;
try{
result = stmt.getResultSet();
return handler.handle(stmt, result);
return handler.handleQueryResult(stmt, result);
}finally{
if(result != null){
try {

View file

@ -63,7 +63,7 @@ public class DBQueue<E> implements Queue<E>{
public synchronized E peek() {
try {
return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler<E>(){
public E handle(Statement stmt, ResultSet rs) throws SQLException{
public E handleQueryResult(Statement stmt, ResultSet rs) throws SQLException{
if (rs.next())
try {
return (E) Converter.toObject(rs.getBytes("data"));
@ -83,7 +83,7 @@ public class DBQueue<E> implements Queue<E>{
public synchronized E poll() {
try {
return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler<E>(){
public E handle(Statement stmt, ResultSet rs) {
public E handleQueryResult(Statement stmt, ResultSet rs) {
try{
if (rs.next()) {
db.exec("DELETE FROM "+table+" WHERE id="+rs.getInt("id")+" LIMIT 1");
@ -121,7 +121,7 @@ public class DBQueue<E> implements Queue<E>{
public boolean contains(Object arg0) {
try {
return db.exec("SELECT data FROM "+table+" WHERE data='"+Converter.toBytes(arg0)+"' LIMIT 1", new SQLResultHandler<Boolean>(){
public Boolean handle(Statement stmt, ResultSet rs) throws SQLException{
public Boolean handleQueryResult(Statement stmt, ResultSet rs) throws SQLException{
return rs.next();
}
});
@ -168,7 +168,7 @@ public class DBQueue<E> implements Queue<E>{
public int size() {
try {
return db.exec("SELECT count(*) FROM "+table, new SQLResultHandler<Integer>(){
public Integer handle(Statement stmt, ResultSet rs) throws SQLException{
public Integer handleQueryResult(Statement stmt, ResultSet rs) throws SQLException{
if (rs.next())
return rs.getInt(1);
return 0;

View file

@ -11,5 +11,5 @@ public interface SQLResultHandler<T> {
* @param stmt is the query
* @param result is the ResultSet
*/
public T handle(Statement stmt, ResultSet result) throws SQLException;
public T handleQueryResult(Statement stmt, ResultSet result) throws SQLException;
}