Search in sources :

Example 91 with ResultSet

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 92 with ResultSet

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 93 with ResultSet

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;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 94 with ResultSet

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;
}
Also used : JID(org.xmpp.packet.JID) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date) SQLException(java.sql.SQLException) Lock(java.util.concurrent.locks.Lock)

Example 95 with ResultSet

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);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) LinkedListNode(org.jivesoftware.util.LinkedListNode) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

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