Fixed some things
This commit is contained in:
parent
b8bf1946d5
commit
985ab58235
3 changed files with 13 additions and 13 deletions
|
|
@ -84,17 +84,17 @@ public class DBConnection{
|
||||||
/**
|
/**
|
||||||
* @return the last inserted id or -1 if there was an error
|
* @return the last inserted id or -1 if there was an error
|
||||||
*/
|
*/
|
||||||
public int getLastInsertID(){
|
public Object getLastInsertID(){
|
||||||
try{
|
try{
|
||||||
return exec("SELECT LAST_INSERT_ID()", new SQLResultHandler<Integer>(){
|
return exec("SELECT LAST_INSERT_ID()", new SQLResultHandler<Object>(){
|
||||||
public Integer handle(Statement stmt, ResultSet result) throws SQLException {
|
public Object handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||||
if(result.next())
|
if(result.next())
|
||||||
return result.getInt(1);
|
return result.getObject(1);
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}catch(SQLException e){
|
}catch(SQLException e){
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +137,7 @@ public class DBConnection{
|
||||||
*/
|
*/
|
||||||
public static int exec(PreparedStatement stmt) throws SQLException {
|
public static int exec(PreparedStatement stmt) throws SQLException {
|
||||||
return exec(stmt, new SQLResultHandler<Integer>(){
|
return exec(stmt, new SQLResultHandler<Integer>(){
|
||||||
public Integer handle(Statement stmt, ResultSet result) {
|
public Integer handleQueryResult(Statement stmt, ResultSet result) {
|
||||||
try {
|
try {
|
||||||
return stmt.getUpdateCount();
|
return stmt.getUpdateCount();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
@ -178,7 +178,7 @@ public class DBConnection{
|
||||||
ResultSet result = null;
|
ResultSet result = null;
|
||||||
try{
|
try{
|
||||||
result = stmt.getResultSet();
|
result = stmt.getResultSet();
|
||||||
return handler.handle(stmt, result);
|
return handler.handleQueryResult(stmt, result);
|
||||||
}finally{
|
}finally{
|
||||||
if(result != null){
|
if(result != null){
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ public class DBQueue<E> implements Queue<E>{
|
||||||
public synchronized E peek() {
|
public synchronized E peek() {
|
||||||
try {
|
try {
|
||||||
return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler<E>(){
|
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())
|
if (rs.next())
|
||||||
try {
|
try {
|
||||||
return (E) Converter.toObject(rs.getBytes("data"));
|
return (E) Converter.toObject(rs.getBytes("data"));
|
||||||
|
|
@ -83,7 +83,7 @@ public class DBQueue<E> implements Queue<E>{
|
||||||
public synchronized E poll() {
|
public synchronized E poll() {
|
||||||
try {
|
try {
|
||||||
return db.exec("SELECT * FROM "+table+" LIMIT 1", new SQLResultHandler<E>(){
|
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{
|
try{
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
db.exec("DELETE FROM "+table+" WHERE id="+rs.getInt("id")+" LIMIT 1");
|
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) {
|
public boolean contains(Object arg0) {
|
||||||
try {
|
try {
|
||||||
return db.exec("SELECT data FROM "+table+" WHERE data='"+Converter.toBytes(arg0)+"' LIMIT 1", new SQLResultHandler<Boolean>(){
|
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();
|
return rs.next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -168,7 +168,7 @@ public class DBQueue<E> implements Queue<E>{
|
||||||
public int size() {
|
public int size() {
|
||||||
try {
|
try {
|
||||||
return db.exec("SELECT count(*) FROM "+table, new SQLResultHandler<Integer>(){
|
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())
|
if (rs.next())
|
||||||
return rs.getInt(1);
|
return rs.getInt(1);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ public interface SQLResultHandler<T> {
|
||||||
* @param stmt is the query
|
* @param stmt is the query
|
||||||
* @param result is the ResultSet
|
* @param result is the ResultSet
|
||||||
*/
|
*/
|
||||||
public T handle(Statement stmt, ResultSet result) throws SQLException;
|
public T handleQueryResult(Statement stmt, ResultSet result) throws SQLException;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue