private ForeignKey getForeignKey(final Attributes attributes) { final ForeignKey foreignKey = new ForeignKey( attributes.getValue(DatabaseXmlUtils.NAME), attributes.getValue(DatabaseXmlUtils.FOREIGN_TABLE)); foreignKey.setOnDelete( CascadeAction.getCascadeAction(attributes.getValue(DatabaseXmlUtils.ON_DELETE))); foreignKey.setOnUpdate( CascadeAction.getCascadeAction(attributes.getValue(DatabaseXmlUtils.ON_UPDATE))); return foreignKey; }
private <T> void cascadeOperation(T theT, CascadeTest theCascadeTest, CascadeAction theAction) { // if we've already cascaded this, move on to the next thing, we don't want infinite loops if (mCascadePending.contains(theT)) { return; } else { mCascadePending.add(theT); } Collection<AccessibleObject> aAccessors = new HashSet<AccessibleObject>(); aAccessors.addAll(getAnnotatedFields(theT.getClass())); aAccessors.addAll(getAnnotatedGetters(theT.getClass(), true)); for (AccessibleObject aObj : aAccessors) { if (theCascadeTest.apply(aObj)) { try { Object aAccessorValue = BeanReflectUtil.safeGet(aObj, theT); if (aAccessorValue == null) { continue; } theAction.apply(aAccessorValue); } catch (Exception e) { throw new PersistenceException(e); } } } }