Java源码示例:com.j256.ormlite.misc.BaseDaoEnabled
示例1
@Override
public int create(T data) throws SQLException {
checkForInitialized();
// ignore creating a null object
if (data == null) {
return 0;
}
if (data instanceof BaseDaoEnabled) {
@SuppressWarnings("unchecked")
BaseDaoEnabled<T, ID> daoEnabled = (BaseDaoEnabled<T, ID>) data;
daoEnabled.setDao(this);
}
DatabaseConnection connection = connectionSource.getReadWriteConnection(tableInfo.getTableName());
try {
return statementExecutor.create(connection, data, objectCache);
} finally {
connectionSource.releaseConnection(connection);
}
}
示例2
@Override
public int update(T data) throws SQLException {
checkForInitialized();
// ignore updating a null object
if (data == null) {
return 0;
}
if (data instanceof BaseDaoEnabled) {
@SuppressWarnings("unchecked")
BaseDaoEnabled<T, ID> daoEnabled = (BaseDaoEnabled<T, ID>) data;
daoEnabled.setDao(this);
}
DatabaseConnection connection = connectionSource.getReadWriteConnection(tableInfo.getTableName());
try {
return statementExecutor.update(connection, data, objectCache);
} finally {
connectionSource.releaseConnection(connection);
}
}
示例3
@Override
public int refresh(T data) throws SQLException {
checkForInitialized();
// ignore refreshing a null object
if (data == null) {
return 0;
}
if (data instanceof BaseDaoEnabled) {
@SuppressWarnings("unchecked")
BaseDaoEnabled<T, ID> daoEnabled = (BaseDaoEnabled<T, ID>) data;
daoEnabled.setDao(this);
}
DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
try {
return statementExecutor.refresh(connection, data, objectCache);
} finally {
connectionSource.releaseConnection(connection);
}
}
示例4
private void wireNewInstance(T instance) {
if (instance instanceof BaseDaoEnabled) {
@SuppressWarnings("unchecked")
BaseDaoEnabled<T, ID> daoEnabled = (BaseDaoEnabled<T, ID>) instance;
daoEnabled.setDao(this);
}
}