本文整理汇总了Java中com.j256.ormlite.table.DatabaseTableConfig类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseTableConfig类的具体用法?Java DatabaseTableConfig怎么用?Java DatabaseTableConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseTableConfig类属于com.j256.ormlite.table包,在下文中一共展示了DatabaseTableConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideDAORepo
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
@Provides
@Singleton
public DAORepo provideDAORepo(@NonNull final DatabaseHelperAndroidStarter poDatabaseHelperAndroidStarter) {
try {
final ConnectionSource loConnectionSource = poDatabaseHelperAndroidStarter.getConnectionSource();
final DatabaseTableConfig<RepoEntity> loTableConfig = DatabaseTableConfigUtil.fromClass(loConnectionSource, RepoEntity.class);
if (loTableConfig != null) {
return new DAORepo(loConnectionSource, loTableConfig);
} else {
return new DAORepo(loConnectionSource);
}
} catch (final SQLException loException) {
if (BuildConfig.DEBUG && DEBUG) {
Logger.t(TAG).e(loException, "");
}
}
return null;
}
示例2: getDao
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
/**
* This method obtains a DAO given its Class
* <p/>
* Source: https://goo.gl/6LIYy2
*
* @param clazz
* The DAO class
* @param <D>
* DAO super class
* @param <T>
* Requested DAO class
*
* @return The DAO instance
*
* @throws SQLException
*/
public <D extends Dao<T, ?>, T> D getDao(Class<T> clazz) throws SQLException {
// lookup the dao, possibly invoking the cached database config
Dao<T, ?> dao = DaoManager.lookupDao(connectionSource, clazz);
if (dao == null) {
// try to use our new reflection magic
DatabaseTableConfig<T> tableConfig = DatabaseTableConfigUtil
.fromClass(connectionSource, clazz);
if (tableConfig == null) {
/**
* Note: We have to do this to get to see if they are using the deprecated
* annotations like
* {@link DatabaseFieldSimple}.
*/
dao = (Dao<T, ?>) DaoManager.createDao(connectionSource, clazz);
} else {
dao = (Dao<T, ?>) DaoManager.createDao(connectionSource, tableConfig);
}
}
@SuppressWarnings("unchecked")
D castDao = (D) dao;
return castDao;
}
示例3: DatabaseFieldConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
public DatabaseFieldConfig(String paramString1, String paramString2, DataType paramDataType, String paramString3, int paramInt1, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, String paramString4, boolean paramBoolean4, DatabaseTableConfig<?> paramDatabaseTableConfig, boolean paramBoolean5, Enum<?> paramEnum, boolean paramBoolean6, String paramString5, boolean paramBoolean7, String paramString6, String paramString7, boolean paramBoolean8, int paramInt2, int paramInt3)
{
this.fieldName = paramString1;
this.columnName = paramString2;
this.dataType = DataType.UNKNOWN;
this.defaultValue = paramString3;
this.width = paramInt1;
this.canBeNull = paramBoolean1;
this.id = paramBoolean2;
this.generatedId = paramBoolean3;
this.generatedIdSequence = paramString4;
this.foreign = paramBoolean4;
this.foreignTableConfig = paramDatabaseTableConfig;
this.useGetSet = paramBoolean5;
this.unknownEnumValue = paramEnum;
this.throwIfNull = paramBoolean6;
this.format = paramString5;
this.unique = paramBoolean7;
this.indexName = paramString6;
this.uniqueIndexName = paramString7;
this.foreignAutoRefresh = paramBoolean8;
this.maxForeignAutoRefreshLevel = paramInt2;
this.foreignCollectionMaxEagerLevel = paramInt3;
}
示例4: fromClass
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
public static <T> DatabaseTableConfig<T> fromClass(ConnectionSource paramConnectionSource, Class<T> paramClass)
{
DatabaseType localDatabaseType = paramConnectionSource.getDatabaseType();
String str = DatabaseTableConfig.extractTableName(paramClass);
ArrayList localArrayList = new ArrayList();
for (Object localObject = paramClass; localObject != null; localObject = ((Class)localObject).getSuperclass())
{
Field[] arrayOfField = ((Class)localObject).getDeclaredFields();
int i = arrayOfField.length;
for (int j = 0; j < i; j++)
{
DatabaseFieldConfig localDatabaseFieldConfig = configFromField(localDatabaseType, str, arrayOfField[j]);
if ((localDatabaseFieldConfig != null) && (localDatabaseFieldConfig.isPersisted()))
localArrayList.add(localDatabaseFieldConfig);
}
}
if (localArrayList.size() == 0)
return null;
return new DatabaseTableConfig(paramClass, str, localArrayList);
}
示例5: getIdFieldName
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected String getIdFieldName(SQLiteMatcherEntry entry) {
OrmLiteMatcherEntry ormliteEntry = (OrmLiteMatcherEntry)entry;
if (ormliteEntry.getClazz() == null) {
throw new IllegalStateException("In order to use ITEM type you should fill in class");
}
try {
DatabaseTableConfig config = getDatabaseTableConfig(ormliteEntry.getClazz());
FieldType[] fieldTypes = config.getFieldTypes(mDatabaseHelper.getConnectionSource().getDatabaseType());
FieldType idFieldType = null;
for (FieldType fieldType : fieldTypes) {
if(fieldType.isId() || fieldType.isGeneratedId() || fieldType.isGeneratedIdSequence()) {
idFieldType = fieldType;
}
}
if (idFieldType == null) {
throw new IllegalStateException("Cannot find id field");
}
return idFieldType.getColumnName();
} catch (SQLException ex) {
Log.e(TAG, "Cannot get id field", ex);
throw new IllegalStateException("Cannot find id field");
}
}
示例6: 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;
}
示例7: getColumnNames
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
public <T extends BaseData> String[] getColumnNames(Class<T> clazz,
boolean foreignOnly) {
List<String> columnNames = new ArrayList<String>();
try {
DatabaseTableConfig<? extends BaseData> cfg = getTableConfig(clazz);
SqliteAndroidDatabaseType dbType = new SqliteAndroidDatabaseType();
for (FieldType fieldType : cfg.getFieldTypes(dbType)) {
if (!foreignOnly || fieldType.isForeign()) {
columnNames.add(fieldType.getColumnName());
}
}
} catch (java.sql.SQLException e) {
throw new android.database.SQLException(e.getMessage());
}
return columnNames.toArray(new String[]{});
}
示例8: fromClass
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
/**
* Build our list table config from a class using some annotation fu around.
*/
public static <T> DatabaseTableConfig<T> fromClass(ConnectionSource connectionSource, Class<T> clazz)
throws SQLException {
DatabaseType databaseType = connectionSource.getDatabaseType();
String tableName = DatabaseTableConfig.extractTableName(clazz);
List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
for (Class<?> classWalk = clazz; classWalk != null; classWalk = classWalk.getSuperclass()) {
for (Field field : classWalk.getDeclaredFields()) {
DatabaseFieldConfig config = configFromField(databaseType, tableName, field);
if (config != null && config.isPersisted()) {
fieldConfigs.add(config);
}
}
}
if (fieldConfigs.size() == 0) {
return null;
} else {
return new DatabaseTableConfig<T>(clazz, tableName, fieldConfigs);
}
}
示例9: testFieldConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
@Test
public void testFieldConfig() throws Exception {
List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
fieldConfigs.add(new DatabaseFieldConfig("id", "id2", DataType.UNKNOWN, null, 0, false, false, true, null,
false, null, false, null, false, null, false, null, null, false, -1, 0));
fieldConfigs.add(new DatabaseFieldConfig("stuff", "stuffy", DataType.UNKNOWN, null, 0, false, false, false,
null, false, null, false, null, false, null, false, null, null, false, -1, 0));
DatabaseTableConfig<NoAnno> tableConfig = new DatabaseTableConfig<NoAnno>(NoAnno.class, "noanno", fieldConfigs);
Dao<NoAnno, Integer> noAnnotaionDao = createDao(tableConfig, true);
NoAnno noa = new NoAnno();
String stuff = "qpoqwpjoqwp12";
noa.stuff = stuff;
assertEquals(1, noAnnotaionDao.create(noa));
NoAnno noa2 = noAnnotaionDao.queryForId(noa.id);
assertEquals(noa.id, noa2.id);
assertEquals(stuff, noa2.stuff);
}
示例10: createTable
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
private void createTable(SQLiteDatabase db,ConnectionSource connectionSource) {
try {
Log.d("DataHelper", "create database");
InputStream is = this.context.getResources().openRawResource(
R.raw.ormlite_config);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr, 4096);
List<DatabaseTableConfig<?>> tableConfigs = DatabaseTableConfigLoader
.loadDatabaseConfigFromReader(reader);
for (DatabaseTableConfig<?> databaseTableConfig : tableConfigs) {
TableUtils.createTableIfNotExists(connectionSource,
databaseTableConfig);
}
is.close();
isr.close();
reader.close();
} catch (Exception e) {
Log.e(DataHelper.class.getName(), "创建数据库失败" + e.getCause());
e.printStackTrace();
}
}
示例11: updateTable
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
private void updateTable(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.d("DataHelper", "Update Database");
InputStream is = this.context.getResources().openRawResource(
R.raw.ormlite_config);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr, 4096);
List<DatabaseTableConfig<?>> tableConfigs = DatabaseTableConfigLoader
.loadDatabaseConfigFromReader(reader);
for (DatabaseTableConfig<?> databaseTableConfig : tableConfigs) {
TableUtils.dropTable(connectionSource, databaseTableConfig,
true);
}
is.close();
isr.close();
reader.close();
onCreate(db, connectionSource);
} catch (Exception e) {
Log.e(DataHelper.class.getName(), "更新数据库失败" + e.getMessage());
e.printStackTrace();
}
}
示例12: 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());
}
示例13: tearDown
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
@Override
public void tearDown() throws Exception {
super.tearDown();
if (connectionSource != null) {
for (Class<?> clazz : dropClassSet) {
dropTable(clazz, true);
}
for (DatabaseTableConfig<?> tableConfig : dropTableConfigSet) {
dropTable(tableConfig, true);
}
}
closeConnectionSource();
if (helper != null) {
helper.close();
}
}
示例14: testFieldConfig
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
public void testFieldConfig() throws Exception {
List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
fieldConfigs.add(new DatabaseFieldConfig("id", "id2", DataType.UNKNOWN, null, 0, false, false, true, null,
false, null, false, null, false, null, false, null, null, false, -1, 0));
fieldConfigs.add(new DatabaseFieldConfig("stuff", "stuffy", DataType.UNKNOWN, null, 0, false, false, false,
null, false, null, false, null, false, null, false, null, null, false, -1, 0));
DatabaseTableConfig<NoAnno> tableConfig = new DatabaseTableConfig<NoAnno>(NoAnno.class, "noanno", fieldConfigs);
Dao<NoAnno, Integer> noAnnotaionDao = createDao(tableConfig, true);
NoAnno noa = new NoAnno();
String stuff = "qpoqwpjoqwp12";
noa.stuff = stuff;
assertEquals(1, noAnnotaionDao.create(noa));
NoAnno noa2 = noAnnotaionDao.queryForId(noa.id);
assertEquals(noa.id, noa2.id);
assertEquals(stuff, noa2.stuff);
}
示例15: lookupDao
import com.j256.ormlite.table.DatabaseTableConfig; //导入依赖的package包/类
/**
* Helper method to lookup a DAO if it has already been associated with the table-config. Otherwise this returns
* null.
*/
public synchronized static <D extends Dao<T, ?>, T> D lookupDao(ConnectionSource connectionSource,
DatabaseTableConfig<T> tableConfig) {
if (connectionSource == null) {
throw new IllegalArgumentException("connectionSource argument cannot be null");
}
TableConfigConnectionSource key = new TableConfigConnectionSource(connectionSource, tableConfig);
Dao<?, ?> dao = lookupDao(key);
if (dao == null) {
return null;
} else {
@SuppressWarnings("unchecked")
D castDao = (D) dao;
return castDao;
}
}