Search in sources :

Example 31 with CallableStatement

use of java.sql.CallableStatement in project binnavi by google.

the class PostgreSQLNativeViewCreator method createNativeCallgraphView.

/**
   * Creates the native call graph view of a module.
   * 
   * @param connection Connection to the database.
   * @param moduleId ID of the BinNavi module where the view is created.
   * 
   * @return The ID of the created view.
   * 
   * @throws SQLException Thrown if creating the view failed.
   */
public static int createNativeCallgraphView(final CConnection connection, final int moduleId) throws SQLException {
    Preconditions.checkNotNull(connection, "IE00706: connection argument can not be null");
    final String query = "{ ? = call create_native_call_graph_view(?) }";
    final CallableStatement call = connection.getConnection().prepareCall(query);
    call.registerOutParameter(1, Types.INTEGER);
    call.setInt(2, moduleId);
    call.execute();
    return call.getInt(1);
}
Also used : CallableStatement(java.sql.CallableStatement)

Example 32 with CallableStatement

use of java.sql.CallableStatement in project binnavi by google.

the class PostgreSQLNativeViewCreator method createNativeFlowgraphEdges.

/**
   * Creates the native flow graph edges of a module.
   * 
   * @param connection Connection to the database
   * @param rawModuleId ID of the raw module that provides the data.
   * @param moduleId ID of the BinNavi module where the edges are created.
   * 
   * @throws SQLException Thrown if creating the edges nodes failed.
   */
public static void createNativeFlowgraphEdges(final CConnection connection, final int rawModuleId, final int moduleId) throws SQLException {
    Preconditions.checkNotNull(connection, "IE01634: connection argument can not be null");
    final String query = " { call create_native_flowgraph_edges(?,?) }";
    final CallableStatement call = connection.getConnection().prepareCall(query);
    call.setInt(1, rawModuleId);
    call.setInt(2, moduleId);
    call.execute();
}
Also used : CallableStatement(java.sql.CallableStatement)

Example 33 with CallableStatement

use of java.sql.CallableStatement in project binnavi by google.

the class PostgreSQLNativeViewCreator method createNativeCallgraphEdges.

/**
   * Creates the edges of the native call graph of a module.
   * 
   * @param connection Connection to a BinNavi database.
   * @param rawModuleId ID of the raw module that provides the data.
   * @param moduleId ID of the BinNavi module where the edges are created.
   * 
   * @throws SQLException Thrown if creating the edges failed.
   */
public static void createNativeCallgraphEdges(final CConnection connection, final int rawModuleId, final int moduleId) throws SQLException {
    Preconditions.checkNotNull(connection, "IE01870: connection argument can not be null");
    final String query = " { call create_native_callgraph_edges(?, ?) } ";
    final CallableStatement call = connection.getConnection().prepareCall(query);
    call.setInt(1, rawModuleId);
    call.setInt(2, moduleId);
    call.execute();
}
Also used : CallableStatement(java.sql.CallableStatement)

Example 34 with CallableStatement

use of java.sql.CallableStatement in project hibernate-orm by hibernate.

the class PostgreSQLStoredProcedureTest method testFunctionWithJDBCByName.

@Test
public void testFunctionWithJDBCByName() {
    EntityManager entityManager = createEntityManager();
    entityManager.getTransaction().begin();
    try {
        Session session = entityManager.unwrap(Session.class);
        Long phoneCount = session.doReturningWork(new ReturningWork<Long>() {

            @Override
            public Long execute(Connection connection) throws SQLException {
                CallableStatement function = null;
                try {
                    function = connection.prepareCall("{ ? = call sp_count_phones(?) }");
                    function.registerOutParameter("phoneCount", Types.BIGINT);
                    function.setLong("personId", 1L);
                    function.execute();
                    return function.getLong(1);
                } finally {
                    if (function != null) {
                        function.close();
                    }
                }
            }
        });
        assertEquals(Long.valueOf(2), phoneCount);
    } catch (Exception e) {
        assertEquals(SQLFeatureNotSupportedException.class, e.getCause().getClass());
    } finally {
        entityManager.getTransaction().rollback();
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) SQLException(java.sql.SQLException) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) Session(org.hibernate.Session) Test(org.junit.Test)

Example 35 with CallableStatement

use of java.sql.CallableStatement in project hibernate-orm by hibernate.

the class PostgreSQLStoredProcedureTest method testFunctionWithJDBC.

@Test
public void testFunctionWithJDBC() {
    EntityManager entityManager = createEntityManager();
    entityManager.getTransaction().begin();
    try {
        Session session = entityManager.unwrap(Session.class);
        Long phoneCount = session.doReturningWork(new ReturningWork<Long>() {

            @Override
            public Long execute(Connection connection) throws SQLException {
                CallableStatement function = null;
                try {
                    function = connection.prepareCall("{ ? = call sp_count_phones(?) }");
                    function.registerOutParameter(1, Types.BIGINT);
                    function.setLong(2, 1L);
                    function.execute();
                    return function.getLong(1);
                } finally {
                    if (function != null) {
                        function.close();
                    }
                }
            }
        });
        assertEquals(Long.valueOf(2), phoneCount);
    } finally {
        entityManager.getTransaction().rollback();
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

CallableStatement (java.sql.CallableStatement)273 SQLException (java.sql.SQLException)138 Connection (java.sql.Connection)125 ResultSet (java.sql.ResultSet)60 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)45 DbConnection (com.axway.ats.core.dbaccess.DbConnection)28 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)22 ArrayList (java.util.ArrayList)22 PreparedStatement (java.sql.PreparedStatement)21 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)20 Timestamp (java.sql.Timestamp)18 Test (org.junit.Test)16 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)15 Statement (java.sql.Statement)14 HashMap (java.util.HashMap)10 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)8 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)7 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)6 BigInteger (java.math.BigInteger)6 OracleCallableStatement (oracle.jdbc.OracleCallableStatement)6