本文整理汇总了Java中com.j256.ormlite.table.TableUtils.createTableIfNotExists方法的典型用法代码示例。如果您正苦于以下问题:Java TableUtils.createTableIfNotExists方法的具体用法?Java TableUtils.createTableIfNotExists怎么用?Java TableUtils.createTableIfNotExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.table.TableUtils
的用法示例。
在下文中一共展示了TableUtils.createTableIfNotExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: DatabaseManager
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
protected DatabaseManager() {
String databaseUrl = "jdbc:sqlite:halgnu.db";
try {
m_connectionSource = new JdbcConnectionSource(databaseUrl);
// Create daos
m_memberDao = DaoManager.createDao(m_connectionSource, MemberModel.class);
m_activityDao = DaoManager.createDao(m_connectionSource, ActivityModel.class);
TableUtils.createTableIfNotExists(m_connectionSource, MemberModel.class);
TableUtils.createTableIfNotExists(m_connectionSource, ActivityModel.class);
// Check if tables need to be created
CheckIfAdminExists();
} catch (SQLException e) {
e.printStackTrace();
}
}
示例7: saveClickPositions
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
@POST
@Path("datasets/{datasetId}/position")
public void saveClickPositions(@PathParam(value = "datasetId") String datasetId,
@DefaultValue("-1") @QueryParam("expertsId") String expertsId,
@DefaultValue("-1") @QueryParam("position") int position) {
String datasetName = getDatasetName(datasetId);
if (datasetName == null) {
// Throw custom exception.
}
DatabaseHandler dbHandler = new DatabaseHandler();
// log.info("USRNAME:: " + username);
try {
TableUtils.createTableIfNotExists(dbHandler.getConnectionSource(), dbHandler.getEntityConfigOfDataSet(dbHandler.getConnectionSource(), UserClickDetails.class, datasetName) );
} catch (SQLException e) {
e.printStackTrace();
}
dbHandler.saveClickPositions(expertsId, position);
}
示例8: saveClickPositions
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
@POST
@Path("datasets/{datasetId}/position")
public void saveClickPositions(@PathParam(value = "datasetId") String datasetId,
@QueryParam(name = "expertsId", defaultValue = "-1") String expertsId, @QueryParam(name = "position", defaultValue = "-1") int position) {
String databaseName = getDatabaseName(datasetId);
if (databaseName == null) {
// Throw custom exception.
}
DatabaseHandler dbHandler = null;
dbHandler = new DatabaseHandler(databaseName, "root", "");
// log.info("USRNAME:: " + username);
try {
TableUtils.createTableIfNotExists(dbHandler.getConnectionSource(), UserClickDetails.class);
} catch (SQLException e) {
e.printStackTrace();
}
dbHandler.saveClickPositions(expertsId, position);
}
示例9: getDaoFormValue
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
public Dao<FormValue, String> getDaoFormValue() {
if (daoFormValue == null) {
try {
TableUtils.createTableIfNotExists(getOrmHelper().getConnectionSource(), FormValue.class);
daoFormValue = getOrmHelper().getDao(FormValue.class);
long count = getDaoForm().countOf();
if (count < 1) {
getForms(true);
} else if (count < 2) {
getForms(false);
}
} catch (SQLiteException | SQLException e) {
Timber.e(e);
}
}
return daoFormValue;
}
示例10: getDaoFeedSource
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
public Dao<FeedSource, String> getDaoFeedSource() {
if (daoFeedSource == null) {
try {
TableUtils.createTableIfNotExists(getOrmHelper().getConnectionSource(), FeedSource.class);
daoFeedSource = getOrmHelper().getDao(FeedSource.class);
if (daoFeedSource.countOf() < 1) {
daoFeedSource.create(new FeedSource("ReliefWeb", 0));
daoFeedSource.create(new FeedSource("UN", 1));
daoFeedSource.create(new FeedSource("FCO", 2));
daoFeedSource.create(new FeedSource("CDC", 3));
daoFeedSource.create(new FeedSource("Global Disaster and Alert Coordination System", 4));
daoFeedSource.create(new FeedSource("US State Department Country Warnings", 5));
}
} catch (SQLiteException | SQLException e) {
Timber.e(e);
}
}
return daoFeedSource;
}
示例11: onCreate
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
Log.d(TAG, "onCreate");
List<String> tableNames = getTableNames(database);
try {
if (!tableNames.contains("bookmark")) {
TableUtils.createTableIfNotExists(connectionSource, Bookmark.class);
Bookmark.initData((Dao<Bookmark, Long>) getDao(Bookmark.class));
}
if (!tableNames.contains("card")) {
TableUtils.createTableIfNotExists(connectionSource, Card.class);
Card.initData((Dao<Card, Long>) getDao(Card.class));
}
} catch (SQLException e) {
Log.d(TAG, "Failed to create tables", e);
}
}
示例12: load
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
/**
* Loads the database.
*/
public static void load() {
ZLogger.info("Loading db...");
try {
ConnectionSource source = openConnection();
DaoManager.createDao(source, UserData.class);
TableUtils.createTableIfNotExists(source, UserData.class);
ZLogger.info("Successfully loaded Database!");
} catch (Exception e) {
ZLogger.warn("Could not load Database!");
}
}
示例13: createTableIfNotExists
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
private void createTableIfNotExists(DatabaseTableConfig<?> tableConfig) {
try {
TableUtils.createTableIfNotExists(connectionSource, tableConfig);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例14: createTable
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void createTable(ConnectionSource connectionSource) throws SQLException {
TableUtils.createTableIfNotExists(connectionSource, Cookbook.class);
mCookbookDao = DaoManager.createDao(connectionSource, Cookbook.class);
Cookbook cb = new Cookbook();
cb.setProfile("大宅门");
cb.setStyle("京城四方");
mCookbookDao.create(cb);
}
示例15: initTables
import com.j256.ormlite.table.TableUtils; //导入方法依赖的package包/类
private void initTables() {
try {
TableUtils.createTableIfNotExists(dbConn, Answer.class);
TableUtils.createTableIfNotExists(dbConn, Poll.class);
TableUtils.createTableIfNotExists(dbConn, Question.class);
TableUtils.createTableIfNotExists(dbConn, Vote.class);
} catch (SQLException ex) {
ex.printStackTrace();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("", ex);
}
}
}