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

📄 jdbcextendeddaoimpl.java

📁 Acegi Security为Spring Framework提供一个兼容的安全认证服务(security services).
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            return;
        }

        // Retrieve acl_object_identity record details
        AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(basicAclEntry
                .getAclObjectIdentity());

        // Ensure there isn't an existing record for this recipient
        if (lookupPermissionId(aclDetailsHolder.getForeignKeyId(),
                basicAclEntry.getRecipient()) != -1) {
            throw new DataIntegrityViolationException(
                "This recipient already exists for this aclObjectIdentity");
        }

        // Create acl_permission
        aclPermissionInsert.insert(new Long(aclDetailsHolder.getForeignKeyId()),
            basicAclEntry.getRecipient().toString(),
            new Integer(basicAclEntry.getMask()));
    }

    public void delete(AclObjectIdentity aclObjectIdentity)
        throws DataAccessException {
        // Retrieve acl_object_identity record details
        AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);

        // Retrieve all acl_permissions applying to this acl_object_identity
        Iterator acls = aclsByObjectIdentity.execute(aclDetailsHolder
                .getForeignKeyId()).iterator();

        // Delete all existing acl_permissions applying to this acl_object_identity
        while (acls.hasNext()) {
            AclDetailsHolder permission = (AclDetailsHolder) acls.next();
            delete(aclObjectIdentity, permission.getRecipient());
        }

        // Delete acl_object_identity
        aclObjectIdentityDelete.delete(new Long(
                aclDetailsHolder.getForeignKeyId()));
    }

    public void delete(AclObjectIdentity aclObjectIdentity, Object recipient)
        throws DataAccessException {
        // Retrieve acl_object_identity record details
        AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity);

        // Delete acl_permission
        aclPermissionDelete.delete(new Long(aclDetailsHolder.getForeignKeyId()),
            recipient.toString());
    }

    protected void initDao() throws ApplicationContextException {
        super.initDao();
        lookupPermissionIdMapping = new LookupPermissionIdMapping(getDataSource());
        aclPermissionInsert = new AclPermissionInsert(getDataSource());
        aclObjectIdentityInsert = new AclObjectIdentityInsert(getDataSource());
        aclPermissionDelete = new AclPermissionDelete(getDataSource());
        aclObjectIdentityDelete = new AclObjectIdentityDelete(getDataSource());
        aclPermissionUpdate = new AclPermissionUpdate(getDataSource());
    }

    /**
     * Convenience method that creates an acl_object_identity record if
     * required.
     *
     * @param basicAclEntry containing the <code>AclObjectIdentity</code> to
     *        create
     *
     * @throws DataAccessException
     */
    private void createAclObjectIdentityIfRequired(BasicAclEntry basicAclEntry)
        throws DataAccessException {
        String aclObjectIdentityString = convertAclObjectIdentityToString(basicAclEntry
                .getAclObjectIdentity());

        // Lookup the object's main properties from the RDBMS (guaranteed no nulls)
        List objects = objectProperties.execute(aclObjectIdentityString);

        if (objects.size() == 0) {
            if (basicAclEntry.getAclObjectParentIdentity() != null) {
                AclDetailsHolder parentDetails = lookupAclDetailsHolder(basicAclEntry
                        .getAclObjectParentIdentity());

                // Must create the acl_object_identity record
                aclObjectIdentityInsert.insert(aclObjectIdentityString,
                    new Long(parentDetails.getForeignKeyId()),
                    basicAclEntry.getClass().getName());
            } else {
                // Must create the acl_object_identity record
                aclObjectIdentityInsert.insert(aclObjectIdentityString, null,
                    basicAclEntry.getClass().getName());
            }
        }
    }

    /**
     * Convenience method that obtains a given acl_object_identity record.
     *
     * @param aclObjectIdentity to lookup
     *
     * @return details of the record
     *
     * @throws DataRetrievalFailureException if record could not be found
     */
    private AclDetailsHolder lookupAclDetailsHolder(
        AclObjectIdentity aclObjectIdentity)
        throws DataRetrievalFailureException {
        String aclObjectIdentityString = convertAclObjectIdentityToString(aclObjectIdentity);

        // Lookup the object's main properties from the RDBMS (guaranteed no nulls)
        List objects = objectProperties.execute(aclObjectIdentityString);

        if (objects.size() == 0) {
            throw new DataRetrievalFailureException(
                "aclObjectIdentity not found: " + aclObjectIdentityString);
        }

        // Should only be one record
        return (AclDetailsHolder) objects.get(0);
    }

    /**
     * Convenience method to lookup the acl_permission applying to a given
     * acl_object_identity.id and acl_permission.recipient.
     *
     * @param aclObjectIdentityId to locate
     * @param recipient to locate
     *
     * @return the acl_permission.id of the record, or -1 if not found
     *
     * @throws DataAccessException DOCUMENT ME!
     */
    private long lookupPermissionId(long aclObjectIdentityId, Object recipient)
        throws DataAccessException {
        List list = lookupPermissionIdMapping.execute(new Object[] {new Long(
                        aclObjectIdentityId), recipient});

        if (list.size() == 0) {
            return -1;
        }

        return ((Long) list.get(0)).longValue();
    }

    //~ Inner Classes ==========================================================

    protected class AclObjectIdentityDelete extends SqlUpdate {
        protected AclObjectIdentityDelete(DataSource ds) {
            super(ds, aclObjectIdentityDeleteStatement);
            declareParameter(new SqlParameter(Types.BIGINT));
            compile();
        }

        protected void delete(Long aclObjectIdentity)
            throws DataAccessException {
            super.update(aclObjectIdentity.intValue());
        }
    }

    protected class AclObjectIdentityInsert extends SqlUpdate {
        protected AclObjectIdentityInsert(DataSource ds) {
            super(ds, aclObjectIdentityInsertStatement);
            declareParameter(new SqlParameter(Types.VARCHAR));
            declareParameter(new SqlParameter(Types.BIGINT));
            declareParameter(new SqlParameter(Types.VARCHAR));
            compile();
        }

        protected void insert(String objectIdentity,
            Long parentAclObjectIdentity, String aclClass)
            throws DataAccessException {
            Object[] objs = new Object[] {objectIdentity, parentAclObjectIdentity, aclClass};
            super.update(objs);
        }
    }

    protected class AclPermissionDelete extends SqlUpdate {
        protected AclPermissionDelete(DataSource ds) {
            super(ds, aclPermissionDeleteStatement);
            declareParameter(new SqlParameter(Types.BIGINT));
            declareParameter(new SqlParameter(Types.VARCHAR));
            compile();
        }

        protected void delete(Long aclObjectIdentity, String recipient)
            throws DataAccessException {
            super.update(new Object[] {aclObjectIdentity, recipient});
        }
    }

    protected class AclPermissionInsert extends SqlUpdate {
        protected AclPermissionInsert(DataSource ds) {
            super(ds, aclPermissionInsertStatement);
            declareParameter(new SqlParameter(Types.BIGINT));
            declareParameter(new SqlParameter(Types.VARCHAR));
            declareParameter(new SqlParameter(Types.INTEGER));
            compile();
        }

        protected void insert(Long aclObjectIdentity, String recipient,
            Integer mask) throws DataAccessException {
            Object[] objs = new Object[] {aclObjectIdentity, recipient, mask};
            super.update(objs);
        }
    }

    protected class AclPermissionUpdate extends SqlUpdate {
        protected AclPermissionUpdate(DataSource ds) {
            super(ds, aclPermissionUpdateStatement);
            declareParameter(new SqlParameter(Types.BIGINT));
            declareParameter(new SqlParameter(Types.INTEGER));
            compile();
        }

        protected void update(Long aclPermissionId, Integer newMask)
            throws DataAccessException {
            super.update(newMask.intValue(), aclPermissionId.intValue());
        }
    }

    protected class LookupPermissionIdMapping extends MappingSqlQuery {
        protected LookupPermissionIdMapping(DataSource ds) {
            super(ds, lookupPermissionIdQuery);
            declareParameter(new SqlParameter(Types.BIGINT));
            declareParameter(new SqlParameter(Types.VARCHAR));
            compile();
        }

        protected Object mapRow(ResultSet rs, int rownum)
            throws SQLException {
            return new Long(rs.getLong(1));
        }
    }
}

⌨️ 快捷键说明

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