Tabnine Logo
DatabaseConnection.queryForLong
Code IndexAdd Tabnine to your IDE (free)

How to use
queryForLong
method
in
com.j256.ormlite.support.DatabaseConnection

Best Java code snippets using com.j256.ormlite.support.DatabaseConnection.queryForLong (Showing top 20 results out of 315)

origin: com.j256.ormlite/ormlite-core

@Override
public long queryForLong(String statement, Object[] args, FieldType[] argFieldTypes) throws SQLException {
  if (proxy == null) {
    return 0;
  } else {
    return proxy.queryForLong(statement, args, argFieldTypes);
  }
}
origin: com.j256.ormlite/ormlite-core

@Override
public long queryForLong(String statement) throws SQLException {
  if (proxy == null) {
    return 0;
  } else {
    return proxy.queryForLong(statement);
  }
}
origin: j256/ormlite-core

@Override
public long queryForLong(String statement) throws SQLException {
  if (proxy == null) {
    return 0;
  } else {
    return proxy.queryForLong(statement);
  }
}
origin: j256/ormlite-core

@Override
public long queryForLong(String statement, Object[] args, FieldType[] argFieldTypes) throws SQLException {
  if (proxy == null) {
    return 0;
  } else {
    return proxy.queryForLong(statement, args, argFieldTypes);
  }
}
origin: com.j256.ormlite/ormlite-core

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);
}
origin: j256/ormlite-core

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);
}
origin: j256/ormlite-core

/**
 * 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;
}
origin: com.j256.ormlite/ormlite-core

/**
 * 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;
}
origin: j256/ormlite-core

@Test
public void testQueryForLongStringObjectArrayFieldTypeArray() throws Exception {
  DatabaseConnection conn = createMock(DatabaseConnection.class);
  String statement = "select stuff from foo";
  long result = 3123123124141413L;
  expect(conn.queryForLong(statement, null, null)).andReturn(result);
  conn.close();
  DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn);
  replay(conn);
  assertEquals(result, proxy.queryForLong(statement, null, null));
  proxy.close();
  verify(conn);
}
origin: j256/ormlite-core

@Test
public void testQueryForLongString() throws Exception {
  DatabaseConnection conn = createMock(DatabaseConnection.class);
  String statement = "select stuff from foo";
  long result = 31231231241414L;
  expect(conn.queryForLong(statement)).andReturn(result);
  conn.close();
  DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn);
  replay(conn);
  assertEquals(result, proxy.queryForLong(statement));
  proxy.close();
  verify(conn);
}
origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testSequenceZero() throws Exception {
  DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
  expect(databaseConnection.queryForLong(isA(String.class))).andReturn(0L);
  replay(databaseConnection);
  NeedsSequenceDatabaseType needsSequence = new NeedsSequenceDatabaseType();
  Dao<GeneratedIdSequence, Integer> dao = createDao(GeneratedIdSequence.class, false);
  MappedCreate<GeneratedIdSequence, Integer> mappedCreate = MappedCreate.build(dao,
      new TableInfo<GeneratedIdSequence, Integer>(databaseType, GeneratedIdSequence.class));
  mappedCreate.insert(needsSequence, databaseConnection, new GeneratedIdSequence(), null);
  verify(databaseConnection);
}
origin: com.j256.ormlite/ormlite-jdbc

@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);
  }
}
origin: j256/ormlite-core

@Test
public void testGeneratedIdSequenceLong() throws Exception {
  DatabaseType databaseType = new NeedsSequenceDatabaseType();
  connectionSource.setDatabaseType(databaseType);
  Dao<GeneratedIdLong, Long> dao = createDao(GeneratedIdLong.class, false);
  StatementExecutor<GeneratedIdLong, Long> se = new StatementExecutor<GeneratedIdLong, Long>(databaseType,
      new TableInfo<GeneratedIdLong, Long>(databaseType, GeneratedIdLong.class), dao);
  DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
  expect(databaseConnection.queryForLong(isA(String.class))).andReturn(1L);
  expect(databaseConnection.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
      (GeneratedKeyHolder) isNull())).andReturn(1);
  replay(databaseConnection);
  GeneratedIdLong genIdSeq = new GeneratedIdLong();
  se.create(databaseConnection, genIdSeq, null);
  verify(databaseConnection);
}
origin: j256/ormlite-core

@Test
public void testGeneratedIdSequence() throws Exception {
  DatabaseType databaseType = new NeedsSequenceDatabaseType();
  connectionSource.setDatabaseType(databaseType);
  TableInfo<GeneratedId, Integer> tableInfo =
      new TableInfo<GeneratedId, Integer>(databaseType, GeneratedId.class);
  Dao<GeneratedId, Integer> dao = createDao(GeneratedId.class, false);
  StatementExecutor<GeneratedId, Integer> se =
      new StatementExecutor<GeneratedId, Integer>(databaseType, tableInfo, dao);
  DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
  expect(databaseConnection.queryForLong(isA(String.class))).andReturn(1L);
  expect(databaseConnection.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
      (GeneratedKeyHolder) isNull())).andReturn(1);
  replay(databaseConnection);
  GeneratedId genIdSeq = new GeneratedId();
  se.create(databaseConnection, genIdSeq, null);
  verify(databaseConnection);
}
origin: com.j256.ormlite/ormlite-jdbc

@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();
  }
}
origin: j256/ormlite-core

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);
}
origin: com.j256.ormlite/ormlite-core

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);
}
origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testDatabasePing() throws Exception {
  if (connectionSource == null) {
    return;
  }
  if (!isDriverClassExpected()) {
    return;
  }
  String ping = databaseType.getPingStatement();
  DatabaseConnection conn = connectionSource.getReadOnlyConnection(null);
  try {
    testPingValue(conn.queryForLong(ping));
  } finally {
    connectionSource.releaseConnection(conn);
  }
}
origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testQueryForLong() 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;
    assertEquals(1, dao.create(foo));
    assertEquals(id, databaseConnection.queryForLong("select id from foo"));
  } finally {
    connectionSource.releaseConnection(databaseConnection);
  }
}
origin: com.j256.ormlite/ormlite-jdbc

@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);
  }
}
com.j256.ormlite.supportDatabaseConnectionqueryForLong

Javadoc

Perform a query whose result should be a single long-integer value.

Popular methods of DatabaseConnection

  • executeStatement
    Execute a statement directly on the connection.
  • isAutoCommit
    Return if auto-commit is currently enabled.
  • setAutoCommit
    Set the auto-commit to be on (true) or off (false). Setting auto-commit to true may or may-not cause
  • commit
    Commit all changes since the savepoint was created. If savePoint is null then commit all outstanding
  • compileStatement
    Like compileStatement(String, StatementType, FieldType[]) except the caller can specify the result f
  • setSavePoint
    Start a save point with a certain name. It can be a noop if savepoints are not supported.
  • close
  • closeQuietly
    Close the connection to the database but swallow any exceptions.
  • insert
    Perform a SQL update while with the associated SQL statement, arguments, and types. This will possib
  • isAutoCommitSupported
    Return if auto-commit is supported.
  • rollback
    Roll back all changes since the savepoint was created. If savePoint is null then roll back all outst
  • delete
    Perform a SQL delete with the associated SQL statement, arguments, and types.
  • rollback,
  • delete,
  • isClosed,
  • isTableExists,
  • queryForOne,
  • update,
  • releaseSavePoint

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • getApplicationContext (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now