本文整理匯總了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;
}