Java Code Examples for com.j256.ormlite.support.ConnectionSource

The following are top voted examples for showing how to use com.j256.ormlite.support.ConnectionSource. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: aliyun-cloudphotos-android-demo   File: DatabaseHelper.java   View source code 6 votes vote down vote up
private void createTable(SQLiteDatabase db, ConnectionSource connectionSource) {
    try {
        TableUtils.createTable(connectionSource, MyPhoto.class);
        TableUtils.createTable(connectionSource, MyMoment.class);
        TableUtils.createTable(connectionSource, MyMomentPhoto.class);
        TableUtils.createTable(connectionSource, MyFace.class);
        TableUtils.createTable(connectionSource, MyFacePhoto.class);
        TableUtils.createTable(connectionSource, UploadedPhoto.class);
        TableUtils.createTable(connectionSource, MyAlbum.class);
        TableUtils.createTable(connectionSource, MyAlbumPhoto.class);
        TableUtils.createTable(connectionSource, MyTag.class);
        TableUtils.createTable(connectionSource, MyTagPhoto.class);
        TableUtils.createTable(connectionSource, MyCursor.class);
        TableUtils.createTable(connectionSource, MySetting.class);
    } catch (Exception e) {
        Log.e(DatabaseHelper.class.getName(), "Can't create database", e);
        e.printStackTrace();
    }
}
 
Example 2
Project: aliyun-cloudphotos-android-demo   File: DatabaseHelper.java   View source code 6 votes vote down vote up
private void updateTable(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        TableUtils.dropTable(connectionSource, MyPhoto.class, true);
        TableUtils.dropTable(connectionSource, MyMoment.class, true);
        TableUtils.dropTable(connectionSource, MyMomentPhoto.class, true);
        TableUtils.dropTable(connectionSource, MyFace.class, true);
        TableUtils.dropTable(connectionSource, MyFacePhoto.class, true);
        TableUtils.dropTable(connectionSource, UploadedPhoto.class, true);
        TableUtils.dropTable(connectionSource, MyAlbum.class, true);
        TableUtils.dropTable(connectionSource, MyAlbumPhoto.class, true);
        TableUtils.dropTable(connectionSource, MyTag.class, true);
        TableUtils.dropTable(connectionSource, MyTagPhoto.class, true);
        TableUtils.dropTable(connectionSource, MyCursor.class, true);
        TableUtils.dropTable(connectionSource, MySetting.class, true);
        onCreate(db, connectionSource);
    } catch (Exception e) {
        Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example 3
Project: GitHub   File: WeatherDatabaseHelper.java   View source code 6 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {

    try {
        TableUtils.createTable(connectionSource, AirQualityLive.class);
        TableUtils.createTable(connectionSource, WeatherForecast.class);
        TableUtils.createTable(connectionSource, LifeIndex.class);
        TableUtils.createTable(connectionSource, WeatherLive.class);
        TableUtils.createTable(connectionSource, Weather.class);

        String weatherTrigger = "CREATE TRIGGER trigger_delete AFTER DELETE " +
                "ON Weather " +
                "FOR EACH ROW " +
                "BEGIN " +
                "DELETE FROM AirQuality WHERE cityId = OLD.cityId; " +
                "DELETE FROM WeatherLive WHERE cityId = OLD.cityId; " +
                "DELETE FROM WeatherForecast WHERE cityId = OLD.cityId; " +
                "DELETE FROM LifeIndex WHERE cityId = OLD.cityId; " +
                "END;";
        database.execSQL(weatherTrigger);

    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 4
Project: android-project-gallery   File: LocalDbCacheHelper.java   View source code 6 votes vote down vote up
/**
 * 创建数据库时会回调的接口,在这个方法里面完成对数据库表的创建
 */
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource)
{
	try
	{
		Log.I(TAG, "--------------------- onCreate ---------------------");
		
		TableUtils.createTable(connectionSource, Like.class);
		
		// 数据初始化
		initDatabase(db, connectionSource);
	}
	catch (SQLException e)
	{
		Log.E(TAG, "Can't create database.", e);
		throw new RuntimeException(e);
	}
	
}
 
Example 5
Project: android-project-gallery   File: DatabaseHelper.java   View source code 6 votes vote down vote up
/**
 * 创建数据库时会回调的接口,在这个方法里面完成对数据库表的创建
 */
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
	try {
		Log.I(TAG, "--------------------- onCreate ---------------------");

		TableUtils.createTable(connectionSource, AlbumInfo.class);
		TableUtils.createTable(connectionSource, PhotoInfo.class);

		// 数据初始化
		initDatabase(db, connectionSource);
	} catch (SQLException e) {
		Log.E(TAG, "Can't create database.", e);
		throw new RuntimeException(e);
	}

}
 
Example 6
Project: android-project-gallery   File: DatabaseHelper.java   View source code 6 votes vote down vote up
/**
 * 处理数据库版本升级
 */
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
	Log.I(TAG, "--------------------- onUpgrade ---------------------");
	int version = oldVersion;
	if (version < 4) {
		upgradeFor2(db);
		version = 3;
	}

	if (version != DATABASE_VERSION) {
		Log.W(TAG, "Destroying all old data.");
		try {
			Log.I(TAG, "--------------------- onUpgrade ---------------------");

			TableUtils.dropTable(connectionSource, AlbumInfo.class, true);
			TableUtils.dropTable(connectionSource, PhotoInfo.class, true);

			onCreate(db, connectionSource);
		} catch (SQLException e) {
			Log.E(TAG, "Can't drop databases", e);
			throw new RuntimeException(e);
		}
	}

}
 
Example 7
Project: zlevels   File: UserData.java   View source code 6 votes vote down vote up
/**
 * Saves the user data to the database.
 *
 * @param data The user data to save.
 */
private static void save(UserData data) {
    data.setAvatarUrl(data.getAvatarUrl());
    data.setUsername(data.getUsername());

    ZLevels.async.submit(() -> {
        try {
            ConnectionSource source = Database.openConnection();
            if (source == null) return;

            Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);
            db.createOrUpdate(data);
            Database.closeConnection();
        } catch (Exception e) {
            ZLogger.warn("Could not save UserData for " + data.getUserId() + "!");
            e.printStackTrace();
        }
    });
}
 
Example 8
Project: zlevels   File: UserData.java   View source code 6 votes vote down vote up
/**
 * Deletes this user data from the database and cache.
 */
public void delete() {
    UserData current = this;

    if (cache.containsKey(current.getUserId())) cache.remove(current.getUserId());

    ZLevels.async.submit(() -> {
        try {
            ConnectionSource source = Database.openConnection();
            if (source == null) return;

            Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);

            db.delete(current);

            Database.closeConnection();
        } catch (Exception e) {
            ZLogger.warn("Colud not delete UserData for " + getUserId() + "!");
            e.printStackTrace();
        }
    });
}
 
Example 9
Project: zlevels   File: UserData.java   View source code 6 votes vote down vote up
/**
 * Gets the user data by userId from the cache and database.
 *
 * @param userId The user id.
 * @return The user data.
 */
public static UserData fromId(String userId) {
    if (cache.containsKey(userId)) {
        return cache.get(userId);
    }
    try {
        ConnectionSource source = Database.openConnection();
        if (source == null) return null;

        Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);

        UserData data = db.queryForEq("userId", userId).get(0);

        Database.closeConnection();

        return data;
    } catch (Exception e) {
        if (e instanceof IndexOutOfBoundsException) {
            return null;
        }

        ZLogger.warn("Could not get UserData for " + userId + "!");
        e.printStackTrace();
        return null;
    }
}
 
Example 10
Project: android-overlay-protection   File: DatabaseHelper.java   View source code 6 votes vote down vote up
/**
 * This is called when your application is upgraded and it has a higher version number. This allows you to adjust
 * the various data to match the new version number.
 */
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        Log.i(TAG, "onUpgrade");
        TableUtils.dropTable(connectionSource, SuspectedApp.class, true);
        Log.d(TAG, String.format("Dropped suspected app table!"));
        Dao<WhiteEntry, Integer> whiteListDao = getWhiteListDao();
        DeleteBuilder<WhiteEntry, Integer> deleteBuilder = whiteListDao.deleteBuilder();
        deleteBuilder.where().eq("systemEntry", Boolean.TRUE);
        int deleted = deleteBuilder.delete();
        Log.d(TAG, String.format("Delete %d old system whitelist entries", deleted));
        onCreate(db, connectionSource);
    } catch (SQLException e) {
        Log.e(TAG, "Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example 11
Project: AndroidStarter   File: ModuleDatabase.java   View source code 6 votes vote down vote up
@Provides
@Singleton
public DAORepo provideDAORepo(@NonNull final DatabaseHelperAndroidStarter poDatabaseHelperAndroidStarter) {
    try {
        final ConnectionSource loConnectionSource = poDatabaseHelperAndroidStarter.getConnectionSource();
        final DatabaseTableConfig<RepoEntity> loTableConfig = DatabaseTableConfigUtil.fromClass(loConnectionSource, RepoEntity.class);
        if (loTableConfig != null) {
            return new DAORepo(loConnectionSource, loTableConfig);
        } else {
            return new DAORepo(loConnectionSource);
        }
    } catch (final SQLException loException) {
        if (BuildConfig.DEBUG && DEBUG) {
            Logger.t(TAG).e(loException, "");
        }
    }
    return null;
}
 
Example 12
Project: apparel   File: OrmLiteSqlHelper.java   View source code 6 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        TableUtils.dropTable(connectionSource, EventGuestOutfitItem.class, false);
        TableUtils.dropTable(connectionSource, EventGuestOutfit.class, false);
        TableUtils.dropTable(connectionSource, EventGuest.class, false);
        TableUtils.dropTable(connectionSource, Event.class, false);
        TableUtils.dropTable(connectionSource, Item.class, false);
        TableUtils.dropTable(connectionSource, User.class, false);
        TableUtils.dropTable(connectionSource, Photo.class, false);

        onCreate(database, connectionSource);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 13
Project: AndroidBase   File: DatabaseHandler.java   View source code 6 votes vote down vote up
public void onUpgrade(SQLiteDatabase db, ConnectionSource cs) throws SQLException {
    List<ColumnStruct> oldStruct = DatabaseUtil.getOldTableStruct(db, tableName);
    List<ColumnStruct> newStruct = DatabaseUtil.getNewTableStruct(cs, clazz);

    if (oldStruct.isEmpty() && newStruct.isEmpty()) {
        LogUtils.d("数据表结构都为空!不是合法的数据库bean!!!");
    } else if (oldStruct.isEmpty()) {
        LogUtils.d("新增表");
        create(cs);
    } else if (newStruct.isEmpty()) {
        // 永远不会执行
        LogUtils.d("删除表");
        drop(cs);
    } else {
        dealColumnChange(db, cs, oldStruct, newStruct);
    }
}
 
Example 14
Project: AndroidBase   File: DatabaseHandler.java   View source code 6 votes vote down vote up
/**
 * 处理表有变化的情况
 */
private void dealColumnChange(SQLiteDatabase db, ConnectionSource cs, List<ColumnStruct> oldStruct,
                              List<ColumnStruct> newStruct) throws SQLException {
    if (DatabaseUtil.hasChangeColumnLimit(oldStruct, newStruct)) {
        LogUtils.d("数据表已有字段的描述改变");
        // 已有字段描述改变了,删除旧表,重建新表
        reset(cs);
    } else {
        // 数据表已有字段的描述没有改变
        // 判断列是否有增减
        List<String> oldColumns = DatabaseUtil.getColumnNames(oldStruct);
        List<String> newColumns = DatabaseUtil.getColumnNames(newStruct);
        if (!oldColumns.equals(newColumns)) {
            LogUtils.d("表发生了变化");
            // 判断列的变化情况:增加、减少、增减
            List<String> deleteList = DatabaseUtil.getDeleteColumns(oldColumns, newColumns);
            upgradeByCopy(db, cs, getCopyColumns(oldColumns, deleteList));
        } else {
            LogUtils.i("表没有发生变化,不需要更新数据表");
        }
    }
}
 
Example 15
Project: AndroidBase   File: OrmLiteDao.java   View source code 6 votes vote down vote up
/**
 * 数据批量处理
 *
 * @param list      要处理的数据集合
 * @param batchType 操作类型
 * @return
 */
private boolean doBatchInTransaction(final List<T> list, final int batchType) {
    boolean doBatch = false;
    ConnectionSource connectionSource = ormLiteDao.getConnectionSource();
    TransactionManager transactionManager = new TransactionManager(connectionSource);
    Callable<Boolean> callable = new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return doBatch(list, batchType);
        }
    };
    try {
        doBatch = transactionManager.callInTransaction(callable);
    } catch (SQLException e) {
        LogUtils.e(e);
    }
    return doBatch;
}
 
Example 16
Project: AndroidAPS   File: DatabaseHelper.java   View source code 6 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
    try {
        log.info("onCreate");
        TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
        TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
        TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
        TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
        TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
        TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
        TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
        TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
        TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class);
        TableUtils.createTableIfNotExists(connectionSource, Food.class);
    } catch (SQLException e) {
        log.error("Can't create database", e);
        throw new RuntimeException(e);
    }
}
 
Example 17
Project: AndroidAPS   File: DatabaseHelper.java   View source code 6 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        if (oldVersion == 7 && newVersion == 8) {
            log.debug("Upgrading database from v7 to v8");
            TableUtils.dropTable(connectionSource, Treatment.class, true);
            TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
        } else {
            log.info(DatabaseHelper.class.getName(), "onUpgrade");
            TableUtils.dropTable(connectionSource, TempTarget.class, true);
            TableUtils.dropTable(connectionSource, Treatment.class, true);
            TableUtils.dropTable(connectionSource, BgReading.class, true);
            TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
            TableUtils.dropTable(connectionSource, DbRequest.class, true);
            TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
            TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
            TableUtils.dropTable(connectionSource, CareportalEvent.class, true);
            TableUtils.dropTable(connectionSource, ProfileSwitch.class, true);
            TableUtils.dropTable(connectionSource, Food.class, true);
            onCreate(database, connectionSource);
        }
    } catch (SQLException e) {
        log.error("Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example 18
Project: privacy-friendly-shopping-list   File: DataBaseHelper.java   View source code 6 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database, final ConnectionSource connectionSource)
{
    try
    {
        setupClasses();
        PFALogger.debug(getClass().getName(), ON_CREATE, START);
        for ( Class aClass : entityClasses )
        {
            TableUtils.createTable(connectionSource, aClass);
        }
    }
    catch ( Exception e )
    {
        PFALogger.error(getClass().getName(), ON_CREATE, e);
    }
}
 
Example 19
Project: privacy-friendly-shopping-list   File: DataBaseHelper.java   View source code 6 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion)
{
    try
    {
        setupClasses();
        for ( Class aClass : entityClasses )
        {
            TableUtils.dropTable(connectionSource, aClass, true);
        }
        onCreate(database, connectionSource);
    }
    catch ( SQLException e )
    {
        PFALogger.error(getClass().getName(), ON_UPGRADE, e);
    }
}
 
Example 20
Project: AndroidDownloader   File: DBHelper.java   View source code 5 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
  try {
    TableUtils.createTable(connectionSource, MyBusinessInfLocal.class);
    TableUtils.createTable(connectionSource, MyDownloadInfLocal.class);
  } catch (SQLException e) {
    e.printStackTrace();
  }
}
 
Example 21
Project: AndroidDownloader   File: DBHelper.java   View source code 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion,
    int newVersion) {
  try {
    TableUtils.dropTable(connectionSource, MyBusinessInfLocal.class, true);
    TableUtils.dropTable(connectionSource, MyDownloadInfLocal.class, true);
  } catch (SQLException e) {
    e.printStackTrace();
  }
}
 
Example 22
Project: Poetry   File: DatabaseHelper.java   View source code 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion)
{
    super.onUpgrade(db, connectionSource, oldVersion, newVersion);

    // When calling the parent class, the whole database is deleted and re-created.
    // Custom upgrade code goes here to override that behavior.
}
 
Example 23
Project: LeagueOfAndroid   File: DbHelperImpl.java   View source code 5 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
    try {
        TableUtils.createTable(connectionSource, Champion.class);
    } catch (SQLException e) {
        Log.e(DbHelperImpl.class.getName(), "Error, unable to create table");
    }
}
 
Example 24
Project: LeagueOfAndroid   File: DbHelperImpl.java   View source code 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        TableUtils.dropTable(connectionSource, Champion.class, true);
    } catch (SQLException e) {
        Log.e(DbHelperImpl.class.getName(), "Error, unable to delete table");
    }

    onCreate(database, connectionSource);
}
 
Example 25
Project: mxisd   File: OrmLiteSqliteStorage.java   View source code 5 votes vote down vote up
OrmLiteSqliteStorage(String path) {
    withCatcher(() -> {
        File parent = new File(path).getParentFile();
        if (!parent.mkdirs() && !parent.isDirectory()) {
            throw new RuntimeException("Unable to create DB parent directory: " + parent);
        }

        ConnectionSource connPool = new JdbcConnectionSource("jdbc:sqlite:" + path);
        invDao = createDaoAndTable(connPool, ThreePidInviteIO.class);
        sessionDao = createDaoAndTable(connPool, ThreePidSessionDao.class);
    });
}
 
Example 26
Project: UnforgetIt   File: DataBaseJPAHelper.java   View source code 5 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
    try {
        Log.d(this.getClass().getName(), "onCreate");
        TableUtils.createTable(connectionSource, Task.class);
    } catch (SQLException e) {
        Log.e(this.getClass().getName(), "Can't create database", e);
        throw new RuntimeException(e);
    }

}
 
Example 27
Project: UnforgetIt   File: DataBaseJPAHelper.java   View source code 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        Log.d(this.getClass().getName(), "onUpgrade");
        TableUtils.dropTable(connectionSource, Task.class, true);
        onCreate(database, connectionSource);
    } catch (SQLException e) {
        Log.e(this.getClass().getName(), "Can't drop databases", e);
        throw new RuntimeException(e);
    }

}
 
Example 28
Project: android-project-gallery   File: LocalDbCacheHelper.java   View source code 5 votes vote down vote up
/**
 * 处理数据库版本升级
 */
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion)
{
	Log.I(TAG, "--------------------- onUpgrade ---------------------");
	int version = oldVersion;
	if (version < 4)
	{
		upgradeFor2(db);
		version = 3;
	}
	
	if (version != DATABASE_VERSION)
	{
		Log.W(TAG, "Destroying all old data.");
		try
		{
			Log.I(TAG, "--------------------- onUpgrade ---------------------");
			
			TableUtils.dropTable(connectionSource, Like.class, true);
			
			onCreate(db, connectionSource);
		}
		catch (SQLException e)
		{
			Log.E(TAG, "Can't drop databases", e);
			throw new RuntimeException(e);
		}
	}
	
}
 
Example 29
Project: android-project-gallery   File: UserDatabaseHelper.java   View source code 5 votes vote down vote up
/**
 * 创建数据库时会回调的接口,在这个方法里面完成对数据库表的创建
 */
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
	try {
		Log.I(TAG, "--------------------- onCreate ---------------------");
		TableUtils.createTable(connectionSource, MyFavorites.class);
		TableUtils.createTable(connectionSource, FocusItemInfo.class);

		initDatabase();
	} catch (SQLException e) {
		Log.E(TAG, "Can't create database", e);
		throw new RuntimeException(e);
	}

}
 
Example 30
Project: android-project-gallery   File: UserDatabaseHelper.java   View source code 5 votes vote down vote up
/**
 * 处理数据库版本升级
 */
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
	try {
		Log.I(TAG, "--------------------- onUpgrade ---------------------");
		TableUtils.dropTable(connectionSource, MyFavorites.class, true);
		TableUtils.dropTable(connectionSource, FocusItemInfo.class, true);

		onCreate(db, connectionSource);
	} catch (SQLException e) {
		Log.E(TAG, "Can't drop databases", e);
		throw new RuntimeException(e);
	}
}
 
Example 31
Project: OkhttpDownloader   File: DBHelper.java   View source code 5 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase database,
                     ConnectionSource connectionSource)
{
    try
    {
        TableUtils.createTable(connectionSource, DownloadInfo.class);
    } catch (SQLException e)
    {
        e.printStackTrace();
    }
}
 
Example 32
Project: OkhttpDownloader   File: DBHelper.java   View source code 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database,
                      ConnectionSource connectionSource, int oldVersion, int newVersion)
{
    try
    {
        TableUtils.dropTable(connectionSource, DownloadInfo.class, true);
        onCreate(database, connectionSource);
    } catch (SQLException e)
    {
        e.printStackTrace();
    }
}
 
Example 33
Project: zlevels   File: Database.java   View source code 5 votes vote down vote up
/**
 * Loads the database.
 */
public static void load() {
    ZLogger.info("Loading db...");

    try {
        ConnectionSource source = openConnection();
        DaoManager.createDao(source, UserData.class);

        TableUtils.createTableIfNotExists(source, UserData.class);

        ZLogger.info("Successfully loaded Database!");
    } catch (Exception e) {
        ZLogger.warn("Could not load Database!");
    }
}
 
Example 34
Project: SelectName   File: DatabaseHelper.java   View source code 5 votes vote down vote up
public void onCreate(SQLiteDatabase database,
		ConnectionSource connectionSource) {

	try {
		if (clazzes != null) {
			for (Class<?> clazz : clazzes) {
				TableUtils.createTable(connectionSource, clazz);
			}
		}
	} catch (SQLException e) {
		LogUtils.e("DatabaseHelper无法创建数据库 :" + e);
	}

}
 
Example 35
Project: SelectName   File: DatabaseHelper.java   View source code 5 votes vote down vote up
public void onUpgrade(android.database.sqlite.SQLiteDatabase database,
		ConnectionSource connectionSource, int oldVersion, int newVersion) {
	try {
		if (clazzes != null) {
			for (Class<?> clazz : clazzes) {
				TableUtils.dropTable(connectionSource, clazz, true);
			}
			onCreate(database, connectionSource);
		}
	} catch (SQLException e) {
		LogUtils.d("DatabaseHelper升级数据库失败:" + e);
	}
}
 
Example 36
Project: CaiNiaoMes   File: OrmDBHelper.java   View source code 5 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
    try {
        TableUtils.clearTable(connectionSource, Message.class);
        TableUtils.clearTable(connectionSource, Conversation.class);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 37
Project: ToBuy   File: DbOpenHelper.java   View source code 5 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
    try {
        TableUtils.createTable(connectionSource, ToBuyItem.class);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 38
Project: fiszki   File: DbUpdater.java   View source code 5 votes vote down vote up
protected void execute(ConnectionSource connectionSource) {
    try {
        TableUtils.dropTable(connectionSource, Word.class, true);
        TableUtils.dropTable(connectionSource, Cluster.class, true);
        TableUtils.dropTable(connectionSource, Lesson.class, true);

        new DbCreator(dbHelper, assetsHelper).execute(connectionSource);

    } catch (SQLException ex) {
        throw new RuntimeException("Can't update databases", ex);
    }
}
 
Example 39
Project: fiszki   File: DbCreator.java   View source code 5 votes vote down vote up
protected void execute(ConnectionSource connectionSource) {
    try {
        TableUtils.createTable(connectionSource, Lesson.class);
        TableUtils.createTable(connectionSource, Cluster.class);
        TableUtils.createTable(connectionSource, Word.class);

        this.insertApplicationData();
        this.insertConfigurationData();

    } catch (SQLException ex) {
        throw new RuntimeException("Can't create database", ex);
    }
}
 
Example 40
Project: XMPPSample_Studio   File: DatabaseHelper.java   View source code 5 votes vote down vote up
public void onCreate(SQLiteDatabase paramSQLiteDatabase,
                     ConnectionSource paramConnectionSource) {
    for (int i = 0; i < daoList.length; i++) {
        try {
            TableUtils.createTable(paramConnectionSource, daoList[i]);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}