當前位置: 首頁>>代碼示例>>Java>>正文


Java TableUtils.createTableIfNotExists方法代碼示例

本文整理匯總了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);
    }
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:19,代碼來源:VaultDao.java

示例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);
        }
    }
 
開發者ID:remipassmoilesel,項目名稱:simple-hostel-management,代碼行數:20,代碼來源:AbstractDaoService.java

示例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);
    }
 
開發者ID:lucasbuschlinger,項目名稱:BachelorPraktikum,代碼行數:24,代碼來源:VaultDao.java

示例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);
    }
}
 
開發者ID:MilosKozak,項目名稱:AndroidAPS,代碼行數:20,代碼來源:DatabaseHelper.java

示例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);
    }
}
 
開發者ID:MilosKozak,項目名稱:AndroidAPS,代碼行數:27,代碼來源:DatabaseHelper.java

示例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();
    }
    
}
 
開發者ID:R4stl1n,項目名稱:halgnu,代碼行數:22,代碼來源:DatabaseManager.java

示例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);
  }
 
開發者ID:learning-layers,項目名稱:Expert-Identification-Service,代碼行數:23,代碼來源:ExpertRecommenderService.java

示例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);
   }
 
開發者ID:rwth-acis,項目名稱:Expert-Recommender-Service,代碼行數:23,代碼來源:ExpertRecommenderService.java

示例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;
}
 
開發者ID:securityfirst,項目名稱:Umbrella_android,代碼行數:18,代碼來源:Global.java

示例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;
}
 
開發者ID:securityfirst,項目名稱:Umbrella_android,代碼行數:20,代碼來源:Global.java

示例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);
    }
}
 
開發者ID:wakhub,項目名稱:monodict,代碼行數:19,代碼來源:DatabaseOpenHelper.java

示例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!");
    }
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:18,代碼來源:Database.java

示例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);
  }
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:8,代碼來源:CustomTableCreator.java

示例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);
}
 
開發者ID:AskViky,項目名稱:CommunityService,代碼行數:11,代碼來源:CookbookDao.java

示例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);
        }
    }
}
 
開發者ID:fgreinus,項目名稱:jwebpoll,代碼行數:14,代碼來源:Database.java


注:本文中的com.j256.ormlite.table.TableUtils.createTableIfNotExists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。