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


Java DataType類代碼示例

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

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

示例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);
}
 
開發者ID:j256,項目名稱:ormlite-jdbc,代碼行數:18,代碼來源:JdbcBaseDaoImplTest.java

示例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);
		}
	}
}
 
開發者ID:j256,項目名稱:ormlite-core,代碼行數:29,代碼來源:StatementExecutor.java

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

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

示例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);
	}
}
 
開發者ID:j256,項目名稱:ormlite-core,代碼行數:25,代碼來源:SerializableTypeTest.java

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

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

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

示例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);
	}
}
 
開發者ID:j256,項目名稱:ormlite-core,代碼行數:25,代碼來源:EnumIntegerTypeTest.java

示例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));
}
 
開發者ID:slavetto,項目名稱:anki-cards-web-browser,代碼行數:20,代碼來源:AnkiDatabase.java

示例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;
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:16,代碼來源:StatementExecutor.java

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

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


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