本文整理汇总了Java中com.j256.ormlite.field.SqlType类的典型用法代码示例。如果您正苦于以下问题:Java SqlType类的具体用法?Java SqlType怎么用?Java SqlType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlType类属于com.j256.ormlite.field包,在下文中一共展示了SqlType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureGeneratedIdSequence
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
@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);
}
示例2: testRawArgsColumnSqlType
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
@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);
}
示例3: findPinyin
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
/**
* Find dictionary entries in the data store that begin with the given
* pinyin syllables.
*
* @param pinyin a sequence of {@link PinyinSyllable}.
* @param limit the maximum number of entries to return.
* @param offset the number of search results to skip.
* @param canceller a {@link SearchCanceller} (may be {@code null}).
* @return a list of {@link DictionaryEntry}.
* @throws IllegalArgumentException if limit or offset are negative.
*/
public List<DictionaryEntry> findPinyin(final List<PinyinSyllable> pinyin, final long limit, final long offset, final SearchCanceller canceller) {
if (limit < 0) {
throw new IllegalArgumentException("Invalid limit: " + limit);
}
if (offset < 0) {
throw new IllegalArgumentException("Invalid offset: " + offset);
}
LOGGER.debug("Finding pinyin: " + pinyin);
final String pinyinQueryString = this.formatPinyinQuery(pinyin);
final PreparedQuery<DictionaryDataStoreEntry> query;
try {
query = this.dictionaryEntryDao.queryBuilder()
.orderByRaw("case when like (?, " + DictionaryDataStoreEntry.COLUMN_PINYIN + ") " +
"then 1 else 0 end desc, " +
"length(" + DictionaryDataStoreEntry.COLUMN_HANZI_SIMPLIFIED + "), " +
DictionaryDataStoreEntry.COLUMN_PINYIN,
new SelectArg(SqlType.STRING, "" + pinyinQueryString + " %"))
.limit(limit)
.offset(offset)
.where().like(DictionaryDataStoreEntry.COLUMN_PINYIN, new SelectArg(pinyinQueryString + "%"))
.prepare();
} catch (final SQLException e) {
throw new DictionaryDataStoreException("Failed to create query", e);
}
return this.transformEntries(this.doQuery(query, canceller, pinyinQueryString));
}
示例4: findChinese
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
/**
* Find dictionary entries in the data store that begin with the given
* Chinese characters.
*
* @param chineseCharacters Chinese character text to find.
* @param limit the maximum number of entries to return.
* @param offset the number of search results to skip.
* @param canceller a {@link SearchCanceller} (may be {@code null}).
* @return a list of {@link DictionaryEntry}.
* @throws IllegalArgumentException if limit or offset are negative.
*/
public List<DictionaryEntry> findChinese(final String chineseCharacters, final long limit, final long offset, final SearchCanceller canceller) {
if (limit < 0) {
throw new IllegalArgumentException("Invalid limit: " + limit);
}
if (offset < 0) {
throw new IllegalArgumentException("Invalid offset: " + offset);
}
LOGGER.debug("Finding Chinese characters: " + chineseCharacters);
final PreparedQuery<DictionaryDataStoreEntry> query;
try {
query = this.dictionaryEntryDao.queryBuilder()
.orderByRaw("case " +
"when like (?, " + DictionaryDataStoreEntry.COLUMN_HANZI_SIMPLIFIED + ") then 0 " +
"else 1 end, " +
"length(" + DictionaryDataStoreEntry.COLUMN_HANZI_SIMPLIFIED + "), " +
DictionaryDataStoreEntry.COLUMN_PINYIN,
new SelectArg(SqlType.STRING, chineseCharacters + "%"))
.limit(limit)
.offset(offset)
.where().like(DictionaryDataStoreEntry.COLUMN_HANZI_SIMPLIFIED, new SelectArg("%" + chineseCharacters + "%"))
.prepare();
} catch (final SQLException e) {
throw new DictionaryDataStoreException("Failed to prepare query", e);
}
return this.transformEntries(this.doQuery(query, canceller, chineseCharacters));
}
示例5: findDefinitions
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
/**
* Find dictionary entries in the data store that contain the given English
* text.
*
* @param englishWords English definition text to find.
* @param limit the maximum number of entries to return.
* @param offset the number of search results to skip.
* @param canceller a {@link SearchCanceller} (may be {@code null}).
* @return a list of {@link DictionaryEntry}.
* @throws IllegalArgumentException if limit or offset are negative.
*/
public List<DictionaryEntry> findDefinitions(final String englishWords, final long limit, final long offset, final SearchCanceller canceller) {
if (limit < 0) {
throw new IllegalArgumentException("Invalid limit: " + limit);
}
if (offset < 0) {
throw new IllegalArgumentException("Invalid offset: " + offset);
}
LOGGER.debug("Finding definitions: " + englishWords);
final PreparedQuery<DictionaryDataStoreEntry> query;
try {
query = this.dictionaryEntryDao.queryBuilder()
.orderByRaw("case " +
"when like (?, " + DictionaryDataStoreEntry.COLUMN_ENGLISH + ") then 0 " +
"when like (?, " + DictionaryDataStoreEntry.COLUMN_ENGLISH + ") then 1 " +
"when like (?, " + DictionaryDataStoreEntry.COLUMN_ENGLISH + ") then 2 " +
"when like (?, " + DictionaryDataStoreEntry.COLUMN_ENGLISH + ") then 3 " +
"else 4 end, " +
"length(" + DictionaryDataStoreEntry.COLUMN_HANZI_SIMPLIFIED + "), " +
DictionaryDataStoreEntry.COLUMN_PINYIN,
new SelectArg(SqlType.STRING, "/ " + englishWords + " /%"),
new SelectArg(SqlType.STRING, "%/ " + englishWords + " /%"),
new SelectArg(SqlType.STRING, "%/ " + englishWords + " %"),
new SelectArg(SqlType.STRING, "% " + englishWords + " %"))
.limit(limit)
.offset(offset)
.where().like(DictionaryDataStoreEntry.COLUMN_ENGLISH, new SelectArg("%" + englishWords + "%"))
.prepare();
} catch (final SQLException e) {
throw new DictionaryDataStoreException("Failed to create query", e);
}
return this.transformEntries(this.doQuery(query, canceller, englishWords));
}
示例6: appendLongType
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
protected void appendLongType(StringBuilder paramStringBuilder, FieldType paramFieldType, int paramInt)
{
if ((paramFieldType.getSqlType() == SqlType.LONG) && (paramFieldType.isGeneratedId()))
{
paramStringBuilder.append("INTEGER");
return;
}
paramStringBuilder.append("BIGINT");
}
示例7: setObject
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
public void setObject(int paramInt, Object paramObject, SqlType paramSqlType)
{
isInPrep();
if (this.args == null)
this.args = new ArrayList();
if (paramObject == null)
{
this.args.add(paramInt, null);
return;
}
switch (1.$SwitchMap$com$j256$ormlite$field$SqlType[paramSqlType.ordinal()])
{
default:
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
this.args.add(paramInt, paramObject.toString());
return;
case 12:
case 13:
this.args.add(paramInt, paramObject);
return;
case 14:
case 15:
throw new java.sql.SQLException("Invalid Android type: " + paramSqlType);
}
throw new java.sql.SQLException("Unknown sql argument type: " + paramSqlType);
}
示例8: getGroupsForIdent
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
public List<UserGroup> getGroupsForIdent(IdentMethod method, String identString) {
try {
DatabaseManager databaseManager = manager.app.databaseManager;
QueryBuilder<UserGroupIdent, Integer> qbIdent = databaseManager.getDao(UserGroupIdent.class, Integer.class).queryBuilder();
qbIdent.where().eq(UserGroupIdent.METHOD_COLUMN, method.prefix)
.and().raw(String.format("? REGEXP %s", UserGroupIdent.IDENT_PATTERN_COLUMN), new SelectArg(SqlType.STRING, identString));
QueryBuilder<UserGroup, Integer> qbGroup = databaseManager.getDao(UserGroup.class, Integer.class).queryBuilder();
return qbGroup.join(qbIdent).query();
} catch (SQLException e) {
throw new UnexpectedException(e);
}
}
示例9: appendLongType
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
@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");
}
}
示例10: getTypeValForSqlType
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
/**
* Returns the primary type value associated with the SqlType argument.
*/
public static int getTypeValForSqlType(SqlType sqlType) throws SQLException {
int[] typeVals = typeToValMap.get(sqlType);
if (typeVals == null) {
throw new SQLException("SqlType is unknown to type val mapping: " + sqlType);
}
if (typeVals.length == 0) {
throw new SQLException("SqlType does not have any JDBC type value mapping: " + sqlType);
} else {
return typeVals[0];
}
}
示例11: setObject
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
@Override
public void setObject(int parameterIndex, Object obj, SqlType sqlType) throws SQLException {
if (obj == null) {
preparedStatement.setNull(parameterIndex + 1, TypeValMapper.getTypeValForSqlType(sqlType));
} else {
preparedStatement.setObject(parameterIndex + 1, obj, TypeValMapper.getTypeValForSqlType(sqlType));
}
}
示例12: setObject
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
@Override
public void setObject(int parameterIndex, Object obj, SqlType sqlType) throws SQLException {
isInPrep();
if (args == null) {
args = new ArrayList<Object>();
}
if (obj == null) {
args.add(parameterIndex, null);
return;
}
switch (sqlType) {
case STRING:
case LONG_STRING:
case DATE:
case BOOLEAN:
case CHAR:
case BYTE:
case SHORT:
case INTEGER:
case LONG:
case FLOAT:
case DOUBLE:
args.add(parameterIndex, obj.toString());
break;
case BYTE_ARRAY:
case SERIALIZABLE:
args.add(parameterIndex, obj);
break;
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);
}
}
示例13: assignStatementArguments
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
/**
* 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");
}
}
}
示例14: sqlTypeToJdbcInt
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
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);
}
}
示例15: SerializableType
import com.j256.ormlite.field.SqlType; //导入依赖的package包/类
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);
}