Java Code Examples for com.j256.ormlite.field.FieldType#getSqlType()
The following examples show how to use
com.j256.ormlite.field.FieldType#getSqlType() .
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: HsqldbDatabaseType.java From ormlite-jdbc with ISC License | 6 votes |
@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 2
Source File: MappedPreparedStmt.java From ormlite-core with ISC License | 5 votes |
/** * Assign arguments to the statement. * * @return The statement passed in or null if it had to be closed on error. */ private CompiledStatement assignStatementArguments(CompiledStatement stmt) throws SQLException { boolean ok = false; try { if (limit != null) { // we use this if SQL statement LIMITs are not supported by this database type stmt.setMaxRows(limit.intValue()); } // set any arguments if we are logging our object Object[] argValues = null; if (logger.isLevelEnabled(Level.TRACE) && argHolders.length > 0) { argValues = new Object[argHolders.length]; } for (int i = 0; i < argHolders.length; i++) { Object argValue = argHolders[i].getSqlArgValue(); FieldType fieldType = argFieldTypes[i]; SqlType sqlType; if (fieldType == null) { sqlType = argHolders[i].getSqlType(); } else { sqlType = fieldType.getSqlType(); } stmt.setObject(i, argValue, sqlType); if (argValues != null) { argValues[i] = argValue; } } logger.debug("prepared statement '{}' with {} args", statement, argHolders.length); if (argValues != null) { // need to do the (Object) cast to force args to be a single object logger.trace("prepared statement arguments: {}", (Object) argValues); } ok = true; return stmt; } finally { if (!ok) { IOUtils.closeThrowSqlException(stmt, "statement"); } } }
Example 3
Source File: BaseSqliteDatabaseType.java From ormlite-core with ISC License | 5 votes |
@Override protected void appendLongType(StringBuilder sb, FieldType fieldType, int fieldWidth) { /* * This is unfortunate. SQLIte requires that a generated-id have the string "INTEGER PRIMARY KEY AUTOINCREMENT" * even though the maximum generated value is 64-bit. See configureGeneratedId below. */ if (fieldType.getSqlType() == SqlType.LONG && fieldType.isGeneratedId()) { sb.append("INTEGER"); } else { sb.append("BIGINT"); } }
Example 4
Source File: BaseSqliteDatabaseType.java From ormlite-core with ISC License | 5 votes |
@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 }