本文整理汇总了Java中com.j256.ormlite.table.DatabaseTableConfig.fromClass方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseTableConfig.fromClass方法的具体用法?Java DatabaseTableConfig.fromClass怎么用?Java DatabaseTableConfig.fromClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.table.DatabaseTableConfig
的用法示例。
在下文中一共展示了DatabaseTableConfig.fromClass方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTableConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends BaseData> DatabaseTableConfig<T> getTableConfig(Class<T> clazz) {
DatabaseTableConfig<T> result = null;
if (tableConfigs.containsKey(clazz)) {
result = (DatabaseTableConfig<T>) tableConfigs.get(clazz);
} else {
try {
result = DatabaseTableConfig.fromClass(getConnectionSource(),
clazz);
} catch (java.sql.SQLException e) {
throw new android.database.SQLException(e.getMessage());
}
tableConfigs.put(clazz, result);
}
return result;
}
示例2: testCreateTableConfigIfNotExists
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
public void testCreateTableConfigIfNotExists() throws Exception {
dropTable(LocalFoo.class, true);
Dao<LocalFoo, Integer> fooDao = createDao(LocalFoo.class, false);
try {
fooDao.countOf();
fail("Should have thrown an exception");
} catch (Exception e) {
// ignored
}
DatabaseTableConfig<LocalFoo> tableConfig = DatabaseTableConfig.fromClass(connectionSource, LocalFoo.class);
TableUtils.createTableIfNotExists(connectionSource, tableConfig);
assertEquals(0, fooDao.countOf());
// should not throw
TableUtils.createTableIfNotExists(connectionSource, tableConfig);
assertEquals(0, fooDao.countOf());
}
示例3: testSelfReferenceWithLoadedConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
@Test
public void testSelfReferenceWithLoadedConfig() throws Exception {
DaoManager.clearCache();
/*
* If a class was loaded as a config (this was found under Android) then, when it went recursive it would build
* itself and set its foreign field to be a primitive. Then when it re-configured itself it would scream because
* the primitive was marked as foreign.
*
* The answer was to do a better job of pre-caching the DAOs in the DaoManager.
*/
DatabaseTableConfig<SelfReference> config =
DatabaseTableConfig.fromClass(connectionSource, SelfReference.class);
@SuppressWarnings("unchecked")
List<DatabaseTableConfig<?>> configs = new ArrayList<DatabaseTableConfig<?>>(Arrays.asList(config));
DaoManager.addCachedDatabaseConfigs(configs);
// this used to throw an exception
DaoManager.createDao(connectionSource, SelfReference.class);
}
示例4: testMoreComplexClassLoopWithLoadedConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
@Test
public void testMoreComplexClassLoopWithLoadedConfig() throws Exception {
DaoManager.clearCache();
DatabaseTableConfig<MoreComplexLoopOne> config1 =
DatabaseTableConfig.fromClass(connectionSource, MoreComplexLoopOne.class);
DatabaseTableConfig<MoreComplexLoopTwo> config2 =
DatabaseTableConfig.fromClass(connectionSource, MoreComplexLoopTwo.class);
DatabaseTableConfig<MoreComplexLoopThree> config3 =
DatabaseTableConfig.fromClass(connectionSource, MoreComplexLoopThree.class);
DatabaseTableConfig<MoreComplexLoopFour> config4 =
DatabaseTableConfig.fromClass(connectionSource, MoreComplexLoopFour.class);
@SuppressWarnings("unchecked")
List<DatabaseTableConfig<?>> configs =
new ArrayList<DatabaseTableConfig<?>>(Arrays.asList(config1, config2, config3, config4));
DaoManager.addCachedDatabaseConfigs(configs);
assertNotNull(DaoManager.createDao(connectionSource, MoreComplexLoopOne.class));
assertNotNull(DaoManager.createDao(connectionSource, MoreComplexLoopTwo.class));
assertNotNull(DaoManager.createDao(connectionSource, MoreComplexLoopThree.class));
assertNotNull(DaoManager.createDao(connectionSource, MoreComplexLoopFour.class));
}
示例5: getConfigFromClass
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
private DatabaseTableConfig<?> getConfigFromClass(Class<?> clazz) {
try {
return DatabaseTableConfig.fromClass(connectionSource, clazz);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例6: getEntityConfigOfDataSet
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
public <T> DatabaseTableConfig<T> getEntityConfigOfDataSet(ConnectionSource connectionSrc, Class<T> entityClass, String datasetName){
// Create the table config, with a custom table name
DatabaseTableConfig<T> entityConfig = null;
try {
if(entityClass == DataEntity.class){
entityConfig = DatabaseTableConfig.fromClass(connectionSrc, entityClass);
entityConfig.setTableName(datasetName + "_" + DatabaseTableConfig.extractTableName(entityClass));
}
else if(entityClass == UserEntity.class){
entityConfig = DatabaseTableConfig.fromClass(connectionSrc, entityClass);
entityConfig.setTableName(datasetName + "_" + DatabaseTableConfig.extractTableName(entityClass));
}
else if(entityClass == SemanticTagEntity.class){
entityConfig = DatabaseTableConfig.fromClass(connectionSrc, entityClass);
entityConfig.setTableName(datasetName + "_" + DatabaseTableConfig.extractTableName(entityClass));
}
else if(entityClass == QueryEntity.class){
entityConfig = DatabaseTableConfig.fromClass(connectionSrc, entityClass);
entityConfig.setTableName(datasetName + "_" + DatabaseTableConfig.extractTableName(entityClass));
}
else if(entityClass == EvaluationMetricsEntity.class){
entityConfig = DatabaseTableConfig.fromClass(connectionSrc, entityClass);
entityConfig.setTableName(datasetName + "_" + DatabaseTableConfig.extractTableName(entityClass));
}
else if(entityClass == GraphEntity.class){
entityConfig = DatabaseTableConfig.fromClass(connectionSrc, entityClass);
entityConfig.setTableName(datasetName + "_" + DatabaseTableConfig.extractTableName(entityClass));
}
else if(entityClass == ExpertEntity.class){
entityConfig = DatabaseTableConfig.fromClass(connectionSrc, entityClass);
entityConfig.setTableName(datasetName + "_" + DatabaseTableConfig.extractTableName(entityClass));
}
} catch (SQLException e) {
e.printStackTrace();
}
return entityConfig;
}
示例7: initialize
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
/**
* If you are using the Spring type wiring, this should be called after all of the set methods.
*/
public void initialize() throws SQLException {
if (!Boolean.parseBoolean(System.getProperty(AUTO_CREATE_TABLES))) {
return;
}
if (configuredDaos == null) {
throw new SQLException("configuredDaos was not set in " + getClass().getSimpleName());
}
// find all of the daos and create the tables
for (Dao<?, ?> dao : configuredDaos) {
Class<?> clazz = dao.getDataClass();
try {
DatabaseTableConfig<?> tableConfig = null;
if (dao instanceof BaseDaoImpl) {
tableConfig = ((BaseDaoImpl<?, ?>) dao).getTableConfig();
}
if (tableConfig == null) {
tableConfig = DatabaseTableConfig.fromClass(connectionSource, clazz);
}
TableUtils.createTable(connectionSource, tableConfig);
createdClasses.add(tableConfig);
} catch (Exception e) {
// we don't stop because the table might already exist
System.err.println("Was unable to auto-create table for " + clazz);
e.printStackTrace();
}
}
}
示例8: configDao
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
private <T, ID> Dao<T, ID> configDao(BaseDaoImpl<T, ID> dao, boolean createTable) throws Exception {
if (connectionSource == null) {
throw new SQLException(DATASOURCE_ERROR);
}
dao.setConnectionSource(connectionSource);
if (createTable) {
DatabaseTableConfig<T> tableConfig = dao.getTableConfig();
if (tableConfig == null) {
tableConfig = DatabaseTableConfig.fromClass(connectionSource, dao.getDataClass());
}
createTable(tableConfig, true);
}
dao.initialize();
return dao;
}
示例9: onCreate
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(DatabaseHelper.class.getName(), "onCreate");
DatabaseTableConfig<WordWithCachedPlayback> databaseTableConfig = DatabaseTableConfig.fromClass(connectionSource, WordWithCachedPlayback.class);
List<String> statements = TableUtils.getCreateTableStatements(connectionSource, databaseTableConfig);
TableUtils.createTable(connectionSource, WordWithCachedPlayback.class);
TableUtils.createTable(connectionSource, WordGroup.class);
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
}
}
示例10: testTableConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
@Test
public void testTableConfig() throws Exception {
DatabaseTableConfig<Foo> config = DatabaseTableConfig.fromClass(connectionSource, Foo.class);
BaseDaoImpl<Foo, Integer> dao = new BaseDaoImpl<Foo, Integer>(connectionSource, config) {
};
assertSame(config, dao.getTableConfig());
}
示例11: testSetters
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
@Test
public void testSetters() throws Exception {
DatabaseTableConfig<Foo> config = DatabaseTableConfig.fromClass(connectionSource, Foo.class);
BaseDaoImpl<Foo, Integer> dao = new BaseDaoImpl<Foo, Integer>(Foo.class) {
};
dao.setTableConfig(config);
dao.setConnectionSource(connectionSource);
assertSame(config, dao.getTableConfig());
}
示例12: testClassLoopWithLoadedConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
@Test
public void testClassLoopWithLoadedConfig() throws Exception {
DaoManager.clearCache();
DatabaseTableConfig<LoopOne> config1 = DatabaseTableConfig.fromClass(connectionSource, LoopOne.class);
DatabaseTableConfig<LoopTwo> config2 = DatabaseTableConfig.fromClass(connectionSource, LoopTwo.class);
@SuppressWarnings("unchecked")
List<DatabaseTableConfig<?>> configs = new ArrayList<DatabaseTableConfig<?>>(Arrays.asList(config1, config2));
DaoManager.addCachedDatabaseConfigs(configs);
assertNotNull(DaoManager.createDao(connectionSource, LoopOne.class));
assertNotNull(DaoManager.createDao(connectionSource, LoopTwo.class));
}
示例13: configDao
import com.j256.ormlite.table.DatabaseTableConfig; //导入方法依赖的package包/类
private <T, ID> Dao<T, ID> configDao(BaseDaoImpl<T, ID> dao, boolean createTable) throws Exception {
if (connectionSource == null) {
throw new SQLException("Connection source is null");
}
if (createTable) {
DatabaseTableConfig<T> tableConfig = dao.getTableConfig();
if (tableConfig == null) {
tableConfig = DatabaseTableConfig.fromClass(connectionSource, dao.getDataClass());
}
createTable(tableConfig, true);
}
return dao;
}