com.j256.ormlite.dao.Dao.getConnectionSource()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中com.j256.ormlite.dao.Dao.getConnectionSource()方法的一些代码示例,展示了Dao.getConnectionSource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.getConnectionSource()方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:getConnectionSource

Dao.getConnectionSource介绍

[英]Return the associated ConnectionSource or null if none set on the DAO yet.
[中]返回关联的ConnectionSource,如果DAO上还没有设置,则返回null。

代码示例

代码示例来源:origin: magefree/mage

  1. public void closeDB() {
  2. try {
  3. if (dao != null && dao.getConnectionSource() != null) {
  4. DatabaseConnection conn = dao.getConnectionSource().getReadWriteConnection();
  5. conn.executeStatement("shutdown compact", 0);
  6. }
  7. } catch (SQLException ex) {
  8. Logger.getLogger(UserStatsRepository.class).error("Error closing user_stats repository - ", ex);
  9. }
  10. }
  11. }

代码示例来源:origin: magefree/mage

  1. public void closeDB() {
  2. try {
  3. if (dao != null && dao.getConnectionSource() != null) {
  4. DatabaseConnection conn = dao.getConnectionSource().getReadWriteConnection();
  5. conn.executeStatement("shutdown compact", 0);
  6. }
  7. } catch (SQLException ex) {
  8. Logger.getLogger(TableRecordRepository.class).error("Error closing table_record repository - ", ex);
  9. }
  10. }
  11. }

代码示例来源:origin: magefree/mage

  1. public void closeDB() {
  2. try {
  3. if (cardDao != null && cardDao.getConnectionSource() != null) {
  4. DatabaseConnection conn = cardDao.getConnectionSource().getReadWriteConnection();
  5. conn.executeStatement("shutdown compact", 0);
  6. }
  7. } catch (SQLException ex) {
  8. }
  9. }

代码示例来源:origin: magefree/mage

  1. public void closeDB() {
  2. try {
  3. if (dao != null && dao.getConnectionSource() != null) {
  4. DatabaseConnection conn = dao.getConnectionSource().getReadWriteConnection();
  5. conn.executeStatement("shutdown compact", 0);
  6. }
  7. } catch (SQLException ex) {
  8. Logger.getLogger(AuthorizedUserRepository.class).error("Error closing authorized_user repository - ", ex);
  9. }
  10. }

代码示例来源:origin: magefree/mage

  1. private boolean migrateFrom1To2() {
  2. try {
  3. Logger.getLogger(AuthorizedUserRepository.class).info("Starting " + VERSION_ENTITY_NAME + " DB migration from version 1 to version 2");
  4. dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN active BOOLEAN DEFAULT true;");
  5. dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN lockedUntil DATETIME;");
  6. dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN chatLockedUntil DATETIME;");
  7. dao.executeRaw("ALTER TABLE authorized_user ADD COLUMN lastConnection DATETIME;");
  8. RepositoryUtil.updateVersion(dao.getConnectionSource(), VERSION_ENTITY_NAME, DB_VERSION);
  9. Logger.getLogger(AuthorizedUserRepository.class).info("Migration finished.");
  10. return true;
  11. } catch (SQLException ex) {
  12. Logger.getLogger(AuthorizedUserRepository.class).error("Error while migrating from version 1 to version 2 - ", ex);
  13. return false;
  14. }
  15. }
  16. }

代码示例来源:origin: j256/ormlite-core

  1. /**
  2. * @see Dao#getConnectionSource()
  3. */
  4. @Override
  5. public ConnectionSource getConnectionSource() {
  6. return dao.getConnectionSource();
  7. }

代码示例来源:origin: com.j256.ormlite/ormlite-core

  1. /**
  2. * @see Dao#getConnectionSource()
  3. */
  4. @Override
  5. public ConnectionSource getConnectionSource() {
  6. return dao.getConnectionSource();
  7. }

代码示例来源:origin: com.j256.ormlite/ormlite-core

  1. private static <T, ID> int doCreateTable(Dao<T, ID> dao, boolean ifNotExists) throws SQLException {
  2. if (dao instanceof BaseDaoImpl<?, ?>) {
  3. return doCreateTable(dao.getConnectionSource(), ((BaseDaoImpl<?, ?>) dao).getTableInfo(), ifNotExists);
  4. } else {
  5. TableInfo<T, ID> tableInfo = new TableInfo<T, ID>(dao.getConnectionSource(), null, dao.getDataClass());
  6. return doCreateTable(dao.getConnectionSource(), tableInfo, ifNotExists);
  7. }
  8. }

代码示例来源:origin: j256/ormlite-core

  1. protected BaseMappedStatement(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, String statement,
  2. FieldType[] argFieldTypes) {
  3. this.dao = dao;
  4. this.connectionSource = dao.getConnectionSource();
  5. this.tableInfo = tableInfo;
  6. this.clazz = tableInfo.getDataClass();
  7. this.idField = tableInfo.getIdField();
  8. this.statement = statement;
  9. this.argFieldTypes = argFieldTypes;
  10. }

代码示例来源:origin: ChestShop-authors/ChestShop-3

  1. /**
  2. * Creates a dao as well as a default table, if doesn't exist
  3. * @see #getDao(Class)
  4. * @throws SQLException
  5. * @throws InvalidParameterException
  6. */
  7. public static <ENTITY, ID> Dao<ENTITY, ID> getDaoAndCreateTable(Class<ENTITY> entity) throws SQLException, InvalidParameterException {
  8. Dao<ENTITY, ID> dao = getDao(entity);
  9. TableUtils.createTableIfNotExists(dao.getConnectionSource(), entity);
  10. return dao;
  11. }
  12. }

代码示例来源:origin: com.j256.ormlite/ormlite-android

  1. @Override
  2. public Cursor loadInBackground() {
  3. Cursor cursor;
  4. try {
  5. DatabaseConnection connection = dao.getConnectionSource().getReadOnlyConnection(dao.getTableName());
  6. AndroidCompiledStatement statement = (AndroidCompiledStatement) query.compile(connection, SELECT);
  7. cursor = statement.getCursor();
  8. } catch (SQLException e) {
  9. throw new RuntimeException(e);
  10. }
  11. // fill the cursor with results
  12. cursor.getCount();
  13. return cursor;
  14. }

代码示例来源:origin: com.j256.ormlite/ormlite-android

  1. @Override
  2. public Cursor loadInBackground() {
  3. Cursor cursor;
  4. try {
  5. DatabaseConnection connection = dao.getConnectionSource().getReadOnlyConnection(dao.getTableName());
  6. AndroidCompiledStatement statement = (AndroidCompiledStatement) query.compile(connection, SELECT);
  7. cursor = statement.getCursor();
  8. } catch (SQLException e) {
  9. throw new RuntimeException(e);
  10. }
  11. // fill the cursor with results
  12. cursor.getCount();
  13. return cursor;
  14. }

代码示例来源:origin: j256/ormlite-core

  1. private boolean addElement(T data) throws SQLException {
  2. if (dao == null) {
  3. return false;
  4. }
  5. if (parent != null && foreignFieldType.getFieldValueIfNotDefault(data) == null) {
  6. foreignFieldType.assignField(dao.getConnectionSource(), data, parent, true, null);
  7. }
  8. dao.create(data);
  9. return true;
  10. }
  11. }

代码示例来源:origin: j256/ormlite-core

  1. public static <T, ID> MappedDelete<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo) throws SQLException {
  2. FieldType idField = tableInfo.getIdField();
  3. if (idField == null) {
  4. throw new SQLException(
  5. "Cannot delete from " + tableInfo.getDataClass() + " because it doesn't have an id field");
  6. }
  7. StringBuilder sb = new StringBuilder(64);
  8. DatabaseType databaseType = dao.getConnectionSource().getDatabaseType();
  9. appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName());
  10. appendWhereFieldEq(databaseType, idField, sb, null);
  11. return new MappedDelete<T, ID>(dao, tableInfo, sb.toString(), new FieldType[] { idField });
  12. }

代码示例来源:origin: org.mycontroller.standalone/mycontroller-core

  1. public void dropTable(Class<?> entity) throws SQLException {
  2. TableUtils.dropTable(DaoUtils.getUserDao().getDao().getConnectionSource(), entity, true);
  3. }

代码示例来源:origin: mycontroller-org/mycontroller

  1. public void dropTable(Class<?> entity) throws SQLException {
  2. TableUtils.dropTable(DaoUtils.getUserDao().getDao().getConnectionSource(), entity, true);
  3. }

代码示例来源:origin: org.mycontroller.standalone/mycontroller-core

  1. public void createTable(Class<?> entity) throws SQLException {
  2. TableUtils.createTableIfNotExists(DaoUtils.getUserDao().getDao().getConnectionSource(), entity);
  3. }

代码示例来源:origin: j256/ormlite-core

  1. public static <T, ID> MappedQueryForFieldEq<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo,
  2. FieldType idFieldType) throws SQLException {
  3. if (idFieldType == null) {
  4. idFieldType = tableInfo.getIdField();
  5. if (idFieldType == null) {
  6. throw new SQLException("Cannot query-for-id with " + tableInfo.getDataClass()
  7. + " because it doesn't have an id field");
  8. }
  9. }
  10. DatabaseType databaseType = dao.getConnectionSource().getDatabaseType();
  11. String statement = buildStatement(databaseType, tableInfo, idFieldType);
  12. return new MappedQueryForFieldEq<T, ID>(dao, tableInfo, statement, new FieldType[] { idFieldType },
  13. tableInfo.getFieldTypes(), "query-for-id");
  14. }

代码示例来源:origin: j256/ormlite-core

  1. public static <T, ID> MappedRefresh<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo) throws SQLException {
  2. FieldType idField = tableInfo.getIdField();
  3. if (idField == null) {
  4. throw new SQLException(
  5. "Cannot refresh " + tableInfo.getDataClass() + " because it doesn't have an id field");
  6. }
  7. DatabaseType databaseType = dao.getConnectionSource().getDatabaseType();
  8. String statement = buildStatement(databaseType, tableInfo, idField);
  9. return new MappedRefresh<T, ID>(dao, tableInfo, statement, new FieldType[] { tableInfo.getIdField() },
  10. tableInfo.getFieldTypes());
  11. }
  12. }

代码示例来源:origin: j256/ormlite-core

  1. private static <T, ID> int doCreateTable(Dao<T, ID> dao, boolean ifNotExists) throws SQLException {
  2. ConnectionSource connectionSource = dao.getConnectionSource();
  3. DatabaseType databaseType = connectionSource.getDatabaseType();
  4. if (dao instanceof BaseDaoImpl<?, ?>) {
  5. return doCreateTable(connectionSource, ((BaseDaoImpl<?, ?>) dao).getTableInfo(), ifNotExists);
  6. } else {
  7. TableInfo<T, ID> tableInfo = new TableInfo<T, ID>(databaseType, dao.getDataClass());
  8. return doCreateTable(connectionSource, tableInfo, ifNotExists);
  9. }
  10. }

相关文章