This commit is contained in:
@@ -5,26 +5,52 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.source;
|
package org.redkale.source;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @see http://www.redkale.org
|
* @see http://www.redkale.org
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public abstract class DataConnection {
|
public class DataConnection {
|
||||||
|
|
||||||
private final Object connection;
|
private final Connection conn;
|
||||||
|
|
||||||
protected DataConnection(Object connection) {
|
protected DataConnection(Connection connection) {
|
||||||
this.connection = connection;
|
this.conn = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> T getConnection() {
|
protected Connection getConnection() {
|
||||||
return (T) this.connection;
|
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 = "$")
|
@Resource(name = "$")
|
||||||
private DataCacheListener cacheListener;
|
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);
|
private final Function<Class, List> fullloader = (t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||||
|
|
||||||
public DataDefaultSource() throws IOException {
|
public DataDefaultSource() throws IOException {
|
||||||
@@ -276,12 +228,12 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataConnection createReadConnection() {
|
public DataConnection createReadConnection() {
|
||||||
return new DataJDBCConnection(createReadSQLConnection());
|
return new DataConnection(createReadSQLConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataConnection createWriteConnection() {
|
public DataConnection createWriteConnection() {
|
||||||
return new DataJDBCConnection(createWriteSQLConnection());
|
return new DataConnection(createWriteSQLConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user