Java Code Examples for com.j256.ormlite.table.TableUtils#dropTable()

The following examples show how to use com.j256.ormlite.table.TableUtils#dropTable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserDatabaseHelper.java    From android-project-wo2b with Apache License 2.0 6 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 2
Source File: TableCreatorTest.java    From ormlite-jdbc with ISC License 6 votes vote down vote up
@Test
public void testDestroyDoesntExist() throws Exception {
	Dao<Foo, Object> fooDao = createDao(Foo.class, false);
	List<Dao<?, ?>> daoList = new ArrayList<Dao<?, ?>>();
	daoList.add(fooDao);
	TableCreator tableCreator = new TableCreator(connectionSource, daoList);
	try {
		System.setProperty(TableCreator.AUTO_CREATE_TABLES, Boolean.TRUE.toString());
		System.setProperty(TableCreator.AUTO_DROP_TABLES, Boolean.TRUE.toString());
		tableCreator.maybeCreateTables();
		TableUtils.dropTable(connectionSource, Foo.class, true);
		tableCreator.maybeDropTables();
	} finally {
		System.clearProperty(TableCreator.AUTO_CREATE_TABLES);
		System.clearProperty(TableCreator.AUTO_DROP_TABLES);
	}
}
 
Example 3
Source File: DatabaseHelper.java    From android-overlay-protection with Apache License 2.0 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 4
Source File: Database.java    From PacketProxy with Apache License 2.0 5 votes vote down vote up
public <T> void dropTable(Class<T> c) throws Exception
{
	if(c==Packet.class){
		dropPacketTableFaster();
	}else {
		TableUtils.dropTable(source, c, true);
	}
}
 
Example 5
Source File: DatabaseHelper.java    From ormlite-android-gradle-plugin with Apache License 2.0 5 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(DatabaseHelper.class.getName(), "onUpgrade");
        TableUtils.dropTable(connectionSource, SimpleData.class, true);
        // after we drop the old databases, we create the new ones
        onCreate(db, connectionSource);
    } catch (SQLException e) {
        Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: DatabaseHelper.java    From ETSMobile-Android2 with Apache License 2.0 5 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(DatabaseHelper.class.getName(), "onUpgrade");
		TableUtils.dropTable(connectionSource, Etudiant.class, true);
           TableUtils.dropTable(connectionSource, Cours.class, true);
           TableUtils.dropTable(connectionSource, JoursRemplaces.class, true);
           TableUtils.dropTable(connectionSource, ListeDesElementsEvaluation.class, true);
           TableUtils.dropTable(connectionSource, ElementEvaluation.class, true);
           TableUtils.dropTable(connectionSource, Enseignant.class, true);
           TableUtils.dropTable(connectionSource, HoraireActivite.class, true);
           TableUtils.dropTable(connectionSource, Personne.class, true);
           TableUtils.dropTable(connectionSource, Programme.class, true);
           TableUtils.dropTable(connectionSource, Trimestre.class, true);
           TableUtils.dropTable(connectionSource, Event.class, true);
           TableUtils.dropTable(connectionSource, TodaysCourses.class, true);
           TableUtils.dropTable(connectionSource, TodaysCourses.Seance.class, true);
           TableUtils.dropTable(connectionSource, HoraireExamenFinal.class, true);
           TableUtils.dropTable(connectionSource, Seances.class, true);
		TableUtils.dropTable(connectionSource, FicheEmploye.class, true);
		TableUtils.dropTable(connectionSource, Sponsor.class, true);
           TableUtils.dropTable(connectionSource, MonETSNotification.class, true);

		// after we drop the old databases, we create the new ones
		onCreate(db, connectionSource);
	} catch (SQLException e) {
		Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e);
		throw new RuntimeException(e);
	}
}
 
Example 7
Source File: DBHelper.java    From A-week-to-develop-android-app-plan with Apache License 2.0 5 votes vote down vote up
/**
 * 更新表
 * @param database
 * @param connectionSource
 * @param oldVersion
 * @param newVersion
 */
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        // 示例
        TableUtils.dropTable(connectionSource, User.class, true);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: DatabaseHelper.java    From mOrgAnd with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        Log.i(DatabaseHelper.class.getName(), "onUpgrade");
        TableUtils.dropTable(connectionSource, OrgNode.class, true);
        TableUtils.dropTable(connectionSource, OrgFile.class, true);

        onCreate(db, connectionSource);
    } catch (SQLException e) {
        Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: DatabaseHelper.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public void resetCareportalEvents() {
    try {
        TableUtils.dropTable(connectionSource, CareportalEvent.class, true);
        TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
    } catch (SQLException e) {
        log.error("Unhandled exception", e);
    }
    scheduleCareportalEventChange();
}
 
Example 10
Source File: ExtentTagTest.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
protected void dropAllTables(ConnectionSource source) throws Exception {
    TableUtils.dropTable(source, CharIndex.class, true);
    TableUtils.dropTable(source, ExtentTag.class, true);
    TableUtils.dropTable(source, TagType.class, true);
    TableUtils.dropTable(source, AttributeType.class, true);
    TableUtils.dropTable(source, Attribute.class, true);

    TableUtils.dropTable(source, LinkTag.class, true);
    TableUtils.dropTable(source, ArgumentType.class, true);
    TableUtils.dropTable(source, Argument.class, true);
}
 
Example 11
Source File: DatabaseHelper.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public void resetTemporaryBasals() {
    try {
        TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
        TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
        updateEarliestDataChange(0);
    } catch (SQLException e) {
        log.error("Unhandled exception", e);
    }
    VirtualPumpPlugin.getPlugin().setFakingStatus(false);
    scheduleTemporaryBasalChange();
}
 
Example 12
Source File: DatabaseHelper.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public void resetTempTargets() {
    try {
        TableUtils.dropTable(connectionSource, TempTarget.class, true);
        TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
    } catch (SQLException e) {
        log.error("Unhandled exception", e);
    }
    scheduleTemporaryTargetChange();
}
 
Example 13
Source File: DatabaseHelper.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        this.oldVersion = oldVersion;
        this.newVersion = newVersion;

        if (oldVersion < 7) {
            log.info(DatabaseHelper.class.getName(), "onUpgrade");
            TableUtils.dropTable(connectionSource, TempTarget.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);
            onCreate(database, connectionSource);
        } else if (oldVersion < 10) {
            TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class);
            TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class);
            TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class);
            database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_BOLUS_IDS + "\", " + System.currentTimeMillis() + " " +
                    "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\")");
            database.execSQL("INSERT INTO sqlite_sequence (name, seq) SELECT \"" + DATABASE_INSIGHT_PUMP_IDS + "\", " + System.currentTimeMillis() + " " +
                    "WHERE NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = \"" + DATABASE_INSIGHT_PUMP_IDS + "\")");
        } else if (oldVersion < 11) {
            database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DATABASE_INSIGHT_BOLUS_IDS + "\"");
            database.execSQL("UPDATE sqlite_sequence SET seq = " + System.currentTimeMillis() + " WHERE name = \"" + DATABASE_INSIGHT_PUMP_IDS + "\"");
        }
    } catch (SQLException e) {
        log.error("Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example 14
Source File: ORMLiteExecutor.java    From android-orm-benchmark-updated with Apache License 2.0 5 votes vote down vote up
@Override
public long dropDb() throws SQLException {
    long start = System.nanoTime();
    ConnectionSource connectionSource = mHelper.getConnectionSource();
    TableUtils.dropTable(connectionSource, User.class, true);
    TableUtils.dropTable(connectionSource, Message.class, true);
    return System.nanoTime() - start;
}
 
Example 15
Source File: DatabaseHelper.java    From android-project-wo2b with Apache License 2.0 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, 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 16
Source File: DatabaseHelper.java    From XMPPSample_Studio with Apache License 2.0 5 votes vote down vote up
public void drop() {
    for (int i = 0; i < daoList.length; i++) {
        try {
            TableUtils.dropTable(getConnectionSource(), daoList[i], true);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
 
Example 17
Source File: TableCreator.java    From ormlite-jdbc with ISC License 5 votes vote down vote up
public void destroy() {
	if (!Boolean.parseBoolean(System.getProperty(AUTO_DROP_TABLES))) {
		return;
	}
	for (DatabaseTableConfig<?> tableConfig : createdClasses) {
		try {
			TableUtils.dropTable(connectionSource, tableConfig, false);
		} catch (Exception e) {
			// we don't stop because the table might already exist
			System.err.println("Was unable to auto-drop table for " + tableConfig.getDataClass());
			e.printStackTrace();
		}
	}
	createdClasses.clear();
}
 
Example 18
Source File: DBHelper.java    From AndroidDownloader with Apache License 2.0 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 19
Source File: DatabaseHelper.java    From renrenpay-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int i, int i1) {
    try {
        TableUtils.dropTable(connectionSource, User.class,true);
        TableUtils.dropTable(connectionSource, Logs.class,true);
        TableUtils.createTable(connectionSource, User.class);
        TableUtils.createTable(connectionSource, Logs.class);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example 20
Source File: BaseCoreTest.java    From ormlite-core with ISC License 4 votes vote down vote up
protected <T> void dropTable(Class<T> clazz, boolean ignoreErrors) throws SQLException {
	// drop the table and ignore any errors along the way
	TableUtils.dropTable(connectionSource, clazz, ignoreErrors);
}