Java Code Examples for com.j256.ormlite.field.DataType

The following examples show how to use com.j256.ormlite.field.DataType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ormlite-jdbc   Source File: OracleDatabaseType.java    License: ISC License 6 votes vote down vote up
@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);
	}
}
 
Example 2
Source Project: ormlite-jdbc   Source File: JdbcBaseDaoImplTest.java    License: ISC License 6 votes vote down vote up
@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);
}
 
Example 3
Source Project: ormlite-core   Source File: StatementExecutor.java    License: ISC License 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 4
Source Project: ormlite-core   Source File: StatementExecutor.java    License: ISC License 6 votes vote down vote up
/**
 * Return a results object associated with an internal iterator that returns Object[] results.
 */
public GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
		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<Object[]> rawResults = new RawResultsImpl<Object[]>(connectionSource, connection, query,
				Object[].class, compiledStatement, new ObjectArrayRowMapper(columnTypes), objectCache);
		compiledStatement = null;
		connection = null;
		return rawResults;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
Example 5
Source Project: ormlite-core   Source File: EnumStringTypeTest.java    License: ISC License 6 votes vote down vote up
@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);
	}
}
 
Example 6
Source Project: ormlite-core   Source File: RawRowObjectMapperTest.java    License: ISC License 6 votes vote down vote up
@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);
}
 
Example 7
Source Project: ormlite-core   Source File: SerializableTypeTest.java    License: ISC License 6 votes vote down vote up
@Test
public void testSerializable() throws Exception {
	Class<LocalSerializable> clazz = LocalSerializable.class;
	Dao<LocalSerializable, Object> dao = createDao(clazz, true);
	Integer val = 1331333131;
	ByteArrayOutputStream outStream = new ByteArrayOutputStream();
	ObjectOutputStream objOutStream = new ObjectOutputStream(outStream);
	objOutStream.writeObject(val);
	byte[] sqlArg = outStream.toByteArray();
	String valStr = val.toString();
	LocalSerializable foo = new LocalSerializable();
	foo.serializable = val;
	assertEquals(1, dao.create(foo));
	testType(dao, foo, clazz, val, sqlArg, sqlArg, valStr, DataType.SERIALIZABLE, SERIALIZABLE_COLUMN, false, false,
			true, false, true, true, false, false);
}
 
Example 8
Source Project: ormlite-core   Source File: SerializableTypeTest.java    License: ISC License 6 votes vote down vote up
@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(databaseType, 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);
	}
}
 
Example 9
Source Project: ormlite-core   Source File: DateTypeTest.java    License: ISC License 6 votes vote down vote up
@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);
}
 
Example 10
Source Project: ormlite-core   Source File: DateStringTypeTest.java    License: ISC License 6 votes vote down vote up
@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);
	}
}
 
Example 11
Source Project: ormlite-core   Source File: EnumIntegerTypeTest.java    License: ISC License 6 votes vote down vote up
@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);
	}
}
 
Example 12
Source Project: ormlite-core   Source File: ByteArrayTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testByteArray() throws Exception {
	Class<LocalByteArray> clazz = LocalByteArray.class;
	Dao<LocalByteArray, Object> dao = createDao(clazz, true);
	byte[] val = new byte[] { 123, 4, 124, 1, 0, 72 };
	String valStr = new String(val);
	LocalByteArray foo = new LocalByteArray();
	foo.byteField = val;
	assertEquals(1, dao.create(foo));
	testType(dao, foo, clazz, val, val, val, valStr, DataType.BYTE_ARRAY, BYTE_COLUMN, false, true, true, false,
			true, false, true, false);
}
 
Example 13
Source Project: ormlite-core   Source File: LongObjectTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testLongObjNull() throws Exception {
	Class<LocalLongObj> clazz = LocalLongObj.class;
	Dao<LocalLongObj, Object> dao = createDao(clazz, true);
	LocalLongObj foo = new LocalLongObj();
	assertEquals(1, dao.create(foo));
	testType(dao, foo, clazz, null, null, null, null, DataType.LONG_OBJ, LONG_COLUMN, true, true, false, false,
			false, false, true, true);
}
 
Example 14
Source Project: ormlite-jdbc   Source File: DerbyEmbeddedDatabaseTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testObjectFieldConverterJavaToArg() throws Exception {
	DerbyEmbeddedDatabaseType type = new DerbyEmbeddedDatabaseType();
	FieldConverter converter = type.getFieldConverter(DataType.SERIALIZABLE.getDataPersister(), null);
	Object object = converter.javaToSqlArg(null, "TEST");
	assertEquals(SerialBlob.class, object.getClass());
}
 
Example 15
Source Project: ormlite-jdbc   Source File: DerbyEmbeddedDatabaseTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testObjectFieldConverterResultToJavaStreamNull() throws Exception {
	int COLUMN = 1;
	DatabaseResults results = (DatabaseResults) createMock(DatabaseResults.class);
	expect(results.getBlobStream(COLUMN)).andReturn(null);
	replay(results);
	DerbyEmbeddedDatabaseType type = new DerbyEmbeddedDatabaseType();
	FieldConverter converter = type.getFieldConverter(DataType.SERIALIZABLE.getDataPersister(), null);
	assertEquals(null, converter.resultToJava(null, results, COLUMN));
	verify(results);
}
 
Example 16
Source Project: ormlite-jdbc   Source File: DerbyEmbeddedDatabaseTypeTest.java    License: ISC License 5 votes vote down vote up
@Test(expected = SQLException.class)
public void testObjectFieldConverterResultToJavaStreamNotObject() throws Exception {
	int COLUMN = 1;
	DatabaseResults results = (DatabaseResults) createMock(DatabaseResults.class);
	String value = "NotASerializedObject";
	expect(results.getBlobStream(COLUMN)).andReturn(new ByteArrayInputStream(value.getBytes()));
	replay(results);
	DerbyEmbeddedDatabaseType type = new DerbyEmbeddedDatabaseType();
	FieldConverter converter = type.getFieldConverter(DataType.SERIALIZABLE.getDataPersister(), null);
	Object obj = converter.resultToJava(null, results, COLUMN);
	verify(results);
	assertEquals(value, obj);
}
 
Example 17
Source Project: ormlite-core   Source File: ShortObjectTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testShortObj() throws Exception {
	Class<LocalShortObj> clazz = LocalShortObj.class;
	Dao<LocalShortObj, Object> dao = createDao(clazz, true);
	Short val = 12312;
	String valStr = val.toString();
	LocalShortObj foo = new LocalShortObj();
	foo.shortField = val;
	assertEquals(1, dao.create(foo));
	testType(dao, foo, clazz, val, val, val, valStr, DataType.SHORT_OBJ, SHORT_COLUMN, false, true, false, false,
			false, false, true, true);
}
 
Example 18
Source Project: ormlite-core   Source File: BaseDaoImpl.java    License: ISC License 5 votes vote down vote up
@Override
public <UO> GenericRawResults<UO> queryRaw(String query, DataType[] columnTypes, RawRowObjectMapper<UO> mapper,
		String... arguments) throws SQLException {
	checkForInitialized();
	try {
		return statementExecutor.queryRaw(connectionSource, query, columnTypes, mapper, arguments, objectCache);
	} catch (SQLException e) {
		throw SqlExceptionUtil.create("Could not perform raw query for " + query, e);
	}
}
 
Example 19
Source Project: ormlite-core   Source File: BaseDaoImpl.java    License: ISC License 5 votes vote down vote up
@Override
public GenericRawResults<Object[]> queryRaw(String query, DataType[] columnTypes, String... arguments)
		throws SQLException {
	checkForInitialized();
	try {
		return statementExecutor.queryRaw(connectionSource, query, columnTypes, arguments, objectCache);
	} catch (SQLException e) {
		throw SqlExceptionUtil.create("Could not perform raw query for " + query, e);
	}
}
 
Example 20
Source Project: ormlite-core   Source File: DoubleTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testDouble() throws Exception {
	Class<LocalDouble> clazz = LocalDouble.class;
	Dao<LocalDouble, Object> dao = createDao(clazz, true);
	double val = 13313323131.221;
	String valStr = Double.toString(val);
	LocalDouble foo = new LocalDouble();
	foo.doubleField = val;
	assertEquals(1, dao.create(foo));
	testType(dao, foo, clazz, val, val, val, valStr, DataType.DOUBLE, DOUBLE_COLUMN, false, true, false, true,
			false, false, true, false);
}
 
Example 21
Source Project: ormlite-core   Source File: RuntimeExceptionDao.java    License: ISC License 5 votes vote down vote up
/**
 * @see Dao#queryRaw(String, DataType[], String...)
 */
@Override
public GenericRawResults<Object[]> queryRaw(String query, DataType[] columnTypes, String... arguments) {
	try {
		return dao.queryRaw(query, columnTypes, arguments);
	} catch (SQLException e) {
		logMessage(e, "queryRaw threw exception on: " + query);
		throw new RuntimeException(e);
	}
}
 
Example 22
Source Project: ormlite-core   Source File: RuntimeExceptionDaoTest.java    License: ISC License 5 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testQueryRawDateTypesThrow() throws Exception {
	@SuppressWarnings("unchecked")
	Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
	RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
	expect(dao.queryRaw(null, (DataType[]) null)).andThrow(new SQLException("Testing catch"));
	replay(dao);
	rtDao.queryRaw(null, (DataType[]) null);
	verify(dao);
}
 
Example 23
Source Project: ormlite-core   Source File: BaseDaoImplTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testQueryRawObjects() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	int equal1 = 1231231232;
	foo1.equal = equal1;
	assertEquals(1, dao.create(foo1));
	Foo foo2 = new Foo();
	int equal2 = 1231232;
	foo2.equal = equal2;
	assertEquals(1, dao.create(foo2));

	QueryBuilder<Foo, Integer> queryBuilder = dao.queryBuilder();
	queryBuilder.where().eq(Foo.ID_COLUMN_NAME, foo1.id);

	GenericRawResults<Object[]> results =
			dao.queryRaw("SELECT " + Foo.ID_COLUMN_NAME + "," + Foo.EQUAL_COLUMN_NAME + " FROM FOO",
					new DataType[] { DataType.STRING, DataType.INTEGER });
	List<Object[]> resultList = results.getResults();
	assertEquals(2, resultList.size());
	Object[] row = resultList.get(0);
	assertEquals(2, row.length);
	assertEquals(Integer.toString(foo1.id), row[0]);
	assertEquals(foo1.equal, row[1]);
	row = resultList.get(1);
	assertEquals(2, row.length);
	assertEquals(Integer.toString(foo2.id), row[0]);
	assertEquals(foo2.equal, row[1]);
}
 
Example 24
Source Project: ormlite-core   Source File: BaseDaoImplTest.java    License: ISC License 5 votes vote down vote up
@Test(expected = SQLException.class)
public void testQueryRawObjectsThrow() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo = new Foo();
	assertEquals(1, dao.create(foo));
	DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
	try {
		conn.close();
		dao.queryRaw("SELECT * FROM FOO", new DataType[0]);
	} finally {
		connectionSource.releaseConnection(conn);
	}
}
 
Example 25
Source Project: ormlite-core   Source File: BaseDaoImplTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testQueryRawObjectsArguments() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	int equal1 = 1231231232;
	foo1.equal = equal1;
	assertEquals(1, dao.create(foo1));
	Foo foo2 = new Foo();
	int equal2 = 1231232;
	foo2.equal = equal2;
	assertEquals(1, dao.create(foo2));

	QueryBuilder<Foo, Integer> queryBuilder = dao.queryBuilder();
	queryBuilder.where().eq(Foo.ID_COLUMN_NAME, foo1.id);

	GenericRawResults<Object[]> results =
			dao.queryRaw(
					"SELECT " + Foo.ID_COLUMN_NAME + "," + Foo.EQUAL_COLUMN_NAME + " FROM FOO WHERE "
							+ Foo.ID_COLUMN_NAME + " = ?",
					new DataType[] { DataType.STRING, DataType.INTEGER }, Integer.toString(foo2.id));
	List<Object[]> resultList = results.getResults();
	assertEquals(1, resultList.size());
	Object[] row = resultList.get(0);
	assertEquals(2, row.length);
	assertEquals(Integer.toString(foo2.id), row[0]);
	assertEquals(foo2.equal, row[1]);
}
 
Example 26
Source Project: ormlite-core   Source File: RawRowObjectMapperTest.java    License: ISC License 5 votes vote down vote up
@Override
public Foo mapRow(String[] columnNames, DataType[] dataTypes, Object[] resultColumns) {
	// may be more than 1 because of the id
	assertTrue(resultColumns.length >= 2);
	// id is added at the end always
	Foo foo = new Foo();
	foo.id = (Integer) resultColumns[0];
	foo.val = (Integer) resultColumns[1];
	foo.stringField = (String) resultColumns[2];
	// other fields could be converted here
	return foo;
}
 
Example 27
Source Project: ormlite-core   Source File: DaoManagerTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testCreateClass() throws Exception {
	testClass(Foo.class);
	DatabaseTableConfig<Foo> tableConfig = new DatabaseTableConfig<Foo>(databaseType, Foo.class,
			Arrays.asList(new DatabaseFieldConfig("id", null, DataType.UNKNOWN, null, 0, false, false, false, null,
					false, null, false, null, false, null, false, null, null, false,
					DatabaseFieldConfig.NO_MAX_FOREIGN_AUTO_REFRESH_LEVEL_SPECIFIED, 0)));
	testTable(tableConfig);
}
 
Example 28
Source Project: ormlite-core   Source File: BigDecimalNumericTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testBigDecimal() throws Exception {
	Class<LocalBigDecimalNumeric> clazz = LocalBigDecimalNumeric.class;
	Dao<LocalBigDecimalNumeric, Object> dao = createDao(clazz, true);
	BigDecimal val = new BigDecimal("1.345345435345345345345345345345345345345345346356524234234");
	String valStr = val.toString();
	LocalBigDecimalNumeric foo = new LocalBigDecimalNumeric();
	foo.bigDecimal = val;
	assertEquals(1, dao.create(foo));
	testType(dao, foo, clazz, val, val, val, valStr, DataType.BIG_DECIMAL_NUMERIC, BIGDECIMAL_COLUMN, false, false,
			false, false, false, false, true, false);
}
 
Example 29
Source Project: ormlite-core   Source File: EnumStringTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testEnumString() throws Exception {
	Class<LocalEnumString> clazz = LocalEnumString.class;
	Dao<LocalEnumString, Object> dao = createDao(clazz, true);
	OurEnum val = OurEnum.SECOND;
	String valStr = val.toString();
	String sqlVal = valStr;
	LocalEnumString foo = new LocalEnumString();
	foo.ourEnum = val;
	assertEquals(1, dao.create(foo));
	testType(dao, foo, clazz, val, sqlVal, sqlVal, valStr, DataType.ENUM_STRING, ENUM_COLUMN, false, true, true,
			false, false, false, true, false);
}
 
Example 30
Source Project: ormlite-core   Source File: DaoManagerTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testDaoClassDifferentDao() throws Exception {
	testClass(Baz.class);
	DatabaseTableConfig<Baz> tableConfig = new DatabaseTableConfig<Baz>(databaseType, Baz.class,
			Arrays.asList(new DatabaseFieldConfig("foo", null, DataType.UNKNOWN, null, 0, false, false, false, null,
					false, null, false, null, false, null, false, null, null, false,
					DatabaseFieldConfig.NO_MAX_FOREIGN_AUTO_REFRESH_LEVEL_SPECIFIED, 0)));
	testTable(tableConfig);
}