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

📄 pubsubpersistencemanager.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            catch (Exception e) { Log.error(e); }            try { if (con != null) con.close(); }            catch (Exception e) { Log.error(e); }        }        return config;    }    /**     * Creates a new default node configuration for the specified service.     *     * @param service the default node configuration used by this pubsub service.     * @param config the default node configuration to create in the database.     */    public static void createDefaultConfiguration(PubSubService service,            DefaultNodeConfiguration config) {        Connection con = null;        PreparedStatement pstmt = null;        try {            con = DbConnectionManager.getConnection();            pstmt = con.prepareStatement(ADD_DEFAULT_CONF);            pstmt.setString(1, service.getServiceID());            pstmt.setInt(2, (config.isLeaf() ? 1 : 0));            pstmt.setInt(3, (config.isDeliverPayloads() ? 1 : 0));            pstmt.setInt(4, config.getMaxPayloadSize());            pstmt.setInt(5, (config.isPersistPublishedItems() ? 1 : 0));            pstmt.setInt(6, config.getMaxPublishedItems());            pstmt.setInt(7, (config.isNotifyConfigChanges() ? 1 : 0));            pstmt.setInt(8, (config.isNotifyDelete() ? 1 : 0));            pstmt.setInt(9, (config.isNotifyRetract() ? 1 : 0));            pstmt.setInt(10, (config.isPresenceBasedDelivery() ? 1 : 0));            pstmt.setInt(11, (config.isSendItemSubscribe() ? 1 : 0));            pstmt.setString(12, config.getPublisherModel().getName());            pstmt.setInt(13, (config.isSubscriptionEnabled() ? 1 : 0));            pstmt.setString(14, config.getAccessModel().getName());            pstmt.setString(15, config.getLanguage());            if (config.getReplyPolicy() != null) {                pstmt.setString(16, config.getReplyPolicy().name());            }            else {                pstmt.setString(16, null);            }            pstmt.setString(17, config.getAssociationPolicy().name());            pstmt.setInt(18, config.getMaxLeafNodes());            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 default node configuration for the specified service.     *     * @param service the default node configuration used by this pubsub service.     * @param config the default node configuration to update in the database.     */    public static void updateDefaultConfiguration(PubSubService service,            DefaultNodeConfiguration config) {        Connection con = null;        PreparedStatement pstmt = null;        try {            con = DbConnectionManager.getConnection();            pstmt = con.prepareStatement(UPDATE_DEFAULT_CONF);            pstmt.setInt(1, (config.isDeliverPayloads() ? 1 : 0));            pstmt.setInt(2, config.getMaxPayloadSize());            pstmt.setInt(3, (config.isPersistPublishedItems() ? 1 : 0));            pstmt.setInt(4, config.getMaxPublishedItems());            pstmt.setInt(5, (config.isNotifyConfigChanges() ? 1 : 0));            pstmt.setInt(6, (config.isNotifyDelete() ? 1 : 0));            pstmt.setInt(7, (config.isNotifyRetract() ? 1 : 0));            pstmt.setInt(8, (config.isPresenceBasedDelivery() ? 1 : 0));            pstmt.setInt(9, (config.isSendItemSubscribe() ? 1 : 0));            pstmt.setString(10, config.getPublisherModel().getName());            pstmt.setInt(11, (config.isSubscriptionEnabled() ? 1 : 0));            pstmt.setString(12, config.getAccessModel().getName());            pstmt.setString(13, config.getLanguage());            if (config.getReplyPolicy() != null) {                pstmt.setString(14, config.getReplyPolicy().name());            }            else {                pstmt.setString(14, null);            }            pstmt.setString(15, config.getAssociationPolicy().name());            pstmt.setInt(16, config.getMaxLeafNodes());            pstmt.setString(17, service.getServiceID());            pstmt.setInt(18, (config.isLeaf() ? 1 : 0));            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);}        }    }    /*public static Node loadNode(PubSubService service, String nodeID) {        Connection con = null;        Node node = null;        try {            con = DbConnectionManager.getConnection();            node = loadNode(service, nodeID, con);        }        catch (SQLException sqle) {            Log.error(sqle);        }        finally {            try { if (con != null) con.close(); }            catch (Exception e) { Log.error(e); }        }        return node;    }    private static Node loadNode(PubSubService service, String nodeID, Connection con) {        Node node = null;        PreparedStatement pstmt = null;        try {            pstmt = con.prepareStatement(LOAD_NODE);            pstmt.setString(1, encodeNodeID(nodeID));            ResultSet rs = pstmt.executeQuery();            if (!rs.next()) {                // No node was found for the specified nodeID so return null                return null;            }            boolean leaf = rs.getInt(1) == 1;            String parent = decodeNodeID(rs.getString(4));            JID creator = new JID(rs.getString(20));            CollectionNode parentNode = null;            if (parent != null) {                // Check if the parent has already been loaded                parentNode = (CollectionNode) service.getNode(parent);                if (parentNode == null) {                    // Parent is not in memory so try to load it                    synchronized (parent.intern()) {                        // Check again if parent has not been already loaded (concurrency issues)                        parentNode = (CollectionNode) service.getNode(parent);                        if (parentNode == null) {                            // Parent was never loaded so load it from the database now                            parentNode = (CollectionNode) loadNode(service, parent, con);                        }                    }                }            }            if (leaf) {                // Retrieving a leaf node                node = new LeafNode(parentNode, nodeID, creator);            }            else {                // Retrieving a collection node                node = new CollectionNode(parentNode, nodeID, creator);            }            node.setCreationDate(new Date(Long.parseLong(rs.getString(2).trim())));            node.setModificationDate(new Date(Long.parseLong(rs.getString(3).trim())));            node.setPayloadDelivered(rs.getInt(5) == 1);            node.setMaxPayloadSize(rs.getInt(6));            node.setPersistPublishedItems(rs.getInt(7) == 1);            node.setMaxPublishedItems(rs.getInt(8));            node.setNotifiedOfConfigChanges(rs.getInt(9) == 1);            node.setNotifiedOfDelete(rs.getInt(10) == 1);            node.setNotifiedOfRetract(rs.getInt(11) == 1);            node.setPresenceBasedDelivery(rs.getInt(12) == 1);            node.setSendItemSubscribe(rs.getInt(13) == 1);            node.setPublisherModel(Node.PublisherModel.valueOf(rs.getString(14)));            node.setSubscriptionEnabled(rs.getInt(15) == 1);            node.setAccessModel(Node.AccessModel.valueOf(rs.getString(16)));            node.setPayloadType(rs.getString(17));            node.setBodyXSLT(rs.getString(18));            node.setDataformXSLT(rs.getString(19));            node.setDescription(rs.getString(21));            node.setLanguage(rs.getString(22));            node.setName(rs.getString(23));            rs.close();            pstmt.close();            pstmt = con.prepareStatement(LOAD_HISTORY);            // Recreate the history until two days ago            long from = System.currentTimeMillis() - (86400000 * 2);            pstmt.setString(1, StringUtils.dateToMillis(new Date(from)));            pstmt.setLong(2, room.getID());            rs = pstmt.executeQuery();            while (rs.next()) {                String senderJID = rs.getString(1);                String nickname = rs.getString(2);                Date sentDate = new Date(Long.parseLong(rs.getString(3).trim()));                String subject = rs.getString(4);                String body = rs.getString(5);                // Recreate the history only for the rooms that have the conversation logging                // enabled                if (room.isLogEnabled()) {                    room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject,                            body);                }            }            rs.close();            pstmt.close();            pstmt = con.prepareStatement(LOAD_NODE_AFFILIATIONS);            pstmt.setString(1, encodeNodeID(node.getNodeID()));            rs = pstmt.executeQuery();            while (rs.next()) {                NodeAffiliate affiliate = new NodeAffiliate(new JID(rs.getString(1)));                affiliate.setAffiliation(NodeAffiliate.Affiliation.valueOf(rs.getString(2)));                affiliate.setSubscription(NodeAffiliate.State.valueOf(rs.getString(3)));                node.addAffiliate(affiliate);            }            rs.close();            // Set now that the room's configuration is updated in the database. Note: We need to            // set this now since otherwise the room's affiliations will be saved to the database            // "again" while adding them to the room!            node.setSavedToDB(true);            // Add the retrieved node to the pubsub service            service.addChildNode(node);        }        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); }        }        return node;    }*/    private static String encodeWithComma(Collection<String> strings) {        StringBuilder sb = new StringBuilder(90);        for (String group : strings) {            sb.append(group).append(",");        }        if (!strings.isEmpty()) {            sb.setLength(sb.length()-1);        }        else {            // Add a blank so an empty string is never replaced with NULL (oracle...arggg!!!)            sb.append(" ");        }        return sb.toString();    }    private static Collection<String> decodeWithComma(String strings) {        Collection<String> decodedStrings = new ArrayList<String>();        StringTokenizer tokenizer = new StringTokenizer(strings.trim(), ",");        while (tokenizer.hasMoreTokens()) {            decodedStrings.add(tokenizer.nextToken());        }        return decodedStrings;    }    private static String encodeNodeID(String nodeID) {        if (DbConnectionManager.getDatabaseType() == DbConnectionManager.DatabaseType.oracle &&                "".equals(nodeID)) {            // Oracle stores empty strings as null so return a string with a space            return " ";        }        return nodeID;    }    private static String decodeNodeID(String nodeID) {        if (DbConnectionManager.getDatabaseType() == DbConnectionManager.DatabaseType.oracle &&                " ".equals(nodeID)) {            // Oracle stores empty strings as null so convert them back to empty strings            return "";        }        return nodeID;    }}

⌨️ 快捷键说明

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