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

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

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

origin: j256/ormlite-core

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

@Override
public int insert(String statement, Object[] args, FieldType[] argfieldTypes, GeneratedKeyHolder keyHolder)
    throws SQLException {
  if (proxy == null) {
    return 0;
  } else {
    return proxy.insert(statement, args, argfieldTypes, keyHolder);
  }
}
origin: j256/ormlite-core

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

@Test
public void testQueryKeyHolderNoKeys() throws Exception {
  DatabaseConnection databaseConnection = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
  try {
    createDao(Foo.class, true);
    GeneratedKeyHolder keyHolder = createMock(GeneratedKeyHolder.class);
    keyHolder.addKey(0L);
    replay(keyHolder);
    databaseConnection.insert("insert into foo (id) values (2)", new Object[0], new FieldType[0], keyHolder);
    verify(keyHolder);
  } finally {
    connectionSource.releaseConnection(databaseConnection);
  }
}
origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testIdColumnChangedFromStringToNumber() throws Exception {
  // NOTE: trying to get the database to return a string as a result but could not figure it out
  DatabaseConnection databaseConnection = connectionSource.getReadOnlyConnection(FOOINT_TABLE_NAME);
  try {
    createDao(FooString.class, true);
    GeneratedKeyHolder keyHolder = createMock(GeneratedKeyHolder.class);
    keyHolder.addKey(0L);
    replay(keyHolder);
    databaseConnection.insert("insert into fooint (id, stuff) values ('12', 'zipper')", new Object[0],
        new FieldType[0], keyHolder);
    verify(keyHolder);
  } finally {
    connectionSource.releaseConnection(databaseConnection);
  }
}
origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testIdColumnInteger() throws Exception {
  // NOTE: this doesn't seem to generate an INTEGER type, oh well
  DatabaseConnection databaseConnection = connectionSource.getReadOnlyConnection(FOOINT_TABLE_NAME);
  try {
    createDao(FooInt.class, true);
    GeneratedKeyHolder keyHolder = createMock(GeneratedKeyHolder.class);
    keyHolder.addKey(1L);
    replay(keyHolder);
    databaseConnection.insert("insert into fooint (stuff) values (2)", new Object[0], new FieldType[0],
        keyHolder);
    verify(keyHolder);
  } finally {
    connectionSource.releaseConnection(databaseConnection);
  }
}
origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testIdColumnInvalid() throws Exception {
  // NOTE: this doesn't seem to generate an INTEGER type, oh well
  DatabaseConnection databaseConnection = connectionSource.getReadOnlyConnection(FOOINT_TABLE_NAME);
  try {
    createDao(FooInt.class, true);
    GeneratedKeyHolder keyHolder = createMock(GeneratedKeyHolder.class);
    keyHolder.addKey(1L);
    replay(keyHolder);
    databaseConnection.insert("insert into fooint (stuff) values ('zipper')", new Object[0], new FieldType[0],
        keyHolder);
    verify(keyHolder);
  } finally {
    connectionSource.releaseConnection(databaseConnection);
  }
}
origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testArgumentHolderNotSet() throws Exception {
  TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(databaseType, Foo.class);
  Dao<Foo, Integer> dao = createDao(Foo.class, false);
  MappedCreate<Foo, Integer> mappedCreate = MappedCreate.build(dao, tableInfo);
  DatabaseConnection conn = createMock(DatabaseConnection.class);
  expect(conn.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
      isA(GeneratedKeyHolder.class))).andReturn(1);
  replay(conn);
  mappedCreate.insert(databaseType, conn, new Foo(), null);
}
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: j256/ormlite-core

@Test(expected = SQLException.class)
public void testArgumentHolderSetZero() throws Exception {
  TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(databaseType, Foo.class);
  Dao<Foo, Integer> dao = createDao(Foo.class, false);
  MappedCreate<Foo, Integer> mappedCreate = MappedCreate.build(dao, tableInfo);
  DatabaseConnection conn = createMock(DatabaseConnection.class);
  expect(conn.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
      isA(GeneratedKeyHolder.class))).andAnswer(new IAnswer<Integer>() {
        @Override
        public Integer answer() throws Throwable {
          GeneratedKeyHolder holder = (GeneratedKeyHolder) getCurrentArguments()[3];
          holder.addKey((Integer) 0);
          return 1;
        }
      });
  replay(conn);
  mappedCreate.insert(databaseType, conn, new Foo(), null);
}
origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testArgumentHolderDoubleSet() throws Exception {
  TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(databaseType, Foo.class);
  Dao<Foo, Integer> dao = createDao(Foo.class, false);
  MappedCreate<Foo, Integer> mappedCreate = MappedCreate.build(dao, tableInfo);
  DatabaseConnection conn = createMock(DatabaseConnection.class);
  expect(conn.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
      isA(GeneratedKeyHolder.class))).andAnswer(new IAnswer<Integer>() {
        @Override
        public Integer answer() throws Throwable {
          GeneratedKeyHolder holder = (GeneratedKeyHolder) getCurrentArguments()[3];
          holder.addKey((Integer) 1);
          holder.addKey((Integer) 2);
          return 1;
        }
      });
  replay(conn);
  mappedCreate.insert(databaseType, conn, new Foo(), null);
}
origin: j256/ormlite-core

@Test
public void testGeneratedId() throws Exception {
  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);
  databaseConnection.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
      isA(GeneratedKeyHolder.class));
  expectLastCall().andAnswer(new IAnswer<Object>() {
    @Override
    public Integer answer() throws Throwable {
      GeneratedKeyHolder keyHolder = (GeneratedKeyHolder) (getCurrentArguments()[3]);
      keyHolder.addKey(2);
      return 1;
    }
  });
  replay(databaseConnection);
  GeneratedId genIdSeq = new GeneratedId();
  se.create(databaseConnection, genIdSeq, null);
  verify(databaseConnection);
}
origin: j256/ormlite-core

  rowC = databaseConnection.insert(statement, args, argFieldTypes, keyHolder);
} catch (SQLException e) {
origin: com.j256.ormlite/ormlite-core

  rowC = databaseConnection.insert(statement, args, argFieldTypes, keyHolder);
} catch (SQLException e) {
com.j256.ormlite.supportDatabaseConnectioninsert

Javadoc

Perform a SQL update while with the associated SQL statement, arguments, and types. This will possibly return generated keys if kyeHolder is not null.

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.
  • 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
  • delete
    Perform a SQL delete with the associated SQL statement, arguments, and types.
  • rollback,
  • delete,
  • isClosed,
  • isTableExists,
  • queryForOne,
  • update,
  • releaseSavePoint

Popular in Java

  • Running tasks concurrently on multiple threads
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • setScale (BigDecimal)
  • getSystemService (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • 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