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

The following examples show how to use com.j256.ormlite.field.SqlType. 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-core   Source File: WhereTest.java    License: ISC License 6 votes vote down vote up
@Test
public void testRawArgsColumnSqlType() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo = new Foo();
	int val = 63465365;
	foo.val = val;
	assertEquals(1, dao.create(foo));

	QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
	qb.where().raw(Foo.ID_COLUMN_NAME + " = ? and " + val + " = ?", new SelectArg(SqlType.STRING, foo.id),
			new SelectArg(SqlType.INTEGER, val));
	List<Foo> results = qb.query();
	assertNotNull(results);
	assertEquals(1, results.size());
	assertEquals(val, results.get(0).val);
}
 
Example 2
Source Project: ormlite-jdbc   Source File: HsqldbDatabaseType.java    License: ISC License 6 votes vote down vote up
@Override
protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List<String> statementsBefore,
		List<String> additionalArgs, List<String> queriesAfter) {
	// needs to match dropColumnArg()
	StringBuilder seqSb = new StringBuilder(128);
	seqSb.append("CREATE SEQUENCE ");
	appendEscapedEntityName(seqSb, fieldType.getGeneratedIdSequence());
	if (fieldType.getSqlType() == SqlType.LONG) {
		seqSb.append(" AS BIGINT");
	} else {
		// integer is the default
	}
	// with hsqldb (as opposed to all else) the sequences start at 0, grumble
	seqSb.append(" START WITH 1");
	statementsBefore.add(seqSb.toString());
	sb.append("GENERATED BY DEFAULT AS IDENTITY ");
	configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
}
 
Example 3
Source Project: ormlite-jdbc   Source File: TypeValMapper.java    License: ISC License 5 votes vote down vote up
/**
 * Returns the SqlType value associated with the typeVal argument. Can be slow-er.
 */
public static SqlType getSqlTypeForTypeVal(int typeVal) {
	// iterate through to save on the extra HashMap since only for errors
	for (Map.Entry<SqlType, int[]> entry : typeToValMap.entrySet()) {
		for (int val : entry.getValue()) {
			if (val == typeVal) {
				return entry.getKey();
			}
		}
	}
	return SqlType.UNKNOWN;
}
 
Example 4
Source Project: ormlite-core   Source File: ThreadLocalSelectArgTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testSqlTypeValueConst() {
	int val = 12;
	SqlType type = SqlType.INTEGER;
	ThreadLocalSelectArg arg = new ThreadLocalSelectArg(type, val);
	assertTrue(arg.isValueSet());
	assertEquals(val, arg.getValue());
	assertEquals(type, arg.getSqlType());
}
 
Example 5
Source Project: ormlite-jdbc   Source File: DerbyEmbeddedDatabaseTypeTest.java    License: ISC License 5 votes vote down vote up
@Test
public void testGetFieldConverterSerializable() {
	DerbyEmbeddedDatabaseType type = new DerbyEmbeddedDatabaseType();
	FieldConverter converter = type.getFieldConverter(DataType.SERIALIZABLE.getDataPersister(), null);
	assertEquals(SqlType.BLOB, converter.getSqlType());
	assertTrue(converter.isStreamType());
}
 
Example 6
Source Project: ormlite-core   Source File: BaseSqliteDatabaseType.java    License: ISC License 5 votes vote down vote up
@Override
protected void configureGeneratedId(String tableName, StringBuilder sb, FieldType fieldType,
		List<String> statementsBefore, List<String> statementsAfter, List<String> additionalArgs,
		List<String> queriesAfter) {
	/*
	 * Even though the documentation talks about INTEGER, it is 64-bit with a maximum value of 9223372036854775807.
	 * See http://www.sqlite.org/faq.html#q1 and http://www.sqlite.org/autoinc.html
	 */
	if (fieldType.getSqlType() != SqlType.INTEGER && fieldType.getSqlType() != SqlType.LONG) {
		throw new IllegalArgumentException(
				"Sqlite requires that auto-increment generated-id be integer or long type");
	}
	sb.append("PRIMARY KEY AUTOINCREMENT ");
	// no additional call to configureId here
}
 
Example 7
Source Project: ormlite-core   Source File: SerializableType.java    License: ISC License 5 votes vote down vote up
private SerializableType() {
	/*
	 * NOTE: Serializable class should _not_ be in the list because _everything_ is serializable and we want to
	 * force folks to use DataType.SERIALIZABLE -- especially for forwards compatibility.
	 */
	super(SqlType.SERIALIZABLE);
}
 
Example 8
Source Project: ormlite-core   Source File: H2CompiledStatement.java    License: ISC License 5 votes vote down vote up
@Override
public void setObject(int parameterIndex, Object obj, SqlType sqlType) throws SQLException {
	if (obj == null) {
		preparedStatement.setNull(parameterIndex + 1, sqlTypeToJdbcInt(sqlType));
	} else {
		preparedStatement.setObject(parameterIndex + 1, obj, sqlTypeToJdbcInt(sqlType));
	}
}
 
Example 9
Source Project: ormlite-core   Source File: H2CompiledStatement.java    License: ISC License 5 votes vote down vote up
public static int sqlTypeToJdbcInt(SqlType sqlType) {
	switch (sqlType) {
		case STRING:
			return Types.VARCHAR;
		case LONG_STRING:
			return Types.LONGVARCHAR;
		case DATE:
			return Types.TIMESTAMP;
		case BOOLEAN:
			return Types.BOOLEAN;
		case CHAR:
			return Types.CHAR;
		case BYTE:
			return Types.TINYINT;
		case BYTE_ARRAY:
			return Types.VARBINARY;
		case SHORT:
			return Types.SMALLINT;
		case INTEGER:
			return Types.INTEGER;
		case LONG:
			// Types.DECIMAL, Types.NUMERIC
			return Types.BIGINT;
		case FLOAT:
			return Types.FLOAT;
		case DOUBLE:
			return Types.DOUBLE;
		case SERIALIZABLE:
			return Types.VARBINARY;
		case BLOB:
			return Types.BLOB;
		case BIG_DECIMAL:
			return Types.NUMERIC;
		default:
			throw new IllegalArgumentException("No JDBC mapping for unknown SqlType " + sqlType);
	}
}
 
Example 10
Source Project: ormlite-core   Source File: SerializableTypeTest.java    License: ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new SerializableType(SqlType.SERIALIZABLE, new Class[0]);
}
 
Example 11
Source Project: ormlite-core   Source File: EnumStringTypeTest.java    License: ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new EnumStringType(SqlType.STRING, new Class[0]);
}
 
Example 12
Source Project: ormlite-core   Source File: CharacterObjectType.java    License: ISC License 4 votes vote down vote up
protected CharacterObjectType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example 13
Source Project: ormlite-jdbc   Source File: DerbyEmbeddedDatabaseType.java    License: ISC License 4 votes vote down vote up
@Override
public SqlType getSqlType() {
	return SqlType.INTEGER;
}
 
Example 14
Source Project: ormlite-jdbc   Source File: MyDatePersister.java    License: ISC License 4 votes vote down vote up
private MyDatePersister() {
	super(SqlType.DATE, new Class<?>[] { Date.class });
}
 
Example 15
Source Project: ormlite-core   Source File: ByteArrayType.java    License: ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected ByteArrayType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example 16
Source Project: ormlite-core   Source File: DateStringType.java    License: ISC License 4 votes vote down vote up
protected DateStringType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example 17
Source Project: ormlite-android   Source File: AndroidDatabaseConnection.java    License: ISC License 4 votes vote down vote up
private void bindArgs(SQLiteStatement stmt, Object[] args, FieldType[] argFieldTypes) throws SQLException {
	if (args == null) {
		return;
	}
	for (int i = 0; i < args.length; i++) {
		Object arg = args[i];
		if (arg == null) {
			stmt.bindNull(i + 1);
		} else {
			SqlType sqlType = argFieldTypes[i].getSqlType();
			switch (sqlType) {
				case STRING:
				case LONG_STRING:
				case CHAR:
					stmt.bindString(i + 1, arg.toString());
					break;
				case BOOLEAN:
				case BYTE:
				case SHORT:
				case INTEGER:
				case LONG:
					stmt.bindLong(i + 1, ((Number) arg).longValue());
					break;
				case FLOAT:
				case DOUBLE:
					stmt.bindDouble(i + 1, ((Number) arg).doubleValue());
					break;
				case BYTE_ARRAY:
				case SERIALIZABLE:
					stmt.bindBlob(i + 1, (byte[]) arg);
					break;
				case DATE:
					// this is mapped to a STRING under Android
				case BLOB:
					// this is only for derby serializable
				case BIG_DECIMAL:
					// this should be handled as a STRING
					throw new SQLException("Invalid Android type: " + sqlType);
				case UNKNOWN:
				default:
					throw new SQLException("Unknown sql argument type: " + sqlType);
			}
		}
	}
}
 
Example 18
Source Project: ormlite-core   Source File: ByteObjectType.java    License: ISC License 4 votes vote down vote up
private ByteObjectType() {
	super(SqlType.BYTE, new Class<?>[] { Byte.class });
}
 
Example 19
Source Project: ormlite-core   Source File: TimeStampTypeTest.java    License: ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new TimeStampType(SqlType.DATE, new Class[0]);
}
 
Example 20
Source Project: ormlite-core   Source File: FloatTypeTest.java    License: ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new FloatType(SqlType.FLOAT, new Class[0]);
}
 
Example 21
Source Project: ormlite-core   Source File: CharacterObjectType.java    License: ISC License 4 votes vote down vote up
private CharacterObjectType() {
	super(SqlType.CHAR, new Class<?>[] { Character.class });
}
 
Example 22
Source Project: ormlite-core   Source File: TimeStampTypeTest.java    License: ISC License 4 votes vote down vote up
public LocalCurrentTimeStampType() {
	super(SqlType.DATE, new Class<?>[] { java.sql.Timestamp.class });
}
 
Example 23
Source Project: ormlite-core   Source File: DoubleObjectType.java    License: ISC License 4 votes vote down vote up
protected DoubleObjectType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example 24
Source Project: ormlite-core   Source File: ByteTypeTest.java    License: ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new ByteType(SqlType.BYTE, new Class[0]);
}
 
Example 25
Source Project: ormlite-core   Source File: BigIntegerType.java    License: ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected BigIntegerType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example 26
Source Project: ormlite-core   Source File: BaseArgumentHolder.java    License: ISC License 4 votes vote down vote up
@Override
public SqlType getSqlType() {
	return sqlType;
}
 
Example 27
Source Project: ormlite-core   Source File: NullArgHolder.java    License: ISC License 4 votes vote down vote up
@Override
public SqlType getSqlType() {
	// we use this as our default because it should work with all SQL engines
	return SqlType.STRING;
}
 
Example 28
Source Project: ormlite-core   Source File: UuidType.java    License: ISC License 4 votes vote down vote up
private UuidType() {
	super(SqlType.STRING, new Class<?>[] { UUID.class });
}
 
Example 29
Source Project: ormlite-core   Source File: UuidType.java    License: ISC License 4 votes vote down vote up
protected UuidType(SqlType sqlType) {
	super(sqlType);
}
 
Example 30
Source Project: ormlite-core   Source File: UuidType.java    License: ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected UuidType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}