本文整理汇总了Java中com.j256.ormlite.support.ConnectionSource类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionSource类的具体用法?Java ConnectionSource怎么用?Java ConnectionSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionSource类属于com.j256.ormlite.support包,在下文中一共展示了ConnectionSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTable
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
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();
}
}
示例2: updateTable
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
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);
}
}
示例3: onCreate
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
@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();
}
}
示例4: onCreate
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 创建数据库时会回调的接口,在这个方法里面完成对数据库表的创建
*/
@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);
}
}
示例5: onCreate
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 创建数据库时会回调的接口,在这个方法里面完成对数据库表的创建
*/
@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);
}
}
示例6: onUpgrade
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 处理数据库版本升级
*/
@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);
}
}
}
示例7: save
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 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();
}
});
}
示例8: delete
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 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();
}
});
}
示例9: fromId
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 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;
}
}
示例10: onUpgrade
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 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);
}
}
示例11: provideDAORepo
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
@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;
}
示例12: onUpgrade
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
@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();
}
}
示例13: onUpgrade
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
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);
}
}
示例14: dealColumnChange
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 处理表有变化的情况
*/
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("表没有发生变化,不需要更新数据表");
}
}
}
示例15: doBatchInTransaction
import com.j256.ormlite.support.ConnectionSource; //导入依赖的package包/类
/**
* 数据批量处理
*
* @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;
}