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();
}
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);
}
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);
}
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);
}
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;
}
Aggregations