本文整理汇总了Java中com.j256.ormlite.field.DataType类的典型用法代码示例。如果您正苦于以下问题:Java DataType类的具体用法?Java DataType怎么用?Java DataType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataType类属于com.j256.ormlite.field包,在下文中一共展示了DataType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryRaw
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
public GenericRawResults<Object[]> queryRaw(ConnectionSource paramConnectionSource, String paramString, DataType[] paramArrayOfDataType, String[] paramArrayOfString, ObjectCache paramObjectCache)
{
logger.debug("executing raw query for: {}", paramString);
if (paramArrayOfString.length > 0)
logger.trace("query arguments: {}", paramArrayOfString);
DatabaseConnection localDatabaseConnection = paramConnectionSource.getReadOnlyConnection();
CompiledStatement localCompiledStatement = null;
try
{
localCompiledStatement = localDatabaseConnection.compileStatement(paramString, StatementBuilder.StatementType.SELECT, noFieldTypes);
assignStatementArguments(localCompiledStatement, paramArrayOfString);
ObjectArrayRowMapper localObjectArrayRowMapper = new ObjectArrayRowMapper(paramArrayOfDataType);
RawResultsImpl localRawResultsImpl = new RawResultsImpl(paramConnectionSource, localDatabaseConnection, paramString, [Ljava.lang.Object.class, localCompiledStatement, localObjectArrayRowMapper, paramObjectCache);
return localRawResultsImpl;
}
finally
{
if (localCompiledStatement != null)
localCompiledStatement.close();
if (localDatabaseConnection != null)
paramConnectionSource.releaseConnection(localDatabaseConnection);
}
}
示例2: getFieldConverter
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Override
public FieldConverter getFieldConverter(DataPersister dataPersister, FieldType fieldType) {
switch (dataPersister.getSqlType()) {
case BOOLEAN :
/*
* Booleans in Oracle are stored as the character '1' or '0'. You can change the characters by
* specifying a format string. It must be a string with 2 characters. The first character is the value
* for TRUE, the second is FALSE. See {@link BooleanCharType}.
*
* You can also specify the format as "integer" to use an integer column type and the value 1 (really
* non-0) for true and 0 for false. See {@link BooleanIntegerType}.
*/
if (BOOLEAN_INTEGER_FORMAT.equalsIgnoreCase(fieldType.getFormat())) {
return DataType.BOOLEAN_INTEGER.getDataPersister();
} else {
return DataType.BOOLEAN_CHAR.getDataPersister();
}
default :
return super.getFieldConverter(dataPersister, fieldType);
}
}
示例3: testFieldConfig
import com.j256.ormlite.field.DataType; //导入依赖的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);
}
示例4: queryRaw
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
/**
* Return a results object associated with an internal iterator is mapped by the user's rowMapper.
*/
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
RawRowObjectMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache) throws SQLException {
logger.debug("executing raw query for: {}", query);
if (arguments.length > 0) {
// need to do the (Object) cast to force args to be a single object
logger.trace("query arguments: {}", (Object) arguments);
}
DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
CompiledStatement compiledStatement = null;
try {
compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
assignStatementArguments(compiledStatement, arguments);
RawResultsImpl<UO> rawResults = new RawResultsImpl<UO>(connectionSource, connection, query, String[].class,
compiledStatement, new UserRawRowObjectMapper<UO>(rowMapper, columnTypes), objectCache);
compiledStatement = null;
connection = null;
return rawResults;
} finally {
IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
if (connection != null) {
connectionSource.releaseConnection(connection);
}
}
}
示例5: testRawResultsObjectMapper
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Test
public void testRawResultsObjectMapper() throws Exception {
Dao<Foo, Object> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
foo1.val = 12321;
foo1.stringField = "fjpojefpwoewfjpewf";
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
foo2.val = 754282321;
foo2.stringField = "foewjfewpfjwe";
assertEquals(1, dao.create(foo2));
QueryBuilder<Foo, Object> qb = dao.queryBuilder();
qb.selectColumns(Foo.ID_COLUMN_NAME, Foo.VAL_COLUMN_NAME, Foo.STRING_COLUMN_NAME);
GenericRawResults<Foo> rawResults =
dao.queryRaw(qb.prepareStatementString(), new DataType[] { DataType.INTEGER, DataType.INTEGER,
DataType.STRING }, new FooObjectArrayMapper());
List<Foo> results = rawResults.getResults();
assertEquals(2, results.size());
assertEquals(foo1.id, results.get(0).id);
assertEquals(foo1.val, results.get(0).val);
assertEquals(foo1.stringField, results.get(0).stringField);
assertEquals(foo2.id, results.get(1).id);
assertEquals(foo2.val, results.get(1).val);
assertEquals(foo2.stringField, results.get(1).stringField);
}
示例6: testEnumStringResultsNoFieldType
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Test
public void testEnumStringResultsNoFieldType() throws Exception {
Dao<LocalEnumString, Object> dao = createDao(LocalEnumString.class, true);
OurEnum val = OurEnum.SECOND;
LocalEnumString foo = new LocalEnumString();
foo.ourEnum = val;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
assertEquals(val.toString(), DataType.ENUM_STRING.getDataPersister().resultToJava(null, results,
results.findColumn(ENUM_COLUMN)));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
示例7: testSerializableInvalidResult
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void testSerializableInvalidResult() throws Exception {
Class<LocalByteArray> clazz = LocalByteArray.class;
Dao<LocalByteArray, Object> dao = createDao(clazz, true);
LocalByteArray foo = new LocalByteArray();
foo.byteField = new byte[] { 1, 2, 3, 4, 5 };
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
FieldType fieldType = FieldType.createFieldType(connectionSource, TABLE_NAME,
LocalSerializable.class.getDeclaredField(SERIALIZABLE_COLUMN), LocalSerializable.class);
DataType.SERIALIZABLE.getDataPersister().resultToJava(fieldType, results, results.findColumn(BYTE_COLUMN));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
示例8: testDate
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Test
public void testDate() throws Exception {
Class<LocalDate> clazz = LocalDate.class;
Dao<LocalDate, Object> dao = createDao(clazz, true);
// we have to round to 0 millis
long millis = System.currentTimeMillis();
millis -= millis % 1000;
java.util.Date val = new java.util.Date(millis);
String format = "yyyy-MM-dd HH:mm:ss.SSSSSS";
DateFormat dateFormat = new SimpleDateFormat(format);
String valStr = dateFormat.format(val);
LocalDate foo = new LocalDate();
foo.date = val;
assertEquals(1, dao.create(foo));
Timestamp timestamp = new Timestamp(val.getTime());
testType(dao, foo, clazz, val, timestamp, timestamp, valStr, DataType.DATE, DATE_COLUMN, false, true, true,
false, true, false, true, false);
}
示例9: testDateStringResultInvalid
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void testDateStringResultInvalid() throws Exception {
Class<LocalString> clazz = LocalString.class;
Dao<LocalString, Object> dao = createDao(clazz, true);
LocalString foo = new LocalString();
foo.string = "not a date format";
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
int colNum = results.findColumn(STRING_COLUMN);
DataType.DATE_STRING.getDataPersister().resultToJava(null, results, colNum);
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
示例10: testSetFieldConfigs
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Test
public void testSetFieldConfigs() throws SQLException {
DatabaseTableConfig<DatabaseTableAnno> dbTableConf = new DatabaseTableConfig<DatabaseTableAnno>();
dbTableConf.setDataClass(DatabaseTableAnno.class);
dbTableConf.setTableName(TABLE_NAME);
List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
fieldConfigs.add(new DatabaseFieldConfig("stuff", null, DataType.UNKNOWN, "", 0, true, false, false, null,
false, null, false, null, false, null, false, null, null, false,
DatabaseFieldConfig.NO_MAX_FOREIGN_AUTO_REFRESH_LEVEL_SPECIFIED, 0));
dbTableConf.setFieldConfigs(fieldConfigs);
dbTableConf.initialize();
assertEquals(DatabaseTableAnno.class, dbTableConf.getDataClass());
assertEquals(TABLE_NAME, dbTableConf.getTableName());
dbTableConf.extractFieldTypes(connectionSource);
FieldType[] fieldTypes = dbTableConf.getFieldTypes(databaseType);
assertEquals(1, fieldTypes.length);
assertEquals("stuff", fieldTypes[0].getColumnName());
}
示例11: testEnumIntResultsNoFieldType
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
@Test
public void testEnumIntResultsNoFieldType() throws Exception {
Class<LocalEnumInt> clazz = LocalEnumInt.class;
Dao<LocalEnumInt, Object> dao = createDao(clazz, true);
OurEnum val = OurEnum.SECOND;
LocalEnumInt foo = new LocalEnumInt();
foo.ourEnum = val;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
assertEquals(val.ordinal(), DataType.ENUM_INTEGER.getDataPersister().resultToJava(null, results,
results.findColumn(ENUM_COLUMN)));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
示例12: fetchCards
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
/**
* Retrieves all the cards from a deck having the given tags.
* @param deckId the id of the deck to pull the cards from
* @param tags the tags that the cards must have
* @return a list of cards.
*/
ArrayList<CardReference> fetchCards(long deckId, String tags) throws SQLException {
String query =
"SELECT C.id, N.mid, C.ord, N.flds " +
"FROM cards C " +
" JOIN notes N " +
" ON C.nid = N.id " +
"WHERE C.did = ? AND N.tags = ? ";
DataType[] columnTypes = {LONG, LONG, INTEGER, STRING};
String[] params = {String.valueOf(deckId), tags};
return Lists.newArrayList(cardsDAO.queryRaw(query, columnTypes, getCardRawRowObjectMapper(), params));
}
示例13: mapRow
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
public Object[] mapRow(DatabaseResults paramDatabaseResults)
{
int i = paramDatabaseResults.getColumnCount();
Object[] arrayOfObject = new Object[i];
for (int j = 0; j < i; j++)
{
DataType localDataType;
if (j >= this.columnTypes.length)
localDataType = DataType.STRING;
else
localDataType = this.columnTypes[j];
arrayOfObject[j] = localDataType.getDataPersister().resultToJava(null, paramDatabaseResults, j);
}
return arrayOfObject;
}
示例14: queryRaw
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
public GenericRawResults<Object[]> queryRaw(String paramString, DataType[] paramArrayOfDataType, String[] paramArrayOfString)
{
checkForInitialized();
try
{
GenericRawResults localGenericRawResults = this.statementExecutor.queryRaw(this.connectionSource, paramString, paramArrayOfDataType, paramArrayOfString, this.objectCache);
return localGenericRawResults;
}
catch (SQLException localSQLException)
{
throw SqlExceptionUtil.create("Could not perform raw query for " + paramString, localSQLException);
}
}
示例15: queryRaw
import com.j256.ormlite.field.DataType; //导入依赖的package包/类
public GenericRawResults<Object[]> queryRaw(String paramString, DataType[] paramArrayOfDataType, String[] paramArrayOfString)
{
try
{
GenericRawResults localGenericRawResults = this.dao.queryRaw(paramString, paramArrayOfDataType, paramArrayOfString);
return localGenericRawResults;
}
catch (SQLException localSQLException)
{
logMessage(localSQLException, "queryRaw threw exception on: " + paramString);
throw new RuntimeException(localSQLException);
}
}