use of java.sql.ResultSet in project Openfire by igniterealtime.
the class JiveLiveProperties method loadProperties.
private void loadProperties() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement("SELECT name,propValue FROM " + tableName + " WHERE ownerID=?");
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
while (rs.next()) {
properties.put(rs.getString(1), DbConnectionManager.getLargeTextField(rs, 2));
}
} catch (SQLException ex) {
Log.error(ex.getMessage(), ex);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
use of java.sql.ResultSet in project Openfire by igniterealtime.
the class DatabaseManager method getLogsByDateAndLimit.
/**
* Returns a list of LogEntry's ordered by date desc
*
* @param olderThan
* unix timestamp in ms
* @param limit
* num of rows max
* @param component
* the specified subdomain of the logged component
* @return Collection of {@link LogEntry}
*/
public Collection<LogEntry> getLogsByDateAndLimit(long olderThan, int limit, String component) {
List<LogEntry> result = new ArrayList<LogEntry>();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_LOGS_DATE_LIMIT_COMPONENT);
pstmt.setLong(1, olderThan);
pstmt.setString(2, component);
pstmt.setInt(3, limit);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String from = rs.getString(4);
String to = rs.getString(5);
String type = rs.getString(3);
long date = rs.getLong(2);
LogEntry res = new LogEntry(from, to, type, date, component);
result.add(res);
}
pstmt.close();
} catch (SQLException sqle) {
Log.error(sqle);
} finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return result;
}
use of java.sql.ResultSet in project Openfire by igniterealtime.
the class PEPServiceManager method loadPEPServiceFromDB.
/**
* Loads a PEP service from the database, if it exists.
*
* @param jid
* the JID of the owner of the PEP service.
* @return the loaded PEP service, or null if not found.
*/
private PEPService loadPEPServiceFromDB(String jid) {
PEPService pepService = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
// Get all PEP services
pstmt = con.prepareStatement(GET_PEP_SERVICE);
pstmt.setString(1, jid);
rs = pstmt.executeQuery();
// Restore old PEPServices
while (rs.next()) {
String serviceID = rs.getString(1);
// Create a new PEPService
pepService = new PEPService(XMPPServer.getInstance(), serviceID);
pepServices.put(serviceID, pepService);
pubSubEngine.start(pepService);
if (Log.isDebugEnabled()) {
Log.debug("PEP: Restored service for " + serviceID + " from the database.");
}
}
} catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return pepService;
}
use of java.sql.ResultSet in project Openfire by igniterealtime.
the class PubSubPersistenceManager method getLastPublishedItem.
/**
* Fetches the last published item for the specified node.
*
* @param node the leaf node to load its last published items.
*/
public static PublishedItem getLastPublishedItem(LeafNode node) {
Lock itemLock = CacheFactory.getLock(ITEM_CACHE, itemCache);
try {
// NOTE: force other requests to wait for DB I/O to complete
itemLock.lock();
flushPendingItems();
} finally {
itemLock.unlock();
}
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
PublishedItem item = null;
try {
con = DbConnectionManager.getConnection();
// Get published items of the specified node
pstmt = con.prepareStatement(LOAD_LAST_ITEM);
pstmt.setFetchSize(1);
pstmt.setMaxRows(1);
pstmt.setString(1, node.getService().getServiceID());
pstmt.setString(2, encodeNodeID(node.getNodeID()));
rs = pstmt.executeQuery();
// Rebuild loaded published items
if (rs.next()) {
String itemID = rs.getString(1);
JID publisher = new JID(rs.getString(2));
Date creationDate = new Date(Long.parseLong(rs.getString(3).trim()));
// Create the item
item = new PublishedItem(node, publisher, itemID, creationDate);
// Add the extra fields to the published item
if (rs.getString(4) != null) {
item.setPayloadXML(rs.getString(4));
}
}
} catch (Exception sqle) {
log.error(sqle.getMessage(), sqle);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return item;
}
use of java.sql.ResultSet in project Openfire by igniterealtime.
the class PubSubPersistenceManager method loadSubscription.
public static void loadSubscription(PubSubService service, Node node, String subId) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Map<String, Node> nodes = new HashMap<>();
nodes.put(node.getNodeID(), node);
try {
con = DbConnectionManager.getConnection();
// Get subscriptions to all nodes
pstmt = con.prepareStatement(LOAD_NODE_SUBSCRIPTION);
pstmt.setString(1, service.getServiceID());
pstmt.setString(2, node.getNodeID());
pstmt.setString(3, subId);
rs = pstmt.executeQuery();
// Add to each node the corresponding subscription
if (rs.next()) {
loadSubscriptions(service, nodes, rs);
}
} catch (SQLException sqle) {
log.error(sqle.getMessage(), sqle);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
Aggregations