⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pubsubpersistencemanager.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            if (parent != null) {                // Check if the parent has already been loaded                parentNode = (CollectionNode) loadedNodes.get(parent);                if (parentNode == null) {                    // Parent is not in memory so try to load it                    Log.warn("Node not loaded due to missing parent. NodeID: " + nodeID);                    return;                }            }            if (leaf) {                // Retrieving a leaf node                node = new LeafNode(service, parentNode, nodeID, creator);            }            else {                // Retrieving a collection node                node = new CollectionNode(service, parentNode, nodeID, creator);            }            node.setCreationDate(new Date(Long.parseLong(rs.getString(3).trim())));            node.setModificationDate(new Date(Long.parseLong(rs.getString(4).trim())));            node.setPayloadDelivered(rs.getInt(6) == 1);            if (leaf) {                ((LeafNode) node).setMaxPayloadSize(rs.getInt(7));                ((LeafNode) node).setPersistPublishedItems(rs.getInt(8) == 1);                ((LeafNode) node).setMaxPublishedItems(rs.getInt(9));                ((LeafNode) node).setSendItemSubscribe(rs.getInt(14) == 1);            }            node.setNotifiedOfConfigChanges(rs.getInt(10) == 1);            node.setNotifiedOfDelete(rs.getInt(11) == 1);            node.setNotifiedOfRetract(rs.getInt(12) == 1);            node.setPresenceBasedDelivery(rs.getInt(13) == 1);            node.setPublisherModel(PublisherModel.valueOf(rs.getString(15)));            node.setSubscriptionEnabled(rs.getInt(16) == 1);            node.setSubscriptionConfigurationRequired(rs.getInt(17) == 1);            node.setAccessModel(AccessModel.valueOf(rs.getString(18)));            node.setPayloadType(rs.getString(19));            node.setBodyXSLT(rs.getString(20));            node.setDataformXSLT(rs.getString(21));            node.setDescription(rs.getString(23));            node.setLanguage(rs.getString(24));            node.setName(rs.getString(25));            if (rs.getString(26) != null) {                node.setReplyPolicy(Node.ItemReplyPolicy.valueOf(rs.getString(26)));            }            if (!leaf) {                ((CollectionNode) node).setAssociationPolicy(                        CollectionNode.LeafNodeAssociationPolicy.valueOf(rs.getString(27)));                ((CollectionNode) node).setMaxLeafNodes(rs.getInt(28));            }            // Add the load to the list of loaded nodes            loadedNodes.put(node.getNodeID(), node);        }        catch (SQLException sqle) {            Log.error(sqle);        }    }    private static void loadAssociatedJIDs(Map<String, Node> nodes, ResultSet rs) {        try {            String nodeID = decodeNodeID(rs.getString(1));            Node node = nodes.get(nodeID);            if (node == null) {                Log.warn("JID associated to a non-existent node: " + nodeID);                return;            }            JID jid = new JID(rs.getString(2));            String associationType = rs.getString(3);            if ("contacts".equals(associationType)) {                node.addContact(jid);            }            else if ("replyRooms".equals(associationType)) {                node.addReplyRoom(jid);            }            else if ("replyTo".equals(associationType)) {                node.addReplyTo(jid);            }            else if ("associationTrusted".equals(associationType)) {                ((CollectionNode) node).addAssociationTrusted(jid);            }        }        catch (Exception ex) {            Log.error(ex);        }    }    private static void loadAssociatedGroups(Map<String, Node> nodes, ResultSet rs) {        try {            String nodeID = decodeNodeID(rs.getString(1));            Node node = nodes.get(nodeID);            if (node == null) {                Log.warn("Roster Group associated to a non-existent node: " + nodeID);                return;            }            node.addAllowedRosterGroup(rs.getString(2));        }        catch (SQLException ex) {            Log.error(ex);        }    }    private static void loadAffiliations(Map<String, Node> nodes, ResultSet rs) {        try {            String nodeID = decodeNodeID(rs.getString(1));            Node node = nodes.get(nodeID);            if (node == null) {                Log.warn("Affiliations found for a non-existent node: " + nodeID);                return;            }            NodeAffiliate affiliate = new NodeAffiliate(node, new JID(rs.getString(2)));            affiliate.setAffiliation(NodeAffiliate.Affiliation.valueOf(rs.getString(3)));            node.addAffiliate(affiliate);        }        catch (SQLException sqle) {            Log.error(sqle);        }    }    private static void loadSubscriptions(PubSubService service, Map<String, Node> nodes,            ResultSet rs) {        try {            String nodeID = decodeNodeID(rs.getString(1));            Node node = nodes.get(nodeID);            if (node == null) {                Log.warn("Subscription found for a non-existent node: " + nodeID);                return;            }            String subID = rs.getString(2);            JID subscriber = new JID(rs.getString(3));            JID owner = new JID(rs.getString(4));            if (node.getAffiliate(owner) == null) {                Log.warn("Subscription found for a non-existent affiliate: " + owner +                        " in node: " + nodeID);                return;            }            NodeSubscription.State state = NodeSubscription.State.valueOf(rs.getString(5));            NodeSubscription subscription =                    new NodeSubscription(service, node, owner, subscriber, state, subID);            subscription.setShouldDeliverNotifications(rs.getInt(6) == 1);            subscription.setUsingDigest(rs.getInt(7) == 1);            subscription.setDigestFrequency(rs.getInt(8));            if (rs.getString(9) != null) {                subscription.setExpire(new Date(Long.parseLong(rs.getString(9).trim())));            }            subscription.setIncludingBody(rs.getInt(10) == 1);            subscription.setPresenceStates(decodeWithComma(rs.getString(11)));            subscription.setType(NodeSubscription.Type.valueOf(rs.getString(12)));            subscription.setDepth(rs.getInt(13));            subscription.setKeyword(rs.getString(14));            // Indicate the subscription that is has already been saved to the database            subscription.setSavedToDB(true);            node.addSubscription(subscription);        }        catch (SQLException sqle) {            Log.error(sqle);        }    }    private static void loadItems(Map<String, Node> nodes, ResultSet rs) {        SAXReader xmlReader = null;        try {            // Get a sax reader from the pool            xmlReader = xmlReaders.take();            String nodeID = decodeNodeID(rs.getString(5));            LeafNode node = (LeafNode) nodes.get(nodeID);            if (node == null) {                Log.warn("Published Item found for a non-existent node: " + nodeID);                return;            }            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            PublishedItem item = new PublishedItem(node, publisher, itemID, creationDate);            // Add the extra fields to the published item            if (rs.getString(4) != null) {                item.setPayload(                        xmlReader.read(new StringReader(rs.getString(4))).getRootElement());            }            // Add the published item to the node            node.addPublishedItem(item);        }        catch (Exception sqle) {            Log.error(sqle);        }        finally {            // Return the sax reader to the pool            if (xmlReader != null) {                xmlReaders.add(xmlReader);            }        }    }    /**     * Update the DB with the new affiliation of the user in the node.     *     * @param service   The pubsub service that is hosting the node.     * @param node      The node where the affiliation of the user was updated.     * @param affiliate The new affiliation of the user in the node.     * @param create    True if this is a new affiliate.     */    public static void saveAffiliation(PubSubService service, Node node, NodeAffiliate affiliate,            boolean create) {        Connection con = null;        PreparedStatement pstmt = null;        try {            con = DbConnectionManager.getConnection();            if (create) {                // Add the user to the generic affiliations table                pstmt = con.prepareStatement(ADD_AFFILIATION);                pstmt.setString(1, service.getServiceID());                pstmt.setString(2, encodeNodeID(node.getNodeID()));                pstmt.setString(3, affiliate.getJID().toString());                pstmt.setString(4, affiliate.getAffiliation().name());                pstmt.executeUpdate();            }            else {                // Update the affiliate's data in the backend store                pstmt = con.prepareStatement(UPDATE_AFFILIATION);                pstmt.setString(1, affiliate.getAffiliation().name());                pstmt.setString(2, service.getServiceID());                pstmt.setString(3, encodeNodeID(node.getNodeID()));                pstmt.setString(4, affiliate.getJID().toString());                pstmt.executeUpdate();            }        }        catch (SQLException sqle) {            Log.error(sqle);        }        finally {            try {if (pstmt != null) {pstmt.close();}}            catch (Exception e) {Log.error(e);}            try {if (con != null) {con.close();}}            catch (Exception e) {Log.error(e);}        }    }    /**     * Removes the affiliation and subsription state of the user from the DB.     *     * @param service   The pubsub service that is hosting the node.     * @param node      The node where the affiliation of the user was updated.     * @param affiliate The existing affiliation and subsription state of the user in the node.     */    public static void removeAffiliation(PubSubService service, Node node,            NodeAffiliate affiliate) {        Connection con = null;        PreparedStatement pstmt = null;        try {            con = DbConnectionManager.getConnection();            // Remove the affiliate from the table of node affiliates            pstmt = con.prepareStatement(DELETE_AFFILIATION);            pstmt.setString(1, service.getServiceID());            pstmt.setString(2, encodeNodeID(node.getNodeID()));            pstmt.setString(3, affiliate.getJID().toString());            pstmt.executeUpdate();        }        catch (SQLException sqle) {            Log.error(sqle);        }        finally {            try {if (pstmt != null) {pstmt.close();}}            catch (Exception e) {Log.error(e);}            try {if (con != null) {con.close();}}            catch (Exception e) {Log.error(e);}        }    }    /**     * Updates the DB with the new subsription of the user to the node.     *     * @param service   The pubsub service that is hosting the node.     * @param node      The node where the user has subscribed to.     * @param subscription The new subscription of the user to the node.     * @param create    True if this is a new affiliate.     */    public static void saveSubscription(PubSubService service, Node node,            NodeSubscription subscription, boolean create) {        Connection con = null;        PreparedStatement pstmt = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -