Package org.jivesoftware.openfire.pubsub
Class DefaultPubSubPersistenceProvider
- java.lang.Object
-
- org.jivesoftware.openfire.pubsub.DefaultPubSubPersistenceProvider
-
- All Implemented Interfaces:
PubSubPersistenceProvider
public class DefaultPubSubPersistenceProvider extends Object implements PubSubPersistenceProvider
A manager responsible for ensuring node persistence.- Author:
- Matt Tucker
-
-
Constructor Summary
Constructors Constructor Description DefaultPubSubPersistenceProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
bulkPublishedItems(List<PublishedItem> addList, List<PublishedItem> delList)
Writes large changesets to the database, using batches and transactions when available.void
createAffiliation(Node node, NodeAffiliate affiliate)
Creates a new affiliation of the user in the node.void
createDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config)
Creates a new default node configuration for the specified service.void
createNode(Node node)
Schedules the node to be created in the database.void
createPublishedItem(PublishedItem item)
void
createSubscription(Node node, NodeSubscription subscription)
Adds the new subscription of the user to the node to the database.PublishedItem
getLastPublishedItem(LeafNode node)
Fetches the last published item for the specified node.PublishedItem
getPublishedItem(LeafNode node, PublishedItem.UniqueIdentifier itemIdentifier)
List<PublishedItem>
getPublishedItems(LeafNode node)
Fetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems()
.List<PublishedItem>
getPublishedItems(LeafNode node, int maxRows)
Fetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems()
.void
initialize()
DefaultNodeConfiguration
loadDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, boolean isLeafType)
Loads from the database the default node configuration for the specified node type and pubsub service.void
loadNode(PubSubService service, Node.UniqueIdentifier nodeIdentifier)
Loads all nodes from the database and adds them to the PubSub service.void
loadNodes(PubSubService service)
Loads all nodes from the database and adds them to the PubSub service.PEPService
loadPEPServiceFromDB(org.xmpp.packet.JID jid)
Loads a PEP service from the database, if it exists.void
loadSubscription(Node node, String subId)
void
purgeNode(LeafNode leafNode)
void
removeAffiliation(Node node, NodeAffiliate affiliate)
Removes the affiliation and subscription state of the user from the DB.void
removeNode(Node node)
Schedules the node to be removed in the database.void
removePublishedItem(PublishedItem item)
Removes the specified published item from the DB.protected void
removePublishedItems(Connection con, List<PublishedItem> delList, boolean batch)
void
removeSubscription(NodeSubscription subscription)
Removes the subscription of the user from the DB.void
saveAffiliation(Node node, NodeAffiliate affiliate, boolean create)
Deprecated.void
savePublishedItem(PublishedItem item)
Creates and stores the published item in the database.void
savePublishedItems(Connection con, List<PublishedItem> addList, boolean batch)
void
saveSubscription(Node node, NodeSubscription subscription, boolean create)
Deprecated.void
shutdown()
void
updateAffiliation(Node node, NodeAffiliate affiliate)
Updates an affiliation of the user in the node.void
updateDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config)
Updates the default node configuration for the specified service.void
updateNode(Node node)
Schedules the node to be updated in the database.void
updatePublishedItem(PublishedItem item)
void
updateSubscription(Node node, NodeSubscription subscription)
Updates the subscription of the user to the node to the database.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.openfire.pubsub.PubSubPersistenceProvider
createDefaultConfiguration, loadDefaultConfiguration, loadPEPServiceFromDB, loadSubscription, updateDefaultConfiguration
-
-
-
-
Method Detail
-
initialize
public void initialize()
- Specified by:
initialize
in interfacePubSubPersistenceProvider
-
createNode
public void createNode(Node node)
Description copied from interface:PubSubPersistenceProvider
Schedules the node to be created in the database.- Specified by:
createNode
in interfacePubSubPersistenceProvider
- Parameters:
node
- The newly created node.
-
updateNode
public void updateNode(Node node)
Description copied from interface:PubSubPersistenceProvider
Schedules the node to be updated in the database.- Specified by:
updateNode
in interfacePubSubPersistenceProvider
- Parameters:
node
- The updated node.
-
removeNode
public void removeNode(Node node)
Description copied from interface:PubSubPersistenceProvider
Schedules the node to be removed in the database.- Specified by:
removeNode
in interfacePubSubPersistenceProvider
- Parameters:
node
- The node that is being deleted.
-
loadNodes
public void loadNodes(PubSubService service)
Description copied from interface:PubSubPersistenceProvider
Loads all nodes from the database and adds them to the PubSub service.- Specified by:
loadNodes
in interfacePubSubPersistenceProvider
- Parameters:
service
- the pubsub service that is hosting the nodes.
-
loadNode
public void loadNode(PubSubService service, Node.UniqueIdentifier nodeIdentifier)
Description copied from interface:PubSubPersistenceProvider
Loads all nodes from the database and adds them to the PubSub service.- Specified by:
loadNode
in interfacePubSubPersistenceProvider
- Parameters:
service
- the pubsub service that is hosting the nodes.nodeIdentifier
- the identifier of the node to load.
-
loadSubscription
public void loadSubscription(Node node, String subId)
- Specified by:
loadSubscription
in interfacePubSubPersistenceProvider
-
saveAffiliation
@Deprecated public void saveAffiliation(Node node, NodeAffiliate affiliate, boolean create)
Deprecated.Update the DB with the new affiliation of the user in the node.- Parameters:
node
- The node where the affiliation of the user was updated.affiliate
- The new affiliation of the user in the node.create
- True if this is a new affiliate.
-
createAffiliation
public void createAffiliation(Node node, NodeAffiliate affiliate)
Description copied from interface:PubSubPersistenceProvider
Creates a new affiliation of the user in the node.- Specified by:
createAffiliation
in interfacePubSubPersistenceProvider
- Parameters:
node
- The node where the affiliation of the user was updated.affiliate
- The new affiliation of the user in the node.
-
updateAffiliation
public void updateAffiliation(Node node, NodeAffiliate affiliate)
Description copied from interface:PubSubPersistenceProvider
Updates an affiliation of the user in the node.- Specified by:
updateAffiliation
in interfacePubSubPersistenceProvider
- Parameters:
node
- The node where the affiliation of the user was updated.affiliate
- The new affiliation of the user in the node.
-
removeAffiliation
public void removeAffiliation(Node node, NodeAffiliate affiliate)
Description copied from interface:PubSubPersistenceProvider
Removes the affiliation and subscription state of the user from the DB.- Specified by:
removeAffiliation
in interfacePubSubPersistenceProvider
- Parameters:
node
- The node where the affiliation of the user was updated.affiliate
- The existing affiliation and subsription state of the user in the node.
-
saveSubscription
@Deprecated public void saveSubscription(Node node, NodeSubscription subscription, boolean create)
Deprecated.Updates the DB with the new subscription of the user to the node.- Parameters:
node
- The node where the user has subscribed to.subscription
- The new subscription of the user to the node.create
- True if this is a new affiliate.
-
createSubscription
public void createSubscription(Node node, NodeSubscription subscription)
Description copied from interface:PubSubPersistenceProvider
Adds the new subscription of the user to the node to the database.- Specified by:
createSubscription
in interfacePubSubPersistenceProvider
- Parameters:
node
- The node where the user has subscribed to.subscription
- The new subscription of the user to the node.
-
updateSubscription
public void updateSubscription(Node node, NodeSubscription subscription)
Description copied from interface:PubSubPersistenceProvider
Updates the subscription of the user to the node to the database.- Specified by:
updateSubscription
in interfacePubSubPersistenceProvider
- Parameters:
node
- The node where the user has subscribed to.subscription
- The new subscription of the user to the node.
-
removeSubscription
public void removeSubscription(NodeSubscription subscription)
Description copied from interface:PubSubPersistenceProvider
Removes the subscription of the user from the DB.- Specified by:
removeSubscription
in interfacePubSubPersistenceProvider
- Parameters:
subscription
- The existing subscription of the user to the node.
-
savePublishedItem
public void savePublishedItem(PublishedItem item)
Description copied from interface:PubSubPersistenceProvider
Creates and stores the published item in the database. When an item with the same ID was previously saved, this item will be replaced by the new item.- Specified by:
savePublishedItem
in interfacePubSubPersistenceProvider
- Parameters:
item
- The published item to save.
-
createPublishedItem
public void createPublishedItem(PublishedItem item)
-
updatePublishedItem
public void updatePublishedItem(PublishedItem item)
-
savePublishedItems
public void savePublishedItems(Connection con, List<PublishedItem> addList, boolean batch) throws SQLException
- Throws:
SQLException
-
removePublishedItem
public void removePublishedItem(PublishedItem item)
Description copied from interface:PubSubPersistenceProvider
Removes the specified published item from the DB.- Specified by:
removePublishedItem
in interfacePubSubPersistenceProvider
- Parameters:
item
- The published item to delete.
-
removePublishedItems
protected void removePublishedItems(Connection con, List<PublishedItem> delList, boolean batch) throws SQLException
- Throws:
SQLException
-
bulkPublishedItems
public void bulkPublishedItems(List<PublishedItem> addList, List<PublishedItem> delList)
Writes large changesets to the database, using batches and transactions when available. The 'delete' list takes precedence over the 'add' list: when an item exists on both lists, it is removed (and not re-added) to the database. To prevent duplicates to exist in the database, this method will attempt to remove all items to-be-added from the database, before re-adding them. Note that multiple attempts to write items to the DB are made: 1) insert all pending items in a single batch 2) if the batch insert fails, retry by inserting each item separately- Specified by:
bulkPublishedItems
in interfacePubSubPersistenceProvider
- Parameters:
addList
- A list of items to be added to the database.delList
- A list of items to be removed from the database.
-
loadDefaultConfiguration
public DefaultNodeConfiguration loadDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, boolean isLeafType)
Description copied from interface:PubSubPersistenceProvider
Loads from the database the default node configuration for the specified node type and pubsub service.- Specified by:
loadDefaultConfiguration
in interfacePubSubPersistenceProvider
- Parameters:
serviceIdentifier
- Identifier of the serviceisLeafType
- true if loading default configuration for leaf nodes.- Returns:
- the loaded default node configuration for the specified node type and service or null if none was found.
-
createDefaultConfiguration
public void createDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config)
Description copied from interface:PubSubPersistenceProvider
Creates a new default node configuration for the specified service.- Specified by:
createDefaultConfiguration
in interfacePubSubPersistenceProvider
- Parameters:
serviceIdentifier
- Identifier of the serviceconfig
- the default node configuration to create in the database.
-
updateDefaultConfiguration
public void updateDefaultConfiguration(PubSubService.UniqueIdentifier serviceIdentifier, DefaultNodeConfiguration config)
Description copied from interface:PubSubPersistenceProvider
Updates the default node configuration for the specified service.- Specified by:
updateDefaultConfiguration
in interfacePubSubPersistenceProvider
- Parameters:
serviceIdentifier
- Identifier of the serviceconfig
- the default node configuration to update in the database.
-
getPublishedItems
public List<PublishedItem> getPublishedItems(LeafNode node)
Description copied from interface:PubSubPersistenceProvider
Fetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems()
.- Specified by:
getPublishedItems
in interfacePubSubPersistenceProvider
- Parameters:
node
- the leaf node to load its published items.
-
getPublishedItems
public List<PublishedItem> getPublishedItems(LeafNode node, int maxRows)
Description copied from interface:PubSubPersistenceProvider
Fetches all the results for the specified node, limited byLeafNode.getMaxPublishedItems()
.- Specified by:
getPublishedItems
in interfacePubSubPersistenceProvider
- Parameters:
node
- the leaf node to load its published items.
-
getLastPublishedItem
public PublishedItem getLastPublishedItem(LeafNode node)
Description copied from interface:PubSubPersistenceProvider
Fetches the last published item for the specified node.- Specified by:
getLastPublishedItem
in interfacePubSubPersistenceProvider
- Parameters:
node
- the leaf node to load its last published items.
-
getPublishedItem
public PublishedItem getPublishedItem(LeafNode node, PublishedItem.UniqueIdentifier itemIdentifier)
- Specified by:
getPublishedItem
in interfacePubSubPersistenceProvider
-
purgeNode
public void purgeNode(LeafNode leafNode)
- Specified by:
purgeNode
in interfacePubSubPersistenceProvider
-
loadPEPServiceFromDB
public PEPService loadPEPServiceFromDB(org.xmpp.packet.JID jid)
Description copied from interface:PubSubPersistenceProvider
Loads a PEP service from the database, if it exists. Note that the returned service is not yet initialized!- Specified by:
loadPEPServiceFromDB
in interfacePubSubPersistenceProvider
- Parameters:
jid
- the JID of the owner of the PEP service.- Returns:
- the loaded PEP service, or null if not found.
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfacePubSubPersistenceProvider
-
-