PubSubPersistenceManager.java 61.4 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5 6 7 8 9 10 11
/**
 * $RCSfile: $
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
 */

12
package org.jivesoftware.openfire.pubsub;
Matt Tucker's avatar
Matt Tucker committed
13 14 15

import org.dom4j.io.SAXReader;
import org.jivesoftware.database.DbConnectionManager;
16 17
import org.jivesoftware.openfire.pubsub.models.AccessModel;
import org.jivesoftware.openfire.pubsub.models.PublisherModel;
18 19
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
Matt Tucker's avatar
Matt Tucker committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
import org.xmpp.packet.JID;

import java.io.StringReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * A manager responsible for ensuring node persistence.
 *
 * @author Matt Tucker
 */
public class PubSubPersistenceManager {

38
    private static final String LOAD_NON_LEAF_NODES =
Matt Tucker's avatar
Matt Tucker committed
39 40 41
            "SELECT nodeID, leaf, creationDate, modificationDate, parent, deliverPayloads, " +
            "maxPayloadSize, persistItems, maxItems, notifyConfigChanges, notifyDelete, " +
            "notifyRetract, presenceBased, sendItemSubscribe, publisherModel, " +
42 43
            "subscriptionEnabled, configSubscription, accessModel, payloadType, " +
            "bodyXSLT, dataformXSLT, creator, description, language, name, " +
44
            "replyPolicy, associationPolicy, maxLeafNodes FROM ofPubsubNode " +
45 46 47 48 49 50 51
            "WHERE serviceID=? AND leaf=0 ORDER BY nodeID";
    private static final String LOAD_LEAF_NODES =
            "SELECT nodeID, leaf, creationDate, modificationDate, parent, deliverPayloads, " +
            "maxPayloadSize, persistItems, maxItems, notifyConfigChanges, notifyDelete, " +
            "notifyRetract, presenceBased, sendItemSubscribe, publisherModel, " +
            "subscriptionEnabled, configSubscription, accessModel, payloadType, " +
            "bodyXSLT, dataformXSLT, creator, description, language, name, " +
52
            "replyPolicy, associationPolicy, maxLeafNodes FROM ofPubsubNode " +
53
            "WHERE serviceID=? AND leaf=1 ORDER BY nodeID";
Matt Tucker's avatar
Matt Tucker committed
54
    private static final String UPDATE_NODE =
55
            "UPDATE ofPubsubNode SET modificationDate=?, parent=?, deliverPayloads=?, " +
Matt Tucker's avatar
Matt Tucker committed
56 57 58
            "maxPayloadSize=?, persistItems=?, maxItems=?, " +
            "notifyConfigChanges=?, notifyDelete=?, notifyRetract=?, presenceBased=?, " +
            "sendItemSubscribe=?, publisherModel=?, subscriptionEnabled=?, configSubscription=?, " +
59 60
            "accessModel=?, payloadType=?, bodyXSLT=?, dataformXSLT=?, description=?, " +
            "language=?, name=?, replyPolicy=?, associationPolicy=?, maxLeafNodes=? " +
Matt Tucker's avatar
Matt Tucker committed
61 62
            "WHERE serviceID=? AND nodeID=?";
    private static final String ADD_NODE =
63
            "INSERT INTO ofPubsubNode (serviceID, nodeID, leaf, creationDate, modificationDate, " +
Matt Tucker's avatar
Matt Tucker committed
64 65 66
            "parent, deliverPayloads, maxPayloadSize, persistItems, maxItems, " +
            "notifyConfigChanges, notifyDelete, notifyRetract, presenceBased, " +
            "sendItemSubscribe, publisherModel, subscriptionEnabled, configSubscription, " +
67 68 69
            "accessModel, payloadType, bodyXSLT, dataformXSLT, creator, description, " +
            "language, name, replyPolicy, associationPolicy, maxLeafNodes) " +
            "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Matt Tucker's avatar
Matt Tucker committed
70
    private static final String DELETE_NODE =
71
            "DELETE FROM ofPubsubNode WHERE serviceID=? AND nodeID=?";
Matt Tucker's avatar
Matt Tucker committed
72

73
    private static final String LOAD_NODES_JIDS =
74
            "SELECT nodeID, jid, associationType FROM ofPubsubNodeJIDs WHERE serviceID=?";
75
    private static final String ADD_NODE_JIDS =
76
            "INSERT INTO ofPubsubNodeJIDs (serviceID, nodeID, jid, associationType) " +
77 78
            "VALUES (?,?,?,?)";
    private static final String DELETE_NODE_JIDS =
79
            "DELETE FROM ofPubsubNodeJIDs WHERE serviceID=? AND nodeID=?";
80 81

    private static final String LOAD_NODES_GROUPS =
82
            "SELECT nodeID, rosterGroup FROM ofPubsubNodeGroups WHERE serviceID=?";
83
    private static final String ADD_NODE_GROUPS =
84
            "INSERT INTO ofPubsubNodeGroups (serviceID, nodeID, rosterGroup) " +
85 86
            "VALUES (?,?,?)";
    private static final String DELETE_NODE_GROUPS =
87
            "DELETE FROM ofPubsubNodeGroups WHERE serviceID=? AND nodeID=?";
88

Matt Tucker's avatar
Matt Tucker committed
89
    private static final String LOAD_AFFILIATIONS =
90
            "SELECT nodeID,jid,affiliation FROM ofPubsubAffiliation WHERE serviceID=? " +
Matt Tucker's avatar
Matt Tucker committed
91 92
            "ORDER BY nodeID";
    private static final String ADD_AFFILIATION =
93
            "INSERT INTO ofPubsubAffiliation (serviceID,nodeID,jid,affiliation) VALUES (?,?,?,?)";
Matt Tucker's avatar
Matt Tucker committed
94
    private static final String UPDATE_AFFILIATION =
95
            "UPDATE ofPubsubAffiliation SET affiliation=? WHERE serviceID=? AND nodeID=? AND jid=?";
Matt Tucker's avatar
Matt Tucker committed
96
    private static final String DELETE_AFFILIATION =
97
            "DELETE FROM ofPubsubAffiliation WHERE serviceID=? AND nodeID=? AND jid=?";
Matt Tucker's avatar
Matt Tucker committed
98
    private static final String DELETE_AFFILIATIONS =
99
            "DELETE FROM ofPubsubAffiliation WHERE serviceID=? AND nodeID=?";
Matt Tucker's avatar
Matt Tucker committed
100 101

    private static final String LOAD_SUBSCRIPTIONS =
Matt Tucker's avatar
Matt Tucker committed
102 103
            "SELECT nodeID, id, jid, owner, state, deliver, digest, digest_frequency, " +
            "expire, includeBody, showValues, subscriptionType, subscriptionDepth, " +
104
            "keyword FROM ofPubsubSubscription WHERE serviceID=? ORDER BY nodeID";
Matt Tucker's avatar
Matt Tucker committed
105
    private static final String ADD_SUBSCRIPTION =
106
            "INSERT INTO ofPubsubSubscription (serviceID, nodeID, id, jid, owner, state, " +
Matt Tucker's avatar
Matt Tucker committed
107
            "deliver, digest, digest_frequency, expire, includeBody, showValues, " +
Matt Tucker's avatar
Matt Tucker committed
108
            "subscriptionType, subscriptionDepth, keyword) " +
Matt Tucker's avatar
Matt Tucker committed
109
            "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Matt Tucker's avatar
Matt Tucker committed
110
    private static final String UPDATE_SUBSCRIPTION =
111
            "UPDATE ofPubsubSubscription SET owner=?, state=?, deliver=?, digest=?, " +
Matt Tucker's avatar
Matt Tucker committed
112 113 114
            "digest_frequency=?, expire=?, includeBody=?, showValues=?, subscriptionType=?, " +
            "subscriptionDepth=?, keyword=? WHERE serviceID=? AND nodeID=? AND id=?";
    private static final String DELETE_SUBSCRIPTION =
115
            "DELETE FROM ofPubsubSubscription WHERE serviceID=? AND nodeID=? AND id=?";
Matt Tucker's avatar
Matt Tucker committed
116
    private static final String DELETE_SUBSCRIPTIONS =
117
            "DELETE FROM ofPubsubSubscription WHERE serviceID=? AND nodeID=?";
Matt Tucker's avatar
Matt Tucker committed
118

Matt Tucker's avatar
Matt Tucker committed
119
    private static final String LOAD_ALL_ITEMS =
120
            "SELECT id,jid,creationDate,payload,nodeID FROM ofPubsubItem " +
Matt Tucker's avatar
Matt Tucker committed
121
            "WHERE serviceID=? ORDER BY creationDate";
Matt Tucker's avatar
Matt Tucker committed
122
    private static final String LOAD_ITEMS =
123
            "SELECT id,jid,creationDate,payload FROM ofPubsubItem " +
Matt Tucker's avatar
Matt Tucker committed
124 125
            "WHERE serviceID=? AND nodeID=? ORDER BY creationDate";
    private static final String ADD_ITEM =
126
            "INSERT INTO ofPubsubItem (serviceID,nodeID,id,jid,creationDate,payload) " +
Matt Tucker's avatar
Matt Tucker committed
127 128
            "VALUES (?,?,?,?,?,?)";
    private static final String DELETE_ITEM =
129
            "DELETE FROM ofPubsubItem WHERE serviceID=? AND nodeID=? AND id=?";
Matt Tucker's avatar
Matt Tucker committed
130
    private static final String DELETE_ITEMS =
131
            "DELETE FROM ofPubsubItem WHERE serviceID=? AND nodeID=?";
Matt Tucker's avatar
Matt Tucker committed
132 133 134 135 136 137

    private static final String LOAD_DEFAULT_CONF =
            "SELECT deliverPayloads, maxPayloadSize, persistItems, maxItems, " +
            "notifyConfigChanges, notifyDelete, notifyRetract, presenceBased, " +
            "sendItemSubscribe, publisherModel, subscriptionEnabled, accessModel, language, " +
            "replyPolicy, associationPolicy, maxLeafNodes " +
138
            "FROM ofPubsubDefaultConf WHERE serviceID=? AND leaf=?";
Matt Tucker's avatar
Matt Tucker committed
139
    private static final String UPDATE_DEFAULT_CONF =
140
            "UPDATE ofPubsubDefaultConf SET deliverPayloads=?, maxPayloadSize=?, persistItems=?, " +
Matt Tucker's avatar
Matt Tucker committed
141 142 143 144 145
            "maxItems=?, notifyConfigChanges=?, notifyDelete=?, notifyRetract=?, " +
            "presenceBased=?, sendItemSubscribe=?, publisherModel=?, subscriptionEnabled=?, " +
            "accessModel=?, language=? replyPolicy=?, associationPolicy=?, maxLeafNodes=? " +
            "WHERE serviceID=? AND leaf=?";
    private static final String ADD_DEFAULT_CONF =
146
            "INSERT INTO ofPubsubDefaultConf (serviceID, leaf, deliverPayloads, maxPayloadSize, " +
Matt Tucker's avatar
Matt Tucker committed
147 148 149 150 151 152 153 154 155 156 157 158 159
            "persistItems, maxItems, notifyConfigChanges, notifyDelete, notifyRetract, " +
            "presenceBased, sendItemSubscribe, publisherModel, subscriptionEnabled, " +
            "accessModel, language, replyPolicy, associationPolicy, maxLeafNodes) " +
            "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

    /**
     * Pool of SAX Readers. SAXReader is not thread safe so we need to have a pool of readers.
     */
    private static BlockingQueue<SAXReader> xmlReaders = new LinkedBlockingQueue<SAXReader>();

    static {
        // Initialize the pool of sax readers
        for (int i=0; i<50; i++) {
160 161 162
            SAXReader xmlReader = new SAXReader();
            xmlReader.setEncoding("UTF-8");
            xmlReaders.add(xmlReader);
Matt Tucker's avatar
Matt Tucker committed
163 164 165 166 167 168 169 170 171 172 173 174
        }
    }

    /**
     * Creates and stores the node configuration in the database.
     *
     * @param service The pubsub service that is hosting the node.
     * @param node The newly created node.
     */
    public static void createNode(PubSubService service, Node node) {
        Connection con = null;
        PreparedStatement pstmt = null;
175
        boolean abortTransaction = false;
Matt Tucker's avatar
Matt Tucker committed
176
        try {
177
            con = DbConnectionManager.getTransactionConnection();
Matt Tucker's avatar
Matt Tucker committed
178 179
            pstmt = con.prepareStatement(ADD_NODE);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
180
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
181 182 183
            pstmt.setInt(3, (node.isCollectionNode() ? 0 : 1));
            pstmt.setString(4, StringUtils.dateToMillis(node.getCreationDate()));
            pstmt.setString(5, StringUtils.dateToMillis(node.getModificationDate()));
Matt Tucker's avatar
Matt Tucker committed
184
            pstmt.setString(6, node.getParent() != null ? encodeNodeID(node.getParent().getNodeID()) : null);
Matt Tucker's avatar
Matt Tucker committed
185
            pstmt.setInt(7, (node.isPayloadDelivered() ? 1 : 0));
Matt Tucker's avatar
Matt Tucker committed
186 187 188 189 190 191 192 193 194 195
            if (!node.isCollectionNode()) {
                pstmt.setInt(8, ((LeafNode) node).getMaxPayloadSize());
                pstmt.setInt(9, (((LeafNode) node).isPersistPublishedItems() ? 1 : 0));
                pstmt.setInt(10, ((LeafNode) node).getMaxPublishedItems());
            }
            else {
                pstmt.setInt(8, 0);
                pstmt.setInt(9, 0);
                pstmt.setInt(10, 0);
            }
Matt Tucker's avatar
Matt Tucker committed
196 197 198
            pstmt.setInt(11, (node.isNotifiedOfConfigChanges() ? 1 : 0));
            pstmt.setInt(12, (node.isNotifiedOfDelete() ? 1 : 0));
            pstmt.setInt(13, (node.isNotifiedOfRetract() ? 1 : 0));
Matt Tucker's avatar
Matt Tucker committed
199 200 201 202 203 204
            pstmt.setInt(14, (node.isPresenceBasedDelivery() ? 1 : 0));
            pstmt.setInt(15, (node.isSendItemSubscribe() ? 1 : 0));
            pstmt.setString(16, node.getPublisherModel().getName());
            pstmt.setInt(17, (node.isSubscriptionEnabled() ? 1 : 0));
            pstmt.setInt(18, (node.isSubscriptionConfigurationRequired() ? 1 : 0));
            pstmt.setString(19, node.getAccessModel().getName());
205 206 207 208 209 210 211
            pstmt.setString(20, node.getPayloadType());
            pstmt.setString(21, node.getBodyXSLT());
            pstmt.setString(22, node.getDataformXSLT());
            pstmt.setString(23, node.getCreator().toString());
            pstmt.setString(24, node.getDescription());
            pstmt.setString(25, node.getLanguage());
            pstmt.setString(26, node.getName());
Matt Tucker's avatar
Matt Tucker committed
212
            if (node.getReplyPolicy() != null) {
213
                pstmt.setString(27, node.getReplyPolicy().name());
Matt Tucker's avatar
Matt Tucker committed
214 215
            }
            else {
216
                pstmt.setString(27, null);
Matt Tucker's avatar
Matt Tucker committed
217 218
            }
            if (node.isCollectionNode()) {
219 220
                pstmt.setString(28, ((CollectionNode)node).getAssociationPolicy().name());
                pstmt.setInt(29, ((CollectionNode)node).getMaxLeafNodes());
Matt Tucker's avatar
Matt Tucker committed
221 222
            }
            else {
223 224
                pstmt.setString(28, null);
                pstmt.setInt(29, 0);
Matt Tucker's avatar
Matt Tucker committed
225 226
            }
            pstmt.executeUpdate();
227 228 229

            // Save associated JIDs and roster groups
            saveAssociatedElements(con, node, service);
Matt Tucker's avatar
Matt Tucker committed
230 231 232
        }
        catch (SQLException sqle) {
            Log.error(sqle);
233
            abortTransaction = true;
Matt Tucker's avatar
Matt Tucker committed
234 235 236 237
        }
        finally {
            try {if (pstmt != null) {pstmt.close();}}
            catch (Exception e) {Log.error(e);}
238
            DbConnectionManager.closeTransactionConnection(con, abortTransaction);
Matt Tucker's avatar
Matt Tucker committed
239 240 241 242 243 244 245 246 247 248 249 250
        }
    }

    /**
     * Updates the node configuration in the database.
     *
     * @param service The pubsub service that is hosting the node.
     * @param node The updated node.
     */
    public static void updateNode(PubSubService service, Node node) {
        Connection con = null;
        PreparedStatement pstmt = null;
251
        boolean abortTransaction = false;
Matt Tucker's avatar
Matt Tucker committed
252
        try {
253
            con = DbConnectionManager.getTransactionConnection();
Matt Tucker's avatar
Matt Tucker committed
254 255
            pstmt = con.prepareStatement(UPDATE_NODE);
            pstmt.setString(1, StringUtils.dateToMillis(node.getModificationDate()));
Matt Tucker's avatar
Matt Tucker committed
256
            pstmt.setString(2, node.getParent() != null ? encodeNodeID(node.getParent().getNodeID()) : null);
Matt Tucker's avatar
Matt Tucker committed
257
            pstmt.setInt(3, (node.isPayloadDelivered() ? 1 : 0));
Matt Tucker's avatar
Matt Tucker committed
258 259 260 261 262 263 264 265 266 267
            if (!node.isCollectionNode()) {
                pstmt.setInt(4, ((LeafNode) node).getMaxPayloadSize());
                pstmt.setInt(5, (((LeafNode) node).isPersistPublishedItems() ? 1 : 0));
                pstmt.setInt(6, ((LeafNode) node).getMaxPublishedItems());
            }
            else {
                pstmt.setInt(4, 0);
                pstmt.setInt(5, 0);
                pstmt.setInt(6, 0);
            }
Matt Tucker's avatar
Matt Tucker committed
268 269 270
            pstmt.setInt(7, (node.isNotifiedOfConfigChanges() ? 1 : 0));
            pstmt.setInt(8, (node.isNotifiedOfDelete() ? 1 : 0));
            pstmt.setInt(9, (node.isNotifiedOfRetract() ? 1 : 0));
Matt Tucker's avatar
Matt Tucker committed
271 272 273 274 275
            pstmt.setInt(10, (node.isPresenceBasedDelivery() ? 1 : 0));
            pstmt.setInt(11, (node.isSendItemSubscribe() ? 1 : 0));
            pstmt.setString(12, node.getPublisherModel().getName());
            pstmt.setInt(13, (node.isSubscriptionEnabled() ? 1 : 0));
            pstmt.setInt(14, (node.isSubscriptionConfigurationRequired() ? 1 : 0));
276 277 278 279 280 281 282
            pstmt.setString(15, node.getAccessModel().getName());
            pstmt.setString(16, node.getPayloadType());
            pstmt.setString(17, node.getBodyXSLT());
            pstmt.setString(18, node.getDataformXSLT());
            pstmt.setString(19, node.getDescription());
            pstmt.setString(20, node.getLanguage());
            pstmt.setString(21, node.getName());
Matt Tucker's avatar
Matt Tucker committed
283
            if (node.getReplyPolicy() != null) {
284
                pstmt.setString(22, node.getReplyPolicy().name());
Matt Tucker's avatar
Matt Tucker committed
285 286
            }
            else {
287
                pstmt.setString(22, null);
Matt Tucker's avatar
Matt Tucker committed
288 289
            }
            if (node.isCollectionNode()) {
290 291
                pstmt.setString(23, ((CollectionNode) node).getAssociationPolicy().name());
                pstmt.setInt(24, ((CollectionNode) node).getMaxLeafNodes());
Matt Tucker's avatar
Matt Tucker committed
292 293
            }
            else {
294 295
                pstmt.setString(23, null);
                pstmt.setInt(24, 0);
Matt Tucker's avatar
Matt Tucker committed
296
            }
297 298
            pstmt.setString(25, service.getServiceID());
            pstmt.setString(26, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
299
            pstmt.executeUpdate();
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317

            // Remove existing JIDs associated with the the node
            pstmt = con.prepareStatement(DELETE_NODE_JIDS);
            pstmt.setString(1, service.getServiceID());
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
            pstmt.executeUpdate();
            pstmt.close();

            // Remove roster groups associated with the the node being deleted
            pstmt = con.prepareStatement(DELETE_NODE_GROUPS);
            pstmt.setString(1, service.getServiceID());
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
            pstmt.executeUpdate();
            pstmt.close();
            pstmt = null;

            // Save associated JIDs and roster groups
            saveAssociatedElements(con, node, service);
Matt Tucker's avatar
Matt Tucker committed
318 319 320
        }
        catch (SQLException sqle) {
            Log.error(sqle);
321
            abortTransaction = true;
Matt Tucker's avatar
Matt Tucker committed
322 323 324 325
        }
        finally {
            try {if (pstmt != null) {pstmt.close();}}
            catch (Exception e) {Log.error(e);}
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
            DbConnectionManager.closeTransactionConnection(con, abortTransaction);
        }
    }

    private static void saveAssociatedElements(Connection con, Node node,
            PubSubService service) throws SQLException {
        // Add new JIDs associated with the the node
        PreparedStatement pstmt = con.prepareStatement(ADD_NODE_JIDS);
        try {
            for (JID jid : node.getContacts()) {
                pstmt.setString(1, service.getServiceID());
                pstmt.setString(2, encodeNodeID(node.getNodeID()));
                pstmt.setString(3, jid.toString());
                pstmt.setString(4, "contacts");
                pstmt.executeUpdate();
            }
            for (JID jid : node.getReplyRooms()) {
                pstmt.setString(1, service.getServiceID());
                pstmt.setString(2, encodeNodeID(node.getNodeID()));
                pstmt.setString(3, jid.toString());
                pstmt.setString(4, "replyRooms");
                pstmt.executeUpdate();
            }
            for (JID jid : node.getReplyTo()) {
                pstmt.setString(1, service.getServiceID());
                pstmt.setString(2, encodeNodeID(node.getNodeID()));
                pstmt.setString(3, jid.toString());
                pstmt.setString(4, "replyTo");
                pstmt.executeUpdate();
            }
            if (node.isCollectionNode()) {
                for (JID jid : ((CollectionNode) node).getAssociationTrusted()) {
                    pstmt.setString(1, service.getServiceID());
                    pstmt.setString(2, encodeNodeID(node.getNodeID()));
                    pstmt.setString(3, jid.toString());
                    pstmt.setString(4, "associationTrusted");
                    pstmt.executeUpdate();
                }
            }
            pstmt.close();
            // Add new roster groups associated with the the node
            pstmt = con.prepareStatement(ADD_NODE_GROUPS);
            for (String groupName : node.getRosterGroupsAllowed()) {
                pstmt.setString(1, service.getServiceID());
                pstmt.setString(2, encodeNodeID(node.getNodeID()));
                pstmt.setString(3, groupName);
                pstmt.executeUpdate();
            }
        }
        finally {
            pstmt.close();
Matt Tucker's avatar
Matt Tucker committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
        }
    }

    /**
     * Removes the specified node from the DB.
     *
     * @param service The pubsub service that is hosting the node.
     * @param node The node that is being deleted.
     * @return true If the operation was successful.
     */
    public static boolean removeNode(PubSubService service, Node node) {
        Connection con = null;
        PreparedStatement pstmt = null;
        boolean abortTransaction = false;
        try {
            con = DbConnectionManager.getTransactionConnection();
            // Remove the affiliate from the table of node affiliates
            pstmt = con.prepareStatement(DELETE_NODE);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
396
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
397 398 399
            pstmt.executeUpdate();
            pstmt.close();

400 401 402 403 404 405 406 407 408 409 410 411 412 413
            // Remove JIDs associated with the the node being deleted
            pstmt = con.prepareStatement(DELETE_NODE_JIDS);
            pstmt.setString(1, service.getServiceID());
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
            pstmt.executeUpdate();
            pstmt.close();

            // Remove roster groups associated with the the node being deleted
            pstmt = con.prepareStatement(DELETE_NODE_GROUPS);
            pstmt.setString(1, service.getServiceID());
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
            pstmt.executeUpdate();
            pstmt.close();

Matt Tucker's avatar
Matt Tucker committed
414 415 416
            // Remove published items of the node being deleted
            pstmt = con.prepareStatement(DELETE_ITEMS);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
417
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
418 419 420 421 422 423
            pstmt.executeUpdate();
            pstmt.close();

            // Remove all affiliates from the table of node affiliates
            pstmt = con.prepareStatement(DELETE_AFFILIATIONS);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
424
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
425 426 427 428 429 430
            pstmt.executeUpdate();
            pstmt.close();

            // Remove users that were subscribed to the node
            pstmt = con.prepareStatement(DELETE_SUBSCRIPTIONS);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
431
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
            pstmt.executeUpdate();
        }
        catch (SQLException sqle) {
            Log.error(sqle);
            abortTransaction = true;
        }
        finally {
            try {if (pstmt != null) {pstmt.close();}}
            catch (Exception e) {Log.error(e);}
            DbConnectionManager.closeTransactionConnection(con, abortTransaction);
        }
        return !abortTransaction;
    }

    /**
     * Loads all nodes from the database and adds them to the PubSub service.
     *
     * @param service the pubsub service that is hosting the nodes.
     */
    public static void loadNodes(PubSubService service) {
        Connection con = null;
        PreparedStatement pstmt = null;
        Map<String, Node> nodes = new HashMap<String, Node>();
        try {
            con = DbConnectionManager.getConnection();
457 458
            // Get all non-leaf nodes (to ensure parent nodes are loaded before their children)
            pstmt = con.prepareStatement(LOAD_NON_LEAF_NODES);
Matt Tucker's avatar
Matt Tucker committed
459 460
            pstmt.setString(1, service.getServiceID());
            ResultSet rs = pstmt.executeQuery();
461 462 463 464 465 466 467 468 469 470 471 472
            // Rebuild loaded non-leaf nodes
            while(rs.next()) {
                loadNode(service, nodes, rs);
            }
            rs.close();
            pstmt.close();

            // Get all leaf nodes (remaining unloaded nodes)
            pstmt = con.prepareStatement(LOAD_LEAF_NODES);
            pstmt.setString(1, service.getServiceID());
            rs = pstmt.executeQuery();
            // Rebuild loaded leaf nodes
Matt Tucker's avatar
Matt Tucker committed
473 474 475 476 477 478
            while(rs.next()) {
                loadNode(service, nodes, rs);
            }
            rs.close();
            pstmt.close();

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
            // Get JIDs associated with all nodes
            pstmt = con.prepareStatement(LOAD_NODES_JIDS);
            pstmt.setString(1, service.getServiceID());
            rs = pstmt.executeQuery();
            // Add to each node the associated JIDs
            while(rs.next()) {
                loadAssociatedJIDs(nodes, rs);
            }
            rs.close();
            pstmt.close();

            // Get roster groups associateds with all nodes
            pstmt = con.prepareStatement(LOAD_NODES_GROUPS);
            pstmt.setString(1, service.getServiceID());
            rs = pstmt.executeQuery();
            // Add to each node the associated Groups
            while(rs.next()) {
                loadAssociatedGroups(nodes, rs);
            }
            rs.close();
            pstmt.close();

Matt Tucker's avatar
Matt Tucker committed
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
            // Get affiliations of all nodes
            pstmt = con.prepareStatement(LOAD_AFFILIATIONS);
            pstmt.setString(1, service.getServiceID());
            rs = pstmt.executeQuery();
            // Add to each node the correspondiding affiliates
            while(rs.next()) {
                loadAffiliations(nodes, rs);
            }
            rs.close();
            pstmt.close();

            // Get subscriptions to all nodes
            pstmt = con.prepareStatement(LOAD_SUBSCRIPTIONS);
            pstmt.setString(1, service.getServiceID());
            rs = pstmt.executeQuery();
            // Add to each node the correspondiding subscriptions
            while(rs.next()) {
                loadSubscriptions(service, nodes, rs);
            }
            rs.close();
Matt Tucker's avatar
Matt Tucker committed
521 522 523 524 525 526 527 528 529 530 531

            // TODO We may need to optimize memory consumption and load items on-demand
            // Load published items of all nodes
            pstmt = con.prepareStatement(LOAD_ALL_ITEMS);
            pstmt.setString(1, service.getServiceID());
            rs = pstmt.executeQuery();
            // Add to each node the correspondiding subscriptions
            while(rs.next()) {
                loadItems(nodes, rs);
            }
            rs.close();
Matt Tucker's avatar
Matt Tucker committed
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
        }
        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); }
        }

        for (Node node : nodes.values()) {
            // Set now that the node is persistent in the database. Note: We need to
            // set this now since otherwise the node's affiliations will be saved to the database
            // "again" while adding them to the node!
            node.setSavedToDB(true);
            // Add the node to the service
            service.addNode(node);
        }
    }

    private static void loadNode(PubSubService service, Map<String, Node> loadedNodes,
            ResultSet rs) {
Matt Tucker's avatar
Matt Tucker committed
555
        Node node;
Matt Tucker's avatar
Matt Tucker committed
556
        try {
Matt Tucker's avatar
Matt Tucker committed
557
            String nodeID = decodeNodeID(rs.getString(1));
Matt Tucker's avatar
Matt Tucker committed
558
            boolean leaf = rs.getInt(2) == 1;
Matt Tucker's avatar
Matt Tucker committed
559
            String parent = decodeNodeID(rs.getString(5));
560
            JID creator = new JID(rs.getString(22));
Matt Tucker's avatar
Matt Tucker committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
            CollectionNode parentNode = null;
            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())));
Matt Tucker's avatar
Matt Tucker committed
582
            node.setPayloadDelivered(rs.getInt(6) == 1);
Matt Tucker's avatar
Matt Tucker committed
583 584 585 586
            if (leaf) {
                ((LeafNode) node).setMaxPayloadSize(rs.getInt(7));
                ((LeafNode) node).setPersistPublishedItems(rs.getInt(8) == 1);
                ((LeafNode) node).setMaxPublishedItems(rs.getInt(9));
Matt Tucker's avatar
Matt Tucker committed
587
                ((LeafNode) node).setSendItemSubscribe(rs.getInt(14) == 1);
Matt Tucker's avatar
Matt Tucker committed
588
            }
Matt Tucker's avatar
Matt Tucker committed
589 590 591
            node.setNotifiedOfConfigChanges(rs.getInt(10) == 1);
            node.setNotifiedOfDelete(rs.getInt(11) == 1);
            node.setNotifiedOfRetract(rs.getInt(12) == 1);
Matt Tucker's avatar
Matt Tucker committed
592 593 594 595
            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);
596 597 598 599 600 601 602 603 604
            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)));
Matt Tucker's avatar
Matt Tucker committed
605 606 607
            }
            if (!leaf) {
                ((CollectionNode) node).setAssociationPolicy(
608 609
                        CollectionNode.LeafNodeAssociationPolicy.valueOf(rs.getString(27)));
                ((CollectionNode) node).setMaxLeafNodes(rs.getInt(28));
Matt Tucker's avatar
Matt Tucker committed
610 611 612 613 614 615 616 617 618 619
            }

            // Add the load to the list of loaded nodes
            loadedNodes.put(node.getNodeID(), node);
        }
        catch (SQLException sqle) {
            Log.error(sqle);
        }
    }

620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
    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);
        }
    }

Matt Tucker's avatar
Matt Tucker committed
663 664
    private static void loadAffiliations(Map<String, Node> nodes, ResultSet rs) {
        try {
Matt Tucker's avatar
Matt Tucker committed
665
            String nodeID = decodeNodeID(rs.getString(1));
Matt Tucker's avatar
Matt Tucker committed
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
            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 {
Matt Tucker's avatar
Matt Tucker committed
683
            String nodeID = decodeNodeID(rs.getString(1));
Matt Tucker's avatar
Matt Tucker committed
684 685 686 687 688 689 690 691
            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));
692 693 694 695 696
            if (node.getAffiliate(owner) == null) {
                Log.warn("Subscription found for a non-existent affiliate: " + owner +
                        " in node: " + nodeID);
                return;
            }
Matt Tucker's avatar
Matt Tucker committed
697 698 699
            NodeSubscription.State state = NodeSubscription.State.valueOf(rs.getString(5));
            NodeSubscription subscription =
                    new NodeSubscription(service, node, owner, subscriber, state, subID);
Matt Tucker's avatar
Matt Tucker committed
700 701 702 703 704 705 706 707 708 709 710
            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));
Matt Tucker's avatar
Matt Tucker committed
711 712 713 714 715 716 717 718 719
            // Indicate the subscription that is has already been saved to the database
            subscription.setSavedToDB(true);
            node.addSubscription(subscription);
        }
        catch (SQLException sqle) {
            Log.error(sqle);
        }
    }

Matt Tucker's avatar
Matt Tucker committed
720 721 722 723 724 725
    private static void loadItems(Map<String, Node> nodes, ResultSet rs) {
        SAXReader xmlReader = null;
        try {
            // Get a sax reader from the pool
            xmlReader = xmlReaders.take();

Matt Tucker's avatar
Matt Tucker committed
726
            String nodeID = decodeNodeID(rs.getString(5));
Matt Tucker's avatar
Matt Tucker committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
            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);
            }
        }
    }

Matt Tucker's avatar
Matt Tucker committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
    /**
     * 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());
Matt Tucker's avatar
Matt Tucker committed
774
                pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
775 776 777 778 779
                pstmt.setString(3, affiliate.getJID().toString());
                pstmt.setString(4, affiliate.getAffiliation().name());
                pstmt.executeUpdate();
            }
            else {
780 781 782 783
                // 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());
Matt Tucker's avatar
Matt Tucker committed
784
                pstmt.setString(3, encodeNodeID(node.getNodeID()));
785 786
                pstmt.setString(4, affiliate.getJID().toString());
                pstmt.executeUpdate();
Matt Tucker's avatar
Matt Tucker committed
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
            }
        }
        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());
Matt Tucker's avatar
Matt Tucker committed
816
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
            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;
        try {
            con = DbConnectionManager.getConnection();
            if (create) {
                // Add the subscription of the user to the database
                pstmt = con.prepareStatement(ADD_SUBSCRIPTION);
                pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
849
                pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
850 851 852 853
                pstmt.setString(3, subscription.getID());
                pstmt.setString(4, subscription.getJID().toString());
                pstmt.setString(5, subscription.getOwner().toString());
                pstmt.setString(6, subscription.getState().name());
Matt Tucker's avatar
Matt Tucker committed
854 855 856
                pstmt.setInt(7, (subscription.shouldDeliverNotifications() ? 1 : 0));
                pstmt.setInt(8, (subscription.isUsingDigest() ? 1 : 0));
                pstmt.setInt(9, subscription.getDigestFrequency());
Matt Tucker's avatar
Matt Tucker committed
857 858
                Date expireDate = subscription.getExpire();
                if (expireDate == null) {
Matt Tucker's avatar
Matt Tucker committed
859
                    pstmt.setString(10, null);
Matt Tucker's avatar
Matt Tucker committed
860 861
                }
                else {
Matt Tucker's avatar
Matt Tucker committed
862
                    pstmt.setString(10, StringUtils.dateToMillis(expireDate));
Matt Tucker's avatar
Matt Tucker committed
863
                }
Matt Tucker's avatar
Matt Tucker committed
864 865 866 867 868
                pstmt.setInt(11, (subscription.isIncludingBody() ? 1 : 0));
                pstmt.setString(12, encodeWithComma(subscription.getPresenceStates()));
                pstmt.setString(13, subscription.getType().name());
                pstmt.setInt(14, subscription.getDepth());
                pstmt.setString(15, subscription.getKeyword());
Matt Tucker's avatar
Matt Tucker committed
869 870 871 872 873 874 875 876 877
                pstmt.executeUpdate();
                // Indicate the subscription that is has been saved to the database
                subscription.setSavedToDB(true);
            }
            else {
                if (NodeSubscription.State.none == subscription.getState()) {
                    // Remove the subscription of the user from the table
                    pstmt = con.prepareStatement(DELETE_SUBSCRIPTION);
                    pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
878
                    pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
879 880 881 882 883 884 885 886
                    pstmt.setString(2, subscription.getID());
                    pstmt.executeUpdate();
                }
                else {
                    // Update the subscription of the user in the backend store
                    pstmt = con.prepareStatement(UPDATE_SUBSCRIPTION);
                    pstmt.setString(1, subscription.getOwner().toString());
                    pstmt.setString(2, subscription.getState().name());
Matt Tucker's avatar
Matt Tucker committed
887 888 889
                    pstmt.setInt(3, (subscription.shouldDeliverNotifications() ? 1 : 0));
                    pstmt.setInt(4, (subscription.isUsingDigest() ? 1 : 0));
                    pstmt.setInt(5, subscription.getDigestFrequency());
Matt Tucker's avatar
Matt Tucker committed
890 891
                    Date expireDate = subscription.getExpire();
                    if (expireDate == null) {
Matt Tucker's avatar
Matt Tucker committed
892
                        pstmt.setString(6, null);
Matt Tucker's avatar
Matt Tucker committed
893 894
                    }
                    else {
Matt Tucker's avatar
Matt Tucker committed
895
                        pstmt.setString(6, StringUtils.dateToMillis(expireDate));
Matt Tucker's avatar
Matt Tucker committed
896
                    }
Matt Tucker's avatar
Matt Tucker committed
897 898 899 900 901 902
                    pstmt.setInt(7, (subscription.isIncludingBody() ? 1 : 0));
                    pstmt.setString(8, encodeWithComma(subscription.getPresenceStates()));
                    pstmt.setString(9, subscription.getType().name());
                    pstmt.setInt(10, subscription.getDepth());
                    pstmt.setString(11, subscription.getKeyword());
                    pstmt.setString(12, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
903
                    pstmt.setString(13, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
904
                    pstmt.setString(14, subscription.getID());
Matt Tucker's avatar
Matt Tucker committed
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
                    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 subscription of the user from the DB.
     *
     * @param service     The pubsub service that is hosting the node.
     * @param node        The node where the user was subscribed to.
     * @param subscription The existing subsription of the user to the node.
     */
    public static void removeSubscription(PubSubService service, Node node,
            NodeSubscription subscription) {
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            // Remove the affiliate from the table of node affiliates
            pstmt = con.prepareStatement(DELETE_SUBSCRIPTION);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
936
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
            pstmt.setString(3, subscription.getID());
            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);}
        }
    }

    /**
     * Loads and adds the published items to the specified node.
     *
     * @param service the pubsub service that is hosting the node.
     * @param node the leaf node to load its published items.
     */
    public static void loadItems(PubSubService service, LeafNode node) {
        Connection con = null;
        PreparedStatement pstmt = null;
        SAXReader xmlReader = null;
        try {
            // Get a sax reader from the pool
            xmlReader = xmlReaders.take();
            con = DbConnectionManager.getConnection();
            // Get published items of the specified node
            pstmt = con.prepareStatement(LOAD_ITEMS);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
968
            pstmt.setString(2, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
            ResultSet rs = pstmt.executeQuery();
            // Rebuild loaded published items
            while(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
                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);
            }
            rs.close();
        }
        catch (Exception sqle) {
            Log.error(sqle);
        }
        finally {
            // Return the sax reader to the pool
            if (xmlReader != null) {
                xmlReaders.add(xmlReader);
            }
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
        }
    }

Matt Tucker's avatar
Matt Tucker committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
    /**
     * Creates and stores the published item in the database.
     *
     * @param service the pubsub service that is hosting the node.
     * @param item The published item to save.
     * @return true if the item was successfully saved to the database.
     */
    public static boolean createPublishedItem(PubSubService service, PublishedItem item) {
        boolean success = false;
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            // Remove the published item from the database
            pstmt = con.prepareStatement(ADD_ITEM);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
1018
            pstmt.setString(2, encodeNodeID(item.getNode().getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
            pstmt.setString(3, item.getID());
            pstmt.setString(4, item.getPublisher().toString());
            pstmt.setString(5, StringUtils.dateToMillis(item.getCreationDate()));
            pstmt.setString(6, item.getPayloadXML());
            pstmt.executeUpdate();
            // Set that the item was successfully saved to the database
            success = true;
        }
        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 success;
    }

Matt Tucker's avatar
Matt Tucker committed
1039 1040 1041 1042 1043
    /**
     * Removes the specified published item from the DB.
     *
     * @param service the pubsub service that is hosting the node.
     * @param item The published item to delete.
Matt Tucker's avatar
Matt Tucker committed
1044
     * @return true if the item was successfully deleted from the database.
Matt Tucker's avatar
Matt Tucker committed
1045
     */
Matt Tucker's avatar
Matt Tucker committed
1046 1047
    public static boolean removePublishedItem(PubSubService service, PublishedItem item) {
        boolean success = false;
Matt Tucker's avatar
Matt Tucker committed
1048 1049 1050 1051 1052 1053 1054
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            // Remove the published item from the database
            pstmt = con.prepareStatement(DELETE_ITEM);
            pstmt.setString(1, service.getServiceID());
Matt Tucker's avatar
Matt Tucker committed
1055
            pstmt.setString(2, encodeNodeID(item.getNode().getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
1056 1057
            pstmt.setString(3, item.getID());
            pstmt.executeUpdate();
Matt Tucker's avatar
Matt Tucker committed
1058 1059
            // Set that the item was successfully deleted from the database
            success = true;
Matt Tucker's avatar
Matt Tucker committed
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
        }
        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);}
        }
Matt Tucker's avatar
Matt Tucker committed
1070
        return success;
Matt Tucker's avatar
Matt Tucker committed
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
    }

    /**
     * Loads from the database the default node configuration for the specified node type
     * and pubsub service.
     *
     * @param service the default node configuration used by this pubsub service.
     * @param isLeafType true if loading default configuration for leaf nodes.
     * @return the loaded default node configuration for the specified node type and service
     *         or <tt>null</tt> if none was found.
     */
    public static DefaultNodeConfiguration loadDefaultConfiguration(PubSubService service,
            boolean isLeafType) {
        Connection con = null;
        PreparedStatement pstmt = null;
        DefaultNodeConfiguration config = null;
        try {
            con = DbConnectionManager.getConnection();
            // Get default node configuration for the specified service
            pstmt = con.prepareStatement(LOAD_DEFAULT_CONF);
            pstmt.setString(1, service.getServiceID());
            pstmt.setInt(2, (isLeafType ? 1 : 0));
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                config = new DefaultNodeConfiguration(isLeafType);
                // Rebuild loaded default node configuration
                config.setDeliverPayloads(rs.getInt(1) == 1);
                config.setMaxPayloadSize(rs.getInt(2));
                config.setPersistPublishedItems(rs.getInt(3) == 1);
                config.setMaxPublishedItems(rs.getInt(4));
                config.setNotifyConfigChanges(rs.getInt(5) == 1);
                config.setNotifyDelete(rs.getInt(6) == 1);
                config.setNotifyRetract(rs.getInt(7) == 1);
                config.setPresenceBasedDelivery(rs.getInt(8) == 1);
                config.setSendItemSubscribe(rs.getInt(9) == 1);
                config.setPublisherModel(PublisherModel.valueOf(rs.getString(10)));
                config.setSubscriptionEnabled(rs.getInt(11) == 1);
                config.setAccessModel(AccessModel.valueOf(rs.getString(12)));
                config.setLanguage(rs.getString(13));
                if (rs.getString(14) != null) {
                    config.setReplyPolicy(Node.ItemReplyPolicy.valueOf(rs.getString(14)));
                }
                config.setAssociationPolicy(
                        CollectionNode.LeafNodeAssociationPolicy.valueOf(rs.getString(15)));
                config.setMaxLeafNodes(rs.getInt(16));
            }
            rs.close();
        }
        catch (Exception 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 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);
Matt Tucker's avatar
Matt Tucker committed
1251
            pstmt.setString(1, encodeNodeID(nodeID));
Matt Tucker's avatar
Matt Tucker committed
1252 1253 1254 1255 1256 1257
            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;
Matt Tucker's avatar
Matt Tucker committed
1258
            String parent = decodeNodeID(rs.getString(4));
Matt Tucker's avatar
Matt Tucker committed
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
            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())));
Matt Tucker's avatar
Matt Tucker committed
1287
            node.setPayloadDelivered(rs.getInt(5) == 1);
Matt Tucker's avatar
Matt Tucker committed
1288 1289 1290
            node.setMaxPayloadSize(rs.getInt(6));
            node.setPersistPublishedItems(rs.getInt(7) == 1);
            node.setMaxPublishedItems(rs.getInt(8));
Matt Tucker's avatar
Matt Tucker committed
1291 1292 1293
            node.setNotifiedOfConfigChanges(rs.getInt(9) == 1);
            node.setNotifiedOfDelete(rs.getInt(10) == 1);
            node.setNotifiedOfRetract(rs.getInt(11) == 1);
Matt Tucker's avatar
Matt Tucker committed
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
            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);
Matt Tucker's avatar
Matt Tucker committed
1331
            pstmt.setString(1, encodeNodeID(node.getNodeID()));
Matt Tucker's avatar
Matt Tucker committed
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
            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);
        }
1369 1370 1371 1372
        else {
            // Add a blank so an empty string is never replaced with NULL (oracle...arggg!!!)
            sb.append(" ");
        }
Matt Tucker's avatar
Matt Tucker committed
1373 1374 1375 1376 1377
        return sb.toString();
    }

    private static Collection<String> decodeWithComma(String strings) {
        Collection<String> decodedStrings = new ArrayList<String>();
1378
        StringTokenizer tokenizer = new StringTokenizer(strings.trim(), ",");
Matt Tucker's avatar
Matt Tucker committed
1379 1380 1381 1382 1383
        while (tokenizer.hasMoreTokens()) {
            decodedStrings.add(tokenizer.nextToken());
        }
        return decodedStrings;
    }
Matt Tucker's avatar
Matt Tucker committed
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401

    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;
    }
Matt Tucker's avatar
Matt Tucker committed
1402
}