本文整理汇总了Java中com.j256.ormlite.support.DatabaseConnection.queryForLong方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseConnection.queryForLong方法的具体用法?Java DatabaseConnection.queryForLong怎么用?Java DatabaseConnection.queryForLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.support.DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection.queryForLong方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ifExists
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public boolean ifExists(DatabaseConnection paramDatabaseConnection, ID paramID)
{
if (this.ifExistsQuery == null)
{
QueryBuilder localQueryBuilder = new QueryBuilder(this.databaseType, this.tableInfo, this.dao);
localQueryBuilder.selectRaw(new String[] { "COUNT(*)" });
localQueryBuilder.where().eq(this.tableInfo.getIdField().getColumnName(), new SelectArg());
this.ifExistsQuery = localQueryBuilder.prepareStatementString();
FieldType[] arrayOfFieldType = new FieldType[1];
arrayOfFieldType[0] = this.tableInfo.getIdField();
this.ifExistsFieldTypes = arrayOfFieldType;
}
long l = paramDatabaseConnection.queryForLong(this.ifExistsQuery, new Object[] { paramID }, this.ifExistsFieldTypes);
logger.debug("query of '{}' returned {}", this.ifExistsQuery, Long.valueOf(l));
return l != 0L;
}
示例2: testQueryForLongTooManyResults
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testQueryForLongTooManyResults() throws Exception {
DatabaseConnection databaseConnection = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
try {
Dao<Foo, Object> dao = createDao(Foo.class, true);
Foo foo = new Foo();
long id = 21321321L;
foo.id = id;
// insert twice
assertEquals(1, dao.create(foo));
assertEquals(1, dao.create(foo));
databaseConnection.queryForLong("select id from foo");
} finally {
connectionSource.releaseConnection(databaseConnection);
}
}
示例3: testTestConnectionThatWasClosed
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testTestConnectionThatWasClosed() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
String pingStatement = pooled.getDatabaseType().getPingStatement();
try {
DatabaseConnection conn1 = pooled.getReadWriteConnection(null);
conn1.queryForLong(pingStatement);
pooled.releaseConnection(conn1);
// close it behind the pool's back, bad dog
conn1.close();
DatabaseConnection conn2 = pooled.getReadWriteConnection(null);
assertSame(conn1, conn2);
conn2.queryForLong(pingStatement);
} finally {
pooled.close();
}
}
示例4: testAuthTestConnectionExpired
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testAuthTestConnectionExpired() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
long delay = 100;
pooled.setCheckConnectionsEveryMillis(delay);
pooled.setMaxConnectionAgeMillis(delay);
String pingStatement = pooled.getDatabaseType().getPingStatement();
try {
DatabaseConnection conn1 = pooled.getReadWriteConnection(null);
conn1.queryForLong(pingStatement);
pooled.releaseConnection(conn1);
// make it test ok once
Thread.sleep(delay * 2);
DatabaseConnection conn2 = pooled.getReadWriteConnection(null);
assertNotSame(conn1, conn2);
conn2.queryForLong(pingStatement);
pooled.releaseConnection(conn2);
} finally {
pooled.close();
}
}
示例5: testTestClosedConnectionWithTesting
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testTestClosedConnectionWithTesting() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
String pingStatement = pooled.getDatabaseType().getPingStatement();
pooled.setTestBeforeGet(true);
try {
DatabaseConnection conn1 = pooled.getReadWriteConnection(null);
conn1.queryForLong(pingStatement);
pooled.releaseConnection(conn1);
// close it behind the pool's back, bad dog
conn1.close();
DatabaseConnection conn2 = pooled.getReadWriteConnection(null);
assertNotSame(conn1, conn2);
conn2.queryForLong(pingStatement);
pooled.releaseConnection(conn2);
DatabaseConnection conn3 = pooled.getReadWriteConnection(null);
assertSame(conn2, conn3);
conn3.queryForLong(pingStatement);
pooled.releaseConnection(conn3);
} finally {
pooled.close();
}
}
示例6: ifExists
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public boolean ifExists(DatabaseConnection connection, ID id) throws SQLException {
if (ifExistsQuery == null) {
QueryBuilder<T, ID> qb = new QueryBuilder<T, ID>(databaseType, tableInfo, dao);
qb.selectRaw("COUNT(*)");
/*
* NOTE: bit of a hack here because the select arg is never used but it _can't_ be a constant because we set
* field-name and field-type on it.
*/
qb.where().eq(tableInfo.getIdField().getColumnName(), new SelectArg());
ifExistsQuery = qb.prepareStatementString();
ifExistsFieldTypes = new FieldType[] { tableInfo.getIdField() };
}
Object idSqlArg = tableInfo.getIdField().convertJavaFieldToSqlArgValue(id);
long count = connection.queryForLong(ifExistsQuery, new Object[] { idSqlArg }, ifExistsFieldTypes);
logger.debug("query of '{}' returned {}", ifExistsQuery, count);
return (count != 0);
}
示例7: assignSequenceId
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
private void assignSequenceId(DatabaseConnection paramDatabaseConnection, T paramT, ObjectCache paramObjectCache)
{
long l = paramDatabaseConnection.queryForLong(this.queryNextSequenceStmt);
logger.debug("queried for sequence {} using stmt: {}", Long.valueOf(l), this.queryNextSequenceStmt);
if (l == 0L)
throw new SQLException("Should not have returned 0 for stmt: " + this.queryNextSequenceStmt);
assignIdValue(paramT, Long.valueOf(l), "sequence", paramObjectCache);
}
示例8: queryForCountStar
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
public long queryForCountStar(DatabaseConnection paramDatabaseConnection)
{
if (this.countStarQuery == null)
{
StringBuilder localStringBuilder = new StringBuilder(64);
localStringBuilder.append("SELECT COUNT(*) FROM ");
this.databaseType.appendEscapedEntityName(localStringBuilder, this.tableInfo.getTableName());
this.countStarQuery = localStringBuilder.toString();
}
long l = paramDatabaseConnection.queryForLong(this.countStarQuery);
logger.debug("query of '{}' returned {}", this.countStarQuery, Long.valueOf(l));
return l;
}
示例9: testQueryForLongNoResult
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test(expected = SQLException.class)
public void testQueryForLongNoResult() throws Exception {
DatabaseConnection databaseConnection = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
try {
createDao(Foo.class, true);
databaseConnection.queryForLong("select id from foo");
} finally {
connectionSource.releaseConnection(databaseConnection);
}
}
示例10: testAuthTestConnection
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
@Test
public void testAuthTestConnection() throws Exception {
JdbcPooledConnectionSource pooled = new JdbcPooledConnectionSource(DEFAULT_DATABASE_URL);
long delay = 100;
pooled.setCheckConnectionsEveryMillis(delay);
String pingStatement = pooled.getDatabaseType().getPingStatement();
try {
DatabaseConnection conn1 = pooled.getReadWriteConnection(null);
conn1.queryForLong(pingStatement);
pooled.releaseConnection(conn1);
// make it test ok once
Thread.sleep(delay + 50);
DatabaseConnection conn2 = pooled.getReadWriteConnection(null);
assertSame(conn1, conn2);
conn2.queryForLong(pingStatement);
pooled.releaseConnection(conn2);
// close it behind the pool's back, bad dog
conn2.close();
// now it should find out that the connection is bad and pull it
Thread.sleep(delay + 50);
DatabaseConnection conn3 = pooled.getReadWriteConnection(null);
assertNotSame(conn2, conn3);
// this should work
conn3.queryForLong(pingStatement);
pooled.releaseConnection(conn3);
} finally {
pooled.close();
}
}
示例11: assignSequenceId
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
private void assignSequenceId(DatabaseConnection databaseConnection, T data, ObjectCache objectCache)
throws SQLException {
// call the query-next-sequence stmt to increment the sequence
long seqVal = databaseConnection.queryForLong(queryNextSequenceStmt);
logger.debug("queried for sequence {} using stmt: {}", seqVal, queryNextSequenceStmt);
if (seqVal == 0) {
// sanity check that it is working
throw new SQLException("Should not have returned 0 for stmt: " + queryNextSequenceStmt);
}
assignIdValue(data, seqVal, "sequence", objectCache);
}
示例12: queryForCountStar
import com.j256.ormlite.support.DatabaseConnection; //导入方法依赖的package包/类
/**
* Return a long value which is the number of rows in the table.
*/
public long queryForCountStar(DatabaseConnection databaseConnection) throws SQLException {
if (countStarQuery == null) {
StringBuilder sb = new StringBuilder(64);
sb.append("SELECT COUNT(*) FROM ");
databaseType.appendEscapedEntityName(sb, tableInfo.getTableName());
countStarQuery = sb.toString();
}
long count = databaseConnection.queryForLong(countStarQuery);
logger.debug("query of '{}' returned {}", countStarQuery, count);
return count;
}