本文整理匯總了Java中com.j256.ormlite.table.TableUtils類的典型用法代碼示例。如果您正苦於以下問題:Java TableUtils類的具體用法?Java TableUtils怎麽用?Java TableUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TableUtils類屬於com.j256.ormlite.table包,在下文中一共展示了TableUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTable
import com.j256.ormlite.table.TableUtils; //導入依賴的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.table.TableUtils; //導入依賴的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.table.TableUtils; //導入依賴的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: initDb
import com.j256.ormlite.table.TableUtils; //導入依賴的package包/類
private void initDb() throws SQLException {
// create a connection source to our database
connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "",
new HsqldbDatabaseType());
// instantiate the DAO
vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
if (!vaultDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
} else {
LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
}
rawDao = DaoManager.createDao(connectionSource, RawEntry.class);
if (!rawDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, RawEntry.class);
}
// TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
}
示例5: AbstractDaoService
import com.j256.ormlite.table.TableUtils; //導入依賴的package包/類
public AbstractDaoService(Class clazz, SpringConfiguration configuration) {
try {
this.clazz = clazz;
// TODO: let user create it's own database
connection = DatabaseUtils.getH2OrmliteConnectionPool(configuration.getDatabasePath(),
// please do not laugh :)
SpringConfiguration.DB_LOGIN, SpringConfiguration.DB_PASSWORD);
TableUtils.createTableIfNotExists(connection, clazz);
// instantiate the dao
dao = DaoManager.createDao(connection, clazz);
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}
示例6: onCreate
import com.j256.ormlite.table.TableUtils; //導入依賴的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);
}
}
示例7: onCreate
import com.j256.ormlite.table.TableUtils; //導入依賴的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);
}
}
示例8: onUpgrade
import com.j256.ormlite.table.TableUtils; //導入依賴的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);
}
}
}
示例9: initDb
import com.j256.ormlite.table.TableUtils; //導入依賴的package包/類
/**
* Initializes the actual database as a {@link JdbcConnectionSource}.
*
* @throws SQLException Thrown if the database can not be successfully initialized.
*/
private void initDb() throws SQLException {
// create a connection source to our database
connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "",
new HsqldbDatabaseType());
// instantiate the DAO
vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
if (!vaultDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
} else {
LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
}
rawDao = DaoManager.createDao(connectionSource, RawEntry.class);
if (!rawDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, RawEntry.class);
}
// TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
}
示例10: onUpgrade
import com.j256.ormlite.table.TableUtils; //導入依賴的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: onUpgrade
import com.j256.ormlite.table.TableUtils; //導入依賴的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();
}
}
示例12: onCreate
import com.j256.ormlite.table.TableUtils; //導入依賴的package包/類
@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);
}
}
示例13: onUpgrade
import com.j256.ormlite.table.TableUtils; //導入依賴的package包/類
@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);
}
}
示例14: onCreate
import com.j256.ormlite.table.TableUtils; //導入依賴的package包/類
@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);
}
}
示例15: onUpgrade
import com.j256.ormlite.table.TableUtils; //導入依賴的package包/類
@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);
}
}