本文整理汇总了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);
}
}