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