Java Code Examples for org.jivesoftware.database.DbConnectionManager#closeTransactionConnection()
The following examples show how to use
org.jivesoftware.database.DbConnectionManager#closeTransactionConnection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bookmark.java From openfire-ofmeet-plugin with Apache License 2.0 | 6 votes |
private void insertBookmarkPermission(int type, String name) throws SQLException { Connection con = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); PreparedStatement pstmt = con.prepareStatement(INSERT_BOOKMARK_PERMISSIONS); pstmt.setLong(1, bookmarkID); pstmt.setInt(2, type); pstmt.setString(3, name); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException sqle) { abortTransaction = true; throw sqle; } finally { DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 2
Source File: Bookmark.java From openfire-ofmeet-plugin with Apache License 2.0 | 6 votes |
private void deleteBookmarkPermissions() throws SQLException { Connection con = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); PreparedStatement pstmt = con.prepareStatement(DELETE_BOOKMARK_PERMISSIONS); pstmt.setLong(1, bookmarkID); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException sqle) { abortTransaction = true; throw sqle; } finally { DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 3
Source File: Bookmark.java From openfire-ofmeet-plugin with Apache License 2.0 | 6 votes |
/** * Saves a bookmark to the database. */ private void saveToDb() { Connection con = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); PreparedStatement pstmt = con.prepareStatement(SAVE_BOOKMARK); pstmt.setString(1, type.toString()); pstmt.setString(2, name); pstmt.setString(3, value); pstmt.setInt(4, global ? 1 : 0); pstmt.setLong(5, bookmarkID); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException sqle) { abortTransaction = true; Log.error(sqle.getMessage(), sqle); } finally { DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 4
Source File: Bookmark.java From openfire-ofmeet-plugin with Apache License 2.0 | 6 votes |
/** * Inserts a new property into the datatabase. */ private void insertPropertyIntoDb(String name, String value) { Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(INSERT_PROPERTY); pstmt.setLong(1, bookmarkID); pstmt.setString(2, name); pstmt.setString(3, value); pstmt.executeUpdate(); } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction); } }
Example 5
Source File: Bookmark.java From openfire-ofmeet-plugin with Apache License 2.0 | 6 votes |
/** * Updates a property value in the database. */ private void updatePropertyInDb(String name, String value) { Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(UPDATE_PROPERTY); pstmt.setString(1, value); pstmt.setString(2, name); pstmt.setLong(3, bookmarkID); pstmt.executeUpdate(); } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction); } }
Example 6
Source File: Bookmark.java From openfire-ofmeet-plugin with Apache License 2.0 | 6 votes |
/** * Deletes a property from the db. */ private synchronized void deletePropertyFromDb(String name) { Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(DELETE_PROPERTY); pstmt.setLong(1, bookmarkID); pstmt.setString(2, name); pstmt.execute(); } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction); } }
Example 7
Source File: Bookmark.java From openfire-ofmeet-plugin with Apache License 2.0 | 6 votes |
/** * Inserts a new bookmark into the database. */ private void insertIntoDb() throws SQLException { this.bookmarkID = SequenceManager.nextID(this); Connection con = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); PreparedStatement pstmt = con.prepareStatement(INSERT_BOOKMARK); pstmt.setLong(1, bookmarkID); pstmt.setString(2, type.toString()); pstmt.setString(3, name); pstmt.setString(4, value); pstmt.setInt(5, global ? 1 : 0); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException sqle) { abortTransaction = true; throw sqle; } finally { DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 8
Source File: DefaultPubSubPersistenceProvider.java From Openfire with Apache License 2.0 | 6 votes |
@Override public void purgeNode(LeafNode leafNode) { Connection con = null; boolean rollback = false; try { con = DbConnectionManager.getTransactionConnection(); purgeNode(leafNode, con); } catch (SQLException exc) { log.error(exc.getMessage(), exc); rollback = true; } finally { DbConnectionManager.closeTransactionConnection(con, rollback); } }
Example 9
Source File: OF1515.java From Openfire with Apache License 2.0 | 5 votes |
/** * Creates appropriate database entries for each pubsub record * @param newRecords A collection of pubsub representations (can be empty, cannot be null). */ private static void toPubsubData( List<PubsubRecordData> newRecords ) { Log.info( "Writing Pubsub entities." ); Connection con = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); for ( final PubsubRecordData newRecord : newRecords ) { if ( !hasRootNode( con, newRecord.serviceID ) ) { writeRootNode( con, newRecord.serviceID ); } writeNode( con, newRecord ); writeItem( con, newRecord ); writeAffiliation( con, newRecord ); } } catch ( SQLException e ) { abortTransaction = true; } finally { DbConnectionManager.closeTransactionConnection( con, abortTransaction ); } }
Example 10
Source File: DefaultUserProvider.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void deleteUser(String username) { Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { // Delete all of the users's extended properties con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(DELETE_USER_PROPS); pstmt.setString(1, username); pstmt.execute(); DbConnectionManager.fastcloseStmt(pstmt); pstmt = con.prepareStatement(DELETE_USER_FLAGS); pstmt.setString(1, username); pstmt.execute(); DbConnectionManager.fastcloseStmt(pstmt); // Delete the actual user entry pstmt = con.prepareStatement(DELETE_USER); pstmt.setString(1, username); pstmt.execute(); } catch (Exception e) { Log.error(e.getMessage(), e); abortTransaction = true; } finally { DbConnectionManager.closeStatement(pstmt); DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction); } }
Example 11
Source File: DefaultGroupProvider.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void deleteGroup(String groupName) { Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); // Remove all users in the group. pstmt = con.prepareStatement(DELETE_GROUP_USERS); pstmt.setString(1, groupName); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove all properties of the group. pstmt = con.prepareStatement(DELETE_PROPERTIES); pstmt.setString(1, groupName); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove the group entry. pstmt = con.prepareStatement(DELETE_GROUP); pstmt.setString(1, groupName); pstmt.executeUpdate(); } catch (SQLException e) { Log.error(e.getMessage(), e); abortTransaction = true; } finally { DbConnectionManager.closeStatement(pstmt); DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 12
Source File: DefaultGroupProvider.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void setName(String oldName, String newName) throws GroupAlreadyExistsException { Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(SET_GROUP_NAME_1); pstmt.setString(1, newName); pstmt.setString(2, oldName); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); pstmt = con.prepareStatement(SET_GROUP_NAME_2); pstmt.setString(1, newName); pstmt.setString(2, oldName); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); pstmt = con.prepareStatement(SET_GROUP_NAME_3); pstmt.setString(1, newName); pstmt.setString(2, oldName); pstmt.executeUpdate(); } catch (SQLException e) { Log.error(e.getMessage(), e); abortTransaction = true; } finally { DbConnectionManager.closeStatement(pstmt); DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 13
Source File: MUCPersistenceManager.java From Openfire with Apache License 2.0 | 5 votes |
/** * Removes the room configuration and its affiliates from the database. * * @param room the room to remove from the database. */ public static void deleteFromDB(MUCRoom room) { if (!room.isPersistent() || !room.wasSavedToDB()) { return; } Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(DELETE_AFFILIATIONS); pstmt.setLong(1, room.getID()); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); pstmt = con.prepareStatement(DELETE_MEMBERS); pstmt.setLong(1, room.getID()); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); pstmt = con.prepareStatement(DELETE_ROOM); pstmt.setLong(1, room.getID()); pstmt.executeUpdate(); // Update the room (in memory) to indicate the it's no longer in the database. room.setSavedToDB(false); } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeStatement(pstmt); DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 14
Source File: DefaultPubSubPersistenceProvider.java From Openfire with Apache License 2.0 | 4 votes |
/** * 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 * * @param addList A list of items to be added to the database. * @param delList A list of items to be removed from the database. */ @Override public void bulkPublishedItems( List<PublishedItem> addList, List<PublishedItem> delList ) { // TODO Consider re-instating 'xmpp.pubsub.item.retry' property, to allow for retries of failed database // writes for items. Note that this behavior was first introduced when the work load was cached. As that's // no longer the case, there likely is no reason to assume that a retry (which would be immediate) would // succeed. There's a case to be made to reinstate this behavior in CachingPubsubPersistneceProvider, // instead of here. // is there anything to do? if ( addList == null ) { addList = new ArrayList<>(); } if ( delList == null ) { delList = new ArrayList<>(); } if ( addList.isEmpty() && delList.isEmpty() ) { return; } log.debug( "Processing collection of changes to published items. Additions: {}, deletes: {}", addList.size(), delList.size() ); // Ensure there are no duplicates by deleting before adding. delList.addAll( addList ); boolean rollback = false; Connection con; try { con = DbConnectionManager.getTransactionConnection(); } catch ( SQLException e ) { log.error( "Failed to obtain a database connection, to process a batch of changes to published items from DB.", e ); return; } try { log.debug( "Try to add the pending items as a dtabase batch." ); removePublishedItems( con, delList, true ); // delete first (to remove possible duplicates), then add new items savePublishedItems( con, addList, true ); } catch ( SQLException e1 ) { log.warn( "Failed to process a collection of changes to published items from DB. Retrying individually.", e1); log.debug( "Retry each item individually, rather than rolling back."); try { removePublishedItems( con, delList, false ); // delete first (to remove possible duplicates), then add new items savePublishedItems( con, addList, false ); } catch ( SQLException e2 ) { // Individual retries also failed. Roll back. log.error( "Failed to process a collection of changes both as a database batch as wel as individual changes. Rolling back transaction and giving up. Data is lost.", e2 ); rollback = true; } } finally { DbConnectionManager.closeTransactionConnection(con, rollback); } }
Example 15
Source File: DefaultPubSubPersistenceProvider.java From Openfire with Apache License 2.0 | 4 votes |
/** * Purges all items from the database that exceed the defined item count on * all nodes. */ private void purgeItems() { boolean abortTransaction = false; Connection con = null; PreparedStatement nodeConfig = null; PreparedStatement purgeNode = null; ResultSet rs = null; try { con = DbConnectionManager.getTransactionConnection(); nodeConfig = con.prepareStatement(PERSISTENT_NODES); rs = nodeConfig.executeQuery(); purgeNode = con.prepareStatement(getPurgeStatement(DbConnectionManager.getDatabaseType())); boolean hasBatchItems = false; while (rs.next()) { hasBatchItems = true; String svcId = rs.getString(1); String nodeId = rs.getString(2); int maxItems = rs.getInt(3); setPurgeParams(DbConnectionManager.getDatabaseType(), purgeNode, svcId, nodeId, maxItems); purgeNode.addBatch(); } if (hasBatchItems) purgeNode.executeBatch(); } catch (Exception sqle) { log.error(sqle.getMessage(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeResultSet(rs); DbConnectionManager.closeStatement(nodeConfig); DbConnectionManager.closeStatement(purgeNode); DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 16
Source File: DefaultPubSubPersistenceProvider.java From Openfire with Apache License 2.0 | 4 votes |
@Override public void removeNode(Node node) { log.trace( "Removing node: {} (write to database)", node.getUniqueIdentifier() ); if ( node instanceof LeafNode ) { purgeNode( (LeafNode) 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, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove JIDs associated with the the node being deleted pstmt = con.prepareStatement(DELETE_NODE_JIDS); pstmt.setString(1, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove roster groups associated with the the node being deleted pstmt = con.prepareStatement(DELETE_NODE_GROUPS); pstmt.setString(1, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove published items of the node being deleted if (node instanceof LeafNode) { purgeNode((LeafNode) node, con); } // Remove all affiliates from the table of node affiliates pstmt = con.prepareStatement(DELETE_AFFILIATIONS); pstmt.setString(1, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove users that were subscribed to the node pstmt = con.prepareStatement(DELETE_SUBSCRIPTIONS); pstmt.setString(1, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); } catch (SQLException sqle) { log.error("An exception occurred while removing a node ({}) in the database.", node.getUniqueIdentifier(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeStatement(pstmt); DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 17
Source File: DefaultPubSubPersistenceProvider.java From Openfire with Apache License 2.0 | 4 votes |
@Override public void updateNode(Node node) { log.trace( "Updating node: {} (write to database)", node.getUniqueIdentifier() ); Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(UPDATE_NODE); pstmt.setString(1, StringUtils.dateToMillis(node.getModificationDate())); pstmt.setString(2, node.getParent() != null ? encodeNodeID(node.getParent().getNodeID()) : null); pstmt.setInt(3, (node.isPayloadDelivered() ? 1 : 0)); 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); } pstmt.setInt(7, (node.isNotifiedOfConfigChanges() ? 1 : 0)); pstmt.setInt(8, (node.isNotifiedOfDelete() ? 1 : 0)); pstmt.setInt(9, (node.isNotifiedOfRetract() ? 1 : 0)); 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)); 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()); if (node.getReplyPolicy() != null) { pstmt.setString(22, node.getReplyPolicy().name()); } else { pstmt.setString(22, null); } if (node.isCollectionNode()) { pstmt.setString(23, ((CollectionNode) node).getAssociationPolicy().name()); pstmt.setInt(24, ((CollectionNode) node).getMaxLeafNodes()); } else { pstmt.setString(23, null); pstmt.setInt(24, 0); } pstmt.setString(25, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(26, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove existing JIDs associated with the the node pstmt = con.prepareStatement(DELETE_NODE_JIDS); pstmt.setString(1, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); DbConnectionManager.fastcloseStmt(pstmt); // Remove roster groups associated with the the node being deleted pstmt = con.prepareStatement(DELETE_NODE_GROUPS); pstmt.setString(1, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.executeUpdate(); // Save associated JIDs and roster groups saveAssociatedElements(con, node); } catch (SQLException sqle) { log.error("An exception occurred while updating a node ({}) in the database.", node.getUniqueIdentifier(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeStatement(pstmt); DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }
Example 18
Source File: DefaultPubSubPersistenceProvider.java From Openfire with Apache License 2.0 | 4 votes |
@Override public void createNode(Node node) { log.trace( "Creating node: {} (write to database)", node.getUniqueIdentifier() ); Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(ADD_NODE); pstmt.setString(1, node.getUniqueIdentifier().getServiceIdentifier().getServiceId()); pstmt.setString(2, encodeNodeID(node.getNodeID())); pstmt.setInt(3, (node.isCollectionNode() ? 0 : 1)); pstmt.setString(4, StringUtils.dateToMillis(node.getCreationDate())); pstmt.setString(5, StringUtils.dateToMillis(node.getModificationDate())); pstmt.setString(6, node.getParent() != null ? encodeNodeID(node.getParent().getNodeID()) : null); pstmt.setInt(7, (node.isPayloadDelivered() ? 1 : 0)); 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); } pstmt.setInt(11, (node.isNotifiedOfConfigChanges() ? 1 : 0)); pstmt.setInt(12, (node.isNotifiedOfDelete() ? 1 : 0)); pstmt.setInt(13, (node.isNotifiedOfRetract() ? 1 : 0)); 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()); 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()); if (node.getReplyPolicy() != null) { pstmt.setString(27, node.getReplyPolicy().name()); } else { pstmt.setString(27, null); } if (node.isCollectionNode()) { pstmt.setString(28, ((CollectionNode)node).getAssociationPolicy().name()); pstmt.setInt(29, ((CollectionNode)node).getMaxLeafNodes()); } else { pstmt.setString(28, null); pstmt.setInt(29, 0); } pstmt.executeUpdate(); // Save associated JIDs and roster groups saveAssociatedElements(con, node); } catch (SQLException sqle) { log.error("An exception occurred while creating a node ({}) in the database.", node.getUniqueIdentifier(), sqle); abortTransaction = true; } finally { DbConnectionManager.closeStatement(pstmt); DbConnectionManager.closeTransactionConnection(con, abortTransaction); } }