com.j256.ormlite.field.SqlType Java Examples

The following examples show how to use com.j256.ormlite.field.SqlType. 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 File: WhereTest.java    From ormlite-core with 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 File: HsqldbDatabaseType.java    From ormlite-jdbc with 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 File: TypeValMapper.java    From ormlite-jdbc with 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 File: ThreadLocalSelectArgTest.java    From ormlite-core with 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 File: H2CompiledStatement.java    From ormlite-core with 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 #6
Source File: BaseSqliteDatabaseType.java    From ormlite-core with 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 File: DerbyEmbeddedDatabaseTypeTest.java    From ormlite-jdbc with 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 #8
Source File: H2CompiledStatement.java    From ormlite-core with 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 #9
Source File: SerializableType.java    From ormlite-core with 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 #10
Source File: ShortType.java    From ormlite-core with ISC License 4 votes vote down vote up
private ShortType() {
	super(SqlType.SHORT, new Class<?>[] { short.class });
}
 
Example #11
Source File: ByteType.java    From ormlite-core with ISC License 4 votes vote down vote up
private ByteType() {
	super(SqlType.BYTE, new Class<?>[] { byte.class });
}
 
Example #12
Source File: ShortType.java    From ormlite-core with ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected ShortType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example #13
Source File: EnumIntegerType.java    From ormlite-core with ISC License 4 votes vote down vote up
private EnumIntegerType() {
	super(SqlType.INTEGER);
}
 
Example #14
Source File: EnumStringType.java    From ormlite-core with ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected EnumStringType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example #15
Source File: ByteType.java    From ormlite-core with ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected ByteType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example #16
Source File: BaseEnumType.java    From ormlite-core with ISC License 4 votes vote down vote up
protected BaseEnumType(SqlType sqlType) {
	super(sqlType);
}
 
Example #17
Source File: LongStringTypeTest.java    From ormlite-core with ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new LongStringType(SqlType.LONG_STRING, new Class[0]);
}
 
Example #18
Source File: BooleanType.java    From ormlite-core with ISC License 4 votes vote down vote up
protected BooleanType(SqlType sqlType) {
	super(sqlType);
}
 
Example #19
Source File: BaseDateType.java    From ormlite-core with ISC License 4 votes vote down vote up
protected BaseDateType(SqlType sqlType) {
	super(sqlType);
}
 
Example #20
Source File: DateStringType.java    From ormlite-core with ISC License 4 votes vote down vote up
private DateStringType() {
	super(SqlType.STRING);
}
 
Example #21
Source File: BooleanTypeTest.java    From ormlite-core with ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new BooleanType(SqlType.BOOLEAN, new Class[0]);
}
 
Example #22
Source File: DoubleType.java    From ormlite-core with ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected DoubleType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example #23
Source File: DoubleType.java    From ormlite-core with ISC License 4 votes vote down vote up
private DoubleType() {
	super(SqlType.DOUBLE, new Class<?>[] { double.class });
}
 
Example #24
Source File: LongObjectType.java    From ormlite-core with ISC License 4 votes vote down vote up
protected LongObjectType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example #25
Source File: LongObjectType.java    From ormlite-core with ISC License 4 votes vote down vote up
private LongObjectType() {
	super(SqlType.LONG, new Class<?>[] { Long.class });
}
 
Example #26
Source File: SqlDateTypeTest.java    From ormlite-core with ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new SqlDateType(SqlType.DATE, new Class[0]);
}
 
Example #27
Source File: ShortObjectType.java    From ormlite-core with ISC License 4 votes vote down vote up
protected ShortObjectType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example #28
Source File: FloatType.java    From ormlite-core with ISC License 4 votes vote down vote up
/**
 * Here for others to subclass.
 */
protected FloatType(SqlType sqlType, Class<?>[] classes) {
	super(sqlType, classes);
}
 
Example #29
Source File: CharTypeTest.java    From ormlite-core with ISC License 4 votes vote down vote up
@Test
public void testCoverage() {
	new CharType(SqlType.CHAR, new Class[0]);
}
 
Example #30
Source File: BigIntegerType.java    From ormlite-core with ISC License 4 votes vote down vote up
protected BigIntegerType() {
	super(SqlType.STRING, new Class<?>[] { BigInteger.class });
}