/** * Inserts an entry into the DIT. If the entry exists, it is overwritten. Overwriting leaves is straight forward. * Overwriting inner nodes will first delete the node's entire subtree, then overwrite the node. Throws * {@link MissingParentException} if an ancestor of the entry is missing. */ public void storeOverwriteExisting(Entry entry) throws MissingParentException { try { deleteSubtreeIncludingRoot(entry.getDn()); } catch (NoSuchNodeException e) { LOGGER.debug("nothing to overwrite"); } finally { try { store(entry); } catch (EntryAlreadyExistsException e) { LOGGER.warn("should never reach here - entry should have been deleted"); } } }
/** * Behaves like {@link #store(List)} except that duplicates do not throw an exception but are overwritten as * described in {@link #storeOverwriteExisting(Entry)}. Note that this action is not atomic. * */ public void storeOverwriteExisting(List<Entry> entries) throws NoSuchNodeException, MissingParentException { for (Entry entry : entries) { try { store(entry); } catch (EntryAlreadyExistsException e) { deleteSubtreeIncludingRoot(e.getEntry().getDn()); try { store(entry); } catch (EntryAlreadyExistsException e1) { LOGGER.debug("should never reach here"); throw new LdapDaoException(e1); } } } }
private List<Node> extractNodesFromCursor(SearchCursor cursor) { LinkedList<Node> result = new LinkedList<Node>(); try { while (cursor.next()) { Node node = new Node(cursor.getEntry()); result.addFirst(node); node.setChildren(searchSubtree(node.getEntry().getDn())); for (Node n : node.getChildren()) { n.setParent(node); } } } catch (Exception e) { throw new LdapDaoException(e); } return result; }
/** * Deletes the entire subtree of root but not root itself. Throws NoSuchNodeException if root does not exist. Throws * MissingParentException if some node above root does not exist. * */ public void deleteSubtreeExcludingRoot(Dn root) throws NoSuchNodeException, MissingParentException { existsCheck(root); try { EntryCursor entryCursor = connection.search(root, "(objectclass=*)", SearchScope.ONELEVEL); while (entryCursor.next()) { deleteSubtreeIncludingRoot(entryCursor.get().getDn()); } } catch (Exception e) { throw new LdapDaoException(e); } }
String msg = I18n.err( I18n.ERR_10020, entry.getDn().getName(), schemaName ); LOG.warn( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg ); String msg = I18n.err( I18n.ERR_10021, entry.getDn().getName(), schemaName ); LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName );
String msg = I18n.err( I18n.ERR_10016, entry.getDn().getName(), schemaName ); LOG.warn( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg ); String msg = I18n.err( I18n.ERR_10017, entry.getDn().getName(), schemaName ); LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName );
String msg = I18n.err( I18n.ERR_10013, entry.getDn().getName(), schemaName ); LOG.warn( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg ); String msg = I18n.err( I18n.ERR_10014, entry.getDn().getName(), schemaName ); LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName );
String msg = I18n.err( I18n.ERR_10018, entry.getDn().getName(), schemaName ); LOG.warn( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg ); String msg = I18n.err( I18n.ERR_10019, entry.getDn().getName(), schemaName ); LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName );
String msg = I18n.err( I18n.ERR_10022, entry.getDn().getName(), schemaName ); LOG.warn( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg ); String msg = I18n.err( I18n.ERR_10023, entry.getDn().getName(), schemaName ); LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName );
String msg = I18n.err( I18n.ERR_10024, entry.getDn().getName(), schemaName ); LOG.warn( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg ); String msg = I18n.err( I18n.ERR_10025, entry.getDn().getName(), schemaName ); LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName );
/** * Inserts an entry into the DIT. Throws {@link EntryAlreadyExistsException} if an entry with given Dn already * exists. Throws {@link MissingParentException} if an ancestor of the entry is missing. */ public void store(Entry entry) throws EntryAlreadyExistsException, MissingParentException { AddRequest addRequest = new AddRequestImpl().setEntry(entry); LdapResult result; try { result = connection.add(addRequest).getLdapResult(); } catch (LdapException e) { throw new LdapDaoException(e); } if (result.getResultCode() == ResultCodeEnum.ENTRY_ALREADY_EXISTS) { throw new EntryAlreadyExistsException(entry); } else if (result.getResultCode() == ResultCodeEnum.NO_SUCH_OBJECT) { throw new MissingParentException(lastMatch(entry.getDn())); } else if (result.getResultCode() != ResultCodeEnum.SUCCESS) { throw new LdapDaoException(result.getDiagnosticMessage()); } }
String msg = I18n.err( I18n.ERR_10026, entry.getDn().getName(), schemaName ); LOG.warn( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg ); String msg = I18n.err( I18n.ERR_10027, entry.getDn().getName(), schemaName ); LOG.info( msg ); schema = schemaManager.getLoadedSchema( schemaName );