This commit is contained in:
@@ -5,26 +5,52 @@
|
||||
*/
|
||||
package org.redkale.source;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see http://www.redkale.org
|
||||
* @author zhangjx
|
||||
*/
|
||||
public abstract class DataConnection {
|
||||
public class DataConnection {
|
||||
|
||||
private final Object connection;
|
||||
private final Connection conn;
|
||||
|
||||
protected DataConnection(Object connection) {
|
||||
this.connection = connection;
|
||||
protected DataConnection(Connection connection) {
|
||||
this.conn = connection;
|
||||
}
|
||||
|
||||
protected <T> T getConnection() {
|
||||
return (T) this.connection;
|
||||
protected Connection getConnection() {
|
||||
return this.conn;
|
||||
}
|
||||
|
||||
public abstract boolean commit();
|
||||
public boolean close() {
|
||||
try {
|
||||
if (conn == null || conn.isClosed()) return true;
|
||||
conn.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
//do nothing
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean rollback();
|
||||
public boolean commit() {
|
||||
try {
|
||||
conn.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean close();
|
||||
public boolean rollback() {
|
||||
try {
|
||||
conn.rollback();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
//do nothing
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,54 +69,6 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
@Resource(name = "$")
|
||||
private DataCacheListener cacheListener;
|
||||
|
||||
private static class DataJDBCConnection extends DataConnection {
|
||||
|
||||
private final Connection sqlconn;
|
||||
|
||||
private DataJDBCConnection(Connection c) {
|
||||
super(c);
|
||||
this.sqlconn = c;
|
||||
try {
|
||||
this.sqlconn.setAutoCommit(true);
|
||||
} catch (Exception e) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean close() {
|
||||
try {
|
||||
if(sqlconn == null || sqlconn.isClosed()) return true;
|
||||
sqlconn.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
//do nothing
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean commit() {
|
||||
try {
|
||||
sqlconn.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rollback() {
|
||||
try {
|
||||
sqlconn.rollback();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
//do nothing
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final Function<Class, List> fullloader = (t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||
|
||||
public DataDefaultSource() throws IOException {
|
||||
@@ -276,12 +228,12 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
|
||||
@Override
|
||||
public DataConnection createReadConnection() {
|
||||
return new DataJDBCConnection(createReadSQLConnection());
|
||||
return new DataConnection(createReadSQLConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataConnection createWriteConnection() {
|
||||
return new DataJDBCConnection(createWriteSQLConnection());
|
||||
return new DataConnection(createWriteSQLConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user