本文整理了Java中com.j256.ormlite.dao.Dao.getConnectionSource()
方法的一些代码示例,展示了Dao.getConnectionSource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.getConnectionSource()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:getConnectionSource
[英]Return the associated ConnectionSource or null if none set on the DAO yet.
[中]返回关联的ConnectionSource,如果DAO上还没有设置,则返回null。
代码示例来源:origin: magefree/mage
public void closeDB() {
try {
if (dao != null && dao.getConnectionSource() != null) {
DatabaseConnection conn = dao.getConnectionSource().getReadWriteConnection();
conn.executeStatement("shutdown compact", 0);
}
} catch (SQLException ex) {
Logger.getLogger(UserStatsRepository.class).error("Error closing user_stats repository - ", ex);
}
}
}
代码示例来源:origin: magefree/mage
public void closeDB() {
try {
if (dao != null && dao.getConnectionSource() != null) {
DatabaseConnection conn = dao.getConnectionSource().getReadWriteConnection();
conn.executeStatement("shutdown compact", 0);
}
} catch (SQLException ex) {
Logger.getLogger(TableRecordRepository.class).error("Error closing table_record repository - ", ex);
}
}
}
代码示例来源:origin: magefree/mage
public void closeDB() {
try {
if (cardDao != null && cardDao.getConnectionSource() != null) {
DatabaseConnection conn = cardDao.getConnectionSource().getReadWriteConnection();
conn.executeStatement("shutdown compact", 0);
}
} catch (SQLException ex) {
}
}
代码示例来源:origin: magefree/mage
public void closeDB() {
try {
if (dao != null && dao.getConnectionSource() != null) {
DatabaseConnection conn = dao.getConnectionSource().getReadWriteConnection();
conn.executeStatement("shutdown compact", 0);
}
} catch (SQLException ex) {
Logger.getLogger(AuthorizedUserRepository.class).error("Error closing authorized_user repository - ", ex);
}
}
代码示例来源:origin: magefree/mage
private boolean migrateFrom1To2() {
try {
Logger.getLogger(AuthorizedUserRepository.class).info("Starting " + VERSION_ENTITY_NAME + " DB migration from version 1 to version 2");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN active BOOLEAN DEFAULT true;");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN lockedUntil DATETIME;");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN chatLockedUntil DATETIME;");
dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN lastConnection DATETIME;");
RepositoryUtil.updateVersion(dao.getConnectionSource(), VERSION_ENTITY_NAME, DB_VERSION);
Logger.getLogger(AuthorizedUserRepository.class).info("Migration finished.");
return true;
} catch (SQLException ex) {
Logger.getLogger(AuthorizedUserRepository.class).error("Error while migrating from version 1 to version 2 - ", ex);
return false;
}
}
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#getConnectionSource()
*/
@Override
public ConnectionSource getConnectionSource() {
return dao.getConnectionSource();
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#getConnectionSource()
*/
@Override
public ConnectionSource getConnectionSource() {
return dao.getConnectionSource();
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
private static <T, ID> int doCreateTable(Dao<T, ID> dao, boolean ifNotExists) throws SQLException {
if (dao instanceof BaseDaoImpl<?, ?>) {
return doCreateTable(dao.getConnectionSource(), ((BaseDaoImpl<?, ?>) dao).getTableInfo(), ifNotExists);
} else {
TableInfo<T, ID> tableInfo = new TableInfo<T, ID>(dao.getConnectionSource(), null, dao.getDataClass());
return doCreateTable(dao.getConnectionSource(), tableInfo, ifNotExists);
}
}
代码示例来源:origin: j256/ormlite-core
protected BaseMappedStatement(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, String statement,
FieldType[] argFieldTypes) {
this.dao = dao;
this.connectionSource = dao.getConnectionSource();
this.tableInfo = tableInfo;
this.clazz = tableInfo.getDataClass();
this.idField = tableInfo.getIdField();
this.statement = statement;
this.argFieldTypes = argFieldTypes;
}
代码示例来源:origin: ChestShop-authors/ChestShop-3
/**
* Creates a dao as well as a default table, if doesn't exist
* @see #getDao(Class)
* @throws SQLException
* @throws InvalidParameterException
*/
public static <ENTITY, ID> Dao<ENTITY, ID> getDaoAndCreateTable(Class<ENTITY> entity) throws SQLException, InvalidParameterException {
Dao<ENTITY, ID> dao = getDao(entity);
TableUtils.createTableIfNotExists(dao.getConnectionSource(), entity);
return dao;
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-android
@Override
public Cursor loadInBackground() {
Cursor cursor;
try {
DatabaseConnection connection = dao.getConnectionSource().getReadOnlyConnection(dao.getTableName());
AndroidCompiledStatement statement = (AndroidCompiledStatement) query.compile(connection, SELECT);
cursor = statement.getCursor();
} catch (SQLException e) {
throw new RuntimeException(e);
}
// fill the cursor with results
cursor.getCount();
return cursor;
}
代码示例来源:origin: com.j256.ormlite/ormlite-android
@Override
public Cursor loadInBackground() {
Cursor cursor;
try {
DatabaseConnection connection = dao.getConnectionSource().getReadOnlyConnection(dao.getTableName());
AndroidCompiledStatement statement = (AndroidCompiledStatement) query.compile(connection, SELECT);
cursor = statement.getCursor();
} catch (SQLException e) {
throw new RuntimeException(e);
}
// fill the cursor with results
cursor.getCount();
return cursor;
}
代码示例来源:origin: j256/ormlite-core
private boolean addElement(T data) throws SQLException {
if (dao == null) {
return false;
}
if (parent != null && foreignFieldType.getFieldValueIfNotDefault(data) == null) {
foreignFieldType.assignField(dao.getConnectionSource(), data, parent, true, null);
}
dao.create(data);
return true;
}
}
代码示例来源:origin: j256/ormlite-core
public static <T, ID> MappedDelete<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo) throws SQLException {
FieldType idField = tableInfo.getIdField();
if (idField == null) {
throw new SQLException(
"Cannot delete from " + tableInfo.getDataClass() + " because it doesn't have an id field");
}
StringBuilder sb = new StringBuilder(64);
DatabaseType databaseType = dao.getConnectionSource().getDatabaseType();
appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName());
appendWhereFieldEq(databaseType, idField, sb, null);
return new MappedDelete<T, ID>(dao, tableInfo, sb.toString(), new FieldType[] { idField });
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void dropTable(Class<?> entity) throws SQLException {
TableUtils.dropTable(DaoUtils.getUserDao().getDao().getConnectionSource(), entity, true);
}
代码示例来源:origin: mycontroller-org/mycontroller
public void dropTable(Class<?> entity) throws SQLException {
TableUtils.dropTable(DaoUtils.getUserDao().getDao().getConnectionSource(), entity, true);
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void createTable(Class<?> entity) throws SQLException {
TableUtils.createTableIfNotExists(DaoUtils.getUserDao().getDao().getConnectionSource(), entity);
}
代码示例来源:origin: j256/ormlite-core
public static <T, ID> MappedQueryForFieldEq<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo,
FieldType idFieldType) throws SQLException {
if (idFieldType == null) {
idFieldType = tableInfo.getIdField();
if (idFieldType == null) {
throw new SQLException("Cannot query-for-id with " + tableInfo.getDataClass()
+ " because it doesn't have an id field");
}
}
DatabaseType databaseType = dao.getConnectionSource().getDatabaseType();
String statement = buildStatement(databaseType, tableInfo, idFieldType);
return new MappedQueryForFieldEq<T, ID>(dao, tableInfo, statement, new FieldType[] { idFieldType },
tableInfo.getFieldTypes(), "query-for-id");
}
代码示例来源:origin: j256/ormlite-core
public static <T, ID> MappedRefresh<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo) throws SQLException {
FieldType idField = tableInfo.getIdField();
if (idField == null) {
throw new SQLException(
"Cannot refresh " + tableInfo.getDataClass() + " because it doesn't have an id field");
}
DatabaseType databaseType = dao.getConnectionSource().getDatabaseType();
String statement = buildStatement(databaseType, tableInfo, idField);
return new MappedRefresh<T, ID>(dao, tableInfo, statement, new FieldType[] { tableInfo.getIdField() },
tableInfo.getFieldTypes());
}
}
代码示例来源:origin: j256/ormlite-core
private static <T, ID> int doCreateTable(Dao<T, ID> dao, boolean ifNotExists) throws SQLException {
ConnectionSource connectionSource = dao.getConnectionSource();
DatabaseType databaseType = connectionSource.getDatabaseType();
if (dao instanceof BaseDaoImpl<?, ?>) {
return doCreateTable(connectionSource, ((BaseDaoImpl<?, ?>) dao).getTableInfo(), ifNotExists);
} else {
TableInfo<T, ID> tableInfo = new TableInfo<T, ID>(databaseType, dao.getDataClass());
return doCreateTable(connectionSource, tableInfo, ifNotExists);
}
}
内容来源于网络,如有侵权,请联系作者删除!