Search in sources :

Example 66 with ResultSet

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

the class AutoDiscoveryTest method testDialectGetColumnAliasExtractor.

@Test
public void testDialectGetColumnAliasExtractor() throws Exception {
    Session session = openSession();
    final SessionImplementor sessionImplementor = (SessionImplementor) session;
    session.beginTransaction();
    session.doWork(new Work() {

        @Override
        public void execute(Connection connection) throws SQLException {
            PreparedStatement ps = sessionImplementor.getJdbcCoordinator().getStatementPreparer().prepareStatement(QUERY_STRING);
            ResultSet rs = sessionImplementor.getJdbcCoordinator().getResultSetReturn().extract(ps);
            try {
                ResultSetMetaData metadata = rs.getMetaData();
                String column1Alias = getDialect().getColumnAliasExtractor().extractColumnAlias(metadata, 1);
                String column2Alias = getDialect().getColumnAliasExtractor().extractColumnAlias(metadata, 2);
                Assert.assertFalse("bad dialect.getColumnAliasExtractor impl", column1Alias.equals(column2Alias));
            } finally {
                sessionImplementor.getJdbcCoordinator().getResourceRegistry().release(rs, ps);
                sessionImplementor.getJdbcCoordinator().getResourceRegistry().release(ps);
            }
        }
    });
    session.getTransaction().commit();
    session.close();
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) Work(org.hibernate.jdbc.Work) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) PreparedStatement(java.sql.PreparedStatement) Session(org.hibernate.Session) Test(org.junit.Test)

Example 67 with ResultSet

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

the class StringValueMappingTest method testNormalVarcharHandling.

@Test
public void testNormalVarcharHandling() throws SQLException {
    final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor(stringJavaDescriptor);
    final ValueBinder<String> binder = varcharSqlDescriptor.getBinder(stringJavaDescriptor);
    final String fixture = "string value";
    ResultSet resultSet = ResultSetProxy.generateProxy(fixture);
    final String value = extractor.extract(resultSet, COLUMN_NAME, wrapperOptions);
    assertEquals(fixture, value);
    PreparedStatement ps = PreparedStatementProxy.generateProxy(fixture);
    binder.bind(ps, fixture, BIND_POSITION, wrapperOptions);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 68 with ResultSet

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

the class StringValueMappingTest method testNullVarcharHandling.

@Test
public void testNullVarcharHandling() throws SQLException {
    final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor(stringJavaDescriptor);
    final ValueBinder<String> binder = varcharSqlDescriptor.getBinder(stringJavaDescriptor);
    final String fixture = null;
    ResultSet resultSet = ResultSetProxy.generateProxy(fixture);
    final String value = extractor.extract(resultSet, COLUMN_NAME, wrapperOptions);
    assertEquals(fixture, value);
    PreparedStatement ps = PreparedStatementProxy.generateProxy(fixture);
    binder.bind(ps, fixture, BIND_POSITION, wrapperOptions);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 69 with ResultSet

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

the class StringValueMappingTest method testNormalClobHandling.

@Test
public void testNormalClobHandling() throws SQLException {
    final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor(stringJavaDescriptor);
    final ValueBinder<String> binder = clobSqlDescriptor.getBinder(stringJavaDescriptor);
    final String fixture = "clob string";
    final Clob clob = new StringClobImpl(fixture);
    ResultSet resultSet = ResultSetProxy.generateProxy(clob);
    final String value = extractor.extract(resultSet, COLUMN_NAME, wrapperOptions);
    assertEquals(fixture, value);
    PreparedStatement ps = PreparedStatementProxy.generateProxy(clob);
    binder.bind(ps, fixture, BIND_POSITION, wrapperOptions);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Clob(java.sql.Clob) Test(org.junit.Test)

Example 70 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class ArchiveIndexer method rebuildIndex.

/**
     * Rebuilds the search index with all archived conversation data. This method returns
     * a Future that represents the status of the index rebuild process (also available
     * via {@link #getIndexRebuildProgress()}). The integer value
     * (values 0 through 100) represents the percentage of work done. If message archiving
     * is disabled, this method will return <tt>null</tt>.
     *
     * @return a Future to indicate the status of rebuilding the index or <tt>null</tt> if
     *      rebuilding the index is not possible.
     */
public synchronized Future<Integer> rebuildIndex() {
    // Immediately return if the service has been stopped.
    if (stopped) {
        return null;
    }
    // If a rebuild is already happening, return.
    if (rebuildInProgress) {
        return null;
    }
    rebuildInProgress = true;
    // Do nothing if archiving is disabled.
    if (!conversationManager.isArchivingEnabled()) {
        return null;
    }
    // Create a future to track the index rebuild progress.
    rebuildFuture = new RebuildFuture();
    // Create a runnable that will perform the actual rebuild work.
    Runnable rebuildTask = new Runnable() {

        public void run() {
            List<Long> conversationIDs = new ArrayList<Long>();
            Map<Long, Boolean> externalMetaData = new HashMap<Long, Boolean>();
            Connection con = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            try {
                con = DbConnectionManager.getConnection();
                pstmt = con.prepareStatement(ALL_CONVERSATIONS);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    long conversationID = rs.getLong(1);
                    conversationIDs.add(conversationID);
                    externalMetaData.put(conversationID, rs.getInt(2) == 1);
                }
            } catch (SQLException sqle) {
                Log.error(sqle.getMessage(), sqle);
            } finally {
                DbConnectionManager.closeConnection(rs, pstmt, con);
            }
            if (!conversationIDs.isEmpty()) {
                // Index the conversations.
                writerLock.lock();
                IndexModifier writer = null;
                try {
                    writer = new IndexModifier(directory, new StandardAnalyzer(), true);
                    long newestDate = indexConversations(conversationIDs, externalMetaData, writer, true);
                    writer.optimize();
                    // Done indexing so store a last modified date.
                    if (newestDate != -1) {
                        lastModified = newestDate;
                        indexProperties.setProperty("lastModified", Long.toString(lastModified));
                    }
                } catch (IOException ioe) {
                    Log.error(ioe.getMessage(), ioe);
                } finally {
                    if (writer != null) {
                        try {
                            writer.close();
                        } catch (Exception e) {
                            Log.error(e.getMessage(), e);
                        }
                    }
                    writerLock.unlock();
                }
            }
            // Done rebuilding the index, so reset state.
            rebuildFuture = null;
            rebuildInProgress = false;
        }
    };
    taskEngine.submit(rebuildTask);
    return rebuildFuture;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) IndexModifier(org.apache.lucene.index.IndexModifier) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) ResultSet(java.sql.ResultSet)

Aggregations

ResultSet (java.sql.ResultSet)15888 PreparedStatement (java.sql.PreparedStatement)9451 SQLException (java.sql.SQLException)6466 Connection (java.sql.Connection)6445 Statement (java.sql.Statement)4619 Test (org.junit.Test)3647 ArrayList (java.util.ArrayList)2376 Properties (java.util.Properties)1233 HashMap (java.util.HashMap)639 ResultSetMetaData (java.sql.ResultSetMetaData)620 CallableStatement (java.sql.CallableStatement)580 DatabaseMetaData (java.sql.DatabaseMetaData)499 IOException (java.io.IOException)438 List (java.util.List)433 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)414 Timestamp (java.sql.Timestamp)363 Map (java.util.Map)359 BigDecimal (java.math.BigDecimal)350 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)292 HashSet (java.util.HashSet)247