当前位置: 首页>>代码示例>>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;未经允许,请勿转载。