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

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

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

origin: j256/ormlite-core

@Override
public <T> Object queryForOne(String statement, Object[] args, FieldType[] argfieldTypes,
    GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException {
  if (proxy == null) {
    return null;
  } else {
    return proxy.queryForOne(statement, args, argfieldTypes, rowMapper, objectCache);
  }
}
origin: com.j256.ormlite/ormlite-core

@Override
public <T> Object queryForOne(String statement, Object[] args, FieldType[] argfieldTypes,
    GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException {
  if (proxy == null) {
    return null;
  } else {
    return proxy.queryForOne(statement, args, argfieldTypes, rowMapper, objectCache);
  }
}
origin: j256/ormlite-core

@Test
public void testQueryForOne() throws Exception {
  DatabaseConnection conn = createMock(DatabaseConnection.class);
  String statement = "insert bar";
  Object result = new Object();
  expect(conn.queryForOne(statement, null, null, null, null)).andReturn(result);
  conn.close();
  DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn);
  replay(conn);
  assertEquals(result, proxy.queryForOne(statement, null, null, null, null));
  proxy.close();
  verify(conn);
}
origin: j256/ormlite-core

/**
 * Query for an object in the database which matches the id argument.
 */
public T execute(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache) throws SQLException {
  if (objectCache != null) {
    T result = objectCache.get(clazz, id);
    if (result != null) {
      return result;
    }
  }
  Object[] args = new Object[] { convertIdToFieldObject(id) };
  // @SuppressWarnings("unchecked")
  Object result = databaseConnection.queryForOne(statement, args, argFieldTypes, this, objectCache);
  if (result == null) {
    logger.debug("{} using '{}' and {} args, got no results", label, statement, args.length);
  } else if (result == DatabaseConnection.MORE_THAN_ONE) {
    logger.error("{} using '{}' and {} args, got >1 results", label, statement, args.length);
    logArgs(args);
    throw new SQLException(label + " got more than 1 result: " + statement);
  } else {
    logger.debug("{} using '{}' and {} args, got 1 result", label, statement, args.length);
  }
  logArgs(args);
  @SuppressWarnings("unchecked")
  T castResult = (T) result;
  return castResult;
}
origin: com.j256.ormlite/ormlite-core

/**
 * Query for an object in the database which matches the id argument.
 */
public T execute(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache) throws SQLException {
  if (objectCache != null) {
    T result = objectCache.get(clazz, id);
    if (result != null) {
      return result;
    }
  }
  Object[] args = new Object[] { convertIdToFieldObject(id) };
  // @SuppressWarnings("unchecked")
  Object result = databaseConnection.queryForOne(statement, args, argFieldTypes, this, objectCache);
  if (result == null) {
    logger.debug("{} using '{}' and {} args, got no results", label, statement, args.length);
  } else if (result == DatabaseConnection.MORE_THAN_ONE) {
    logger.error("{} using '{}' and {} args, got >1 results", label, statement, args.length);
    logArgs(args);
    throw new SQLException(label + " got more than 1 result: " + statement);
  } else {
    logger.debug("{} using '{}' and {} args, got 1 result", label, statement, args.length);
  }
  logArgs(args);
  @SuppressWarnings("unchecked")
  T castResult = (T) result;
  return castResult;
}
origin: j256/ormlite-core

@SuppressWarnings("unchecked")
@Test
public void testForeignAutoRefresh() throws Exception {
  Field field = ForeignAutoRefresh.class.getDeclaredField("foreign");
  ConnectionSource connectionSource = createMock(ConnectionSource.class);
  DatabaseConnection connection = createMock(DatabaseConnection.class);
  expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes();
  expect(connectionSource.getReadOnlyConnection("ForeignAutoRefresh")).andReturn(connection);
  ForeignForeign foreignForeign = new ForeignForeign();
  String stuff = "21312j3213";
  int id = 4123123;
  foreignForeign.id = id;
  foreignForeign.stuff = stuff;
  expect(connection.queryForOne(isA(String.class), isA(Object[].class), isA(FieldType[].class),
      isA(GenericRowMapper.class), (ObjectCache) isNull())).andReturn(foreignForeign);
  connectionSource.releaseConnection(connection);
  DatabaseResults results = createMock(DatabaseResults.class);
  ForeignAutoRefresh foreign = new ForeignAutoRefresh();
  replay(results, connectionSource, connection);
  FieldType fieldType = FieldType.createFieldType(databaseType, ForeignAutoRefresh.class.getSimpleName(), field,
      ForeignAutoRefresh.class);
  fieldType.configDaoInformation(connectionSource, ForeignAutoRefresh.class);
  assertNull(foreign.foreign);
  fieldType.assignField(connectionSource, foreign, id, false, null);
  assertNotNull(foreign.foreign);
  assertEquals(id, foreign.foreign.id);
  assertEquals(stuff, foreign.foreign.stuff);
  verify(results, connectionSource, connection);
}
com.j256.ormlite.supportDatabaseConnectionqueryForOne

Javadoc

Perform a SQL query with the associated SQL statement, arguments, and types and returns a single result.

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.
  • queryForLong
    Perform a query whose result should be a single long-integer value.
  • rollback
    Roll back all changes since the savepoint was created. If savePoint is null then roll back all outst
  • queryForLong,
  • rollback,
  • delete,
  • isClosed,
  • isTableExists,
  • update,
  • releaseSavePoint

Popular in Java

  • Creating JSON documents from java classes using gson
  • findViewById (Activity)
  • getResourceAsStream (ClassLoader)
  • requestLocationUpdates (LocationManager)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Socket (java.net)
    Provides a client-side TCP socket.
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Top PhpStorm plugins
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