Return-Path: X-Original-To: apmail-cayenne-commits-archive@www.apache.org Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8A60D1068F for ; Sun, 4 Aug 2013 18:04:51 +0000 (UTC) Received: (qmail 17490 invoked by uid 500); 4 Aug 2013 18:04:51 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 17475 invoked by uid 500); 4 Aug 2013 18:04:51 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 17468 invoked by uid 99); 4 Aug 2013 18:04:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Aug 2013 18:04:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Aug 2013 18:04:40 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7AA9723889BF; Sun, 4 Aug 2013 18:04:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1510286 [1/3] - in /cayenne/main/trunk: framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/ framework/cayenne-core-unpublished/src/main/java/org/a... Date: Sun, 04 Aug 2013 18:04:15 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130804180417.7AA9723889BF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: aadamchik Date: Sun Aug 4 18:04:14 2013 New Revision: 1510286 URL: http://svn.apache.org/r1510286 Log: correct attribute/rel return type in Obj/DbEntity as a result can remove lots of unneeded casts also some generics cleanup Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainIndirectDiffBuilder.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/ManyToManyCandidateEntity.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/DataRowPostProcessor.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ClientObjRelationship.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DbJoin.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DbRelationship.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/EntityResult.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/AttributePropertyDecorator.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/BaseArcProperty.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/NamedObjectFactory.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/RelationshipFault.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteRulesTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/FlattenedArcKeyTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/JointPrefetchTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjAttributeTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/util/EntityMergeSupportTest.java cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/EntityUtils.java cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/validator/DuplicatedAttributesDialog.java Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java Sun Aug 4 18:04:14 2013 @@ -43,8 +43,8 @@ import org.apache.cayenne.validation.Val import org.apache.cayenne.validation.ValidationResult; /** - * A default implementation of DataObject interface. It is normally used as a superclass - * of Cayenne persistent objects. + * A default implementation of DataObject interface. It is normally used as a + * superclass of Cayenne persistent objects. */ public class CayenneDataObject extends PersistentObject implements DataObject, Validating { @@ -64,16 +64,16 @@ public class CayenneDataObject extends P } /** - * Returns a value of the property identified by a property path. Supports reading - * both mapped and unmapped properties. Unmapped properties are accessed in a manner - * consistent with JavaBeans specification. + * Returns a value of the property identified by a property path. Supports + * reading both mapped and unmapped properties. Unmapped properties are + * accessed in a manner consistent with JavaBeans specification. *

- * Property path (or nested property) is a dot-separated path used to traverse object - * relationships until the final object is found. If a null object found while - * traversing path, null is returned. If a list is encountered in the middle of the - * path, CayenneRuntimeException is thrown. Unlike - * {@link #readPropertyDirectly(String)}, this method will resolve an object if it is - * HOLLOW. + * Property path (or nested property) is a dot-separated path used to + * traverse object relationships until the final object is found. If a null + * object found while traversing path, null is returned. If a list is + * encountered in the middle of the path, CayenneRuntimeException is thrown. + * Unlike {@link #readPropertyDirectly(String)}, this method will resolve an + * object if it is HOLLOW. *

* Examples: *

@@ -109,20 +109,17 @@ public class CayenneDataObject extends P public Object readNestedProperty(String path) { if ((null == path) || (0 == path.length())) { - throw new IllegalArgumentException( - "the path must be supplied in order to lookup a nested property"); + throw new IllegalArgumentException("the path must be supplied in order to lookup a nested property"); } int dotIndex = path.indexOf('.'); if (0 == dotIndex) { - throw new IllegalArgumentException( - "the path is invalid because it starts with a period character"); + throw new IllegalArgumentException("the path is invalid because it starts with a period character"); } if (dotIndex == path.length() - 1) { - throw new IllegalArgumentException( - "the path is invalid because it ends with a period character"); + throw new IllegalArgumentException("the path is invalid because it ends with a period character"); } if (-1 == dotIndex) { @@ -145,11 +142,9 @@ public class CayenneDataObject extends P if (property == null) { return null; - } - else if (property instanceof DataObject) { + } else if (property instanceof DataObject) { return ((DataObject) property).readNestedProperty(pathRemainder); - } - else { + } else { return Cayenne.readNestedProperty(property, pathRemainder); } } @@ -170,8 +165,10 @@ public class CayenneDataObject extends P public Object readProperty(String propertyName) { if (objectContext != null) { - // will resolve faults ourselves below as checking class descriptors for the - // "lazyFaulting" flag is inefficient. Passing "false" here to suppress fault + // will resolve faults ourselves below as checking class descriptors + // for the + // "lazyFaulting" flag is inefficient. Passing "false" here to + // suppress fault // processing objectContext.prepareForAccess(this, propertyName, false); } @@ -195,7 +192,8 @@ public class CayenneDataObject extends P // pass "false" to avoid unneeded fault processing objectContext.prepareForAccess(this, propName, false); - // note how we notify ObjectContext of change BEFORE the object is actually + // note how we notify ObjectContext of change BEFORE the object is + // actually // changed... this is needed to take a valid current snapshot Object oldValue = readPropertyDirectly(propName); objectContext.propertyChanged(this, propName, oldValue, val); @@ -214,15 +212,16 @@ public class CayenneDataObject extends P // flattened or not) Object holder = readProperty(relName); - // call 'propertyChanged' AFTER readProperty as readProperty ensures that this + // call 'propertyChanged' AFTER readProperty as readProperty ensures + // that this // object fault is resolved getObjectContext().propertyChanged(this, relName, value, null); - // TODO: andrus 8/20/2007 - can we optimize this somehow, avoiding type checking?? + // TODO: andrus 8/20/2007 - can we optimize this somehow, avoiding type + // checking?? if (holder instanceof Collection) { ((Collection) holder).remove(value); - } - else if (holder instanceof Map) { + } else if (holder instanceof Map) { ((Map) holder).remove(getMapKey(relName, value)); } @@ -242,15 +241,16 @@ public class CayenneDataObject extends P // flattened or not) Object holder = readProperty(relName); - // call 'propertyChanged' AFTER readProperty as readProperty ensures that this + // call 'propertyChanged' AFTER readProperty as readProperty ensures + // that this // object fault is resolved getObjectContext().propertyChanged(this, relName, null, value); - // TODO: andrus 8/20/2007 - can we optimize this somehow, avoiding type checking?? + // TODO: andrus 8/20/2007 - can we optimize this somehow, avoiding type + // checking?? if (holder instanceof Collection) { ((Collection) holder).add(value); - } - else if (holder instanceof Map) { + } else if (holder instanceof Map) { ((Map) holder).put(getMapKey(relName, value), value); } @@ -259,10 +259,7 @@ public class CayenneDataObject extends P } } - public void setToOneTarget( - String relationshipName, - DataObject value, - boolean setReverse) { + public void setToOneTarget(String relationshipName, DataObject value, boolean setReverse) { willConnect(relationshipName, value); @@ -290,10 +287,11 @@ public class CayenneDataObject extends P } /** - * Called before establishing a relationship with another object. Applies "persistence - * by reachability" logic, pulling one of the two objects to a DataConext of another - * object in case one of the objects is transient. If both objects are persistent, and - * they don't have the same DataContext, CayenneRuntimeException is thrown. + * Called before establishing a relationship with another object. Applies + * "persistence by reachability" logic, pulling one of the two objects to a + * DataConext of another object in case one of the objects is transient. If + * both objects are persistent, and they don't have the same DataContext, + * CayenneRuntimeException is thrown. * * @since 1.2 */ @@ -302,30 +300,25 @@ public class CayenneDataObject extends P // ObjectContext or target is null if (object == null || this.getObjectContext() == object.getObjectContext()) { return; - } - else if (this.getObjectContext() == null && object.getObjectContext() != null) { + } else if (this.getObjectContext() == null && object.getObjectContext() != null) { object.getObjectContext().registerNewObject(this); - } - else if (this.getObjectContext() != null && object.getObjectContext() == null) { + } else if (this.getObjectContext() != null && object.getObjectContext() == null) { this.getObjectContext().registerNewObject(object); - } - else { - throw new CayenneRuntimeException( - "Cannot set object as destination of relationship " - + relationshipName - + " because it is in a different ObjectContext"); + } else { + throw new CayenneRuntimeException("Cannot set object as destination of relationship " + relationshipName + + " because it is in a different ObjectContext"); } } /** - * Initializes reverse relationship from object val to this object. + * Initializes reverse relationship from object val to this + * object. * - * @param relName name of relationship from this object to val. + * @param relName + * name of relationship from this object to val. */ protected void setReverseRelationship(String relName, DataObject val) { - ObjRelationship rel = (ObjRelationship) objectContext - .getEntityResolver() - .getObjEntity(objectId.getEntityName()) + ObjRelationship rel = objectContext.getEntityResolver().getObjEntity(objectId.getEntityName()) .getRelationship(relName); ObjRelationship revRel = rel.getReverseRelationship(); if (revRel != null) { @@ -337,8 +330,8 @@ public class CayenneDataObject extends P } /** - * Removes current object from reverse relationship of object val to this - * object. + * Removes current object from reverse relationship of object + * val to this object. */ protected void unsetReverseRelationship(String relName, DataObject val) { @@ -346,11 +339,10 @@ public class CayenneDataObject extends P ObjEntity entity = resolver.getObjEntity(objectId.getEntityName()); if (entity == null) { - throw new IllegalStateException("DataObject's entity is unmapped, objectId: " - + objectId); + throw new IllegalStateException("DataObject's entity is unmapped, objectId: " + objectId); } - ObjRelationship rel = (ObjRelationship) entity.getRelationship(relName); + ObjRelationship rel = entity.getRelationship(relName); ObjRelationship revRel = rel.getReverseRelationship(); if (revRel != null) { if (revRel.isToMany()) @@ -361,8 +353,8 @@ public class CayenneDataObject extends P } /** - * A variation of "toString" method, that may be more efficient in some cases. For - * example when printing a list of objects into the same String. + * A variation of "toString" method, that may be more efficient in some + * cases. For example when printing a list of objects into the same String. */ public StringBuffer toStringBuffer(StringBuffer buffer, boolean fullDesc) { String id = (objectId != null) ? objectId.toString() : ""; @@ -390,14 +382,11 @@ public class CayenneDataObject extends P if (value instanceof Persistent) { buffer.append('{').append(((Persistent) value).getObjectId()).append('}'); - } - else if (value instanceof Collection) { + } else if (value instanceof Collection) { buffer.append("(..)"); - } - else if (value instanceof Fault) { + } else if (value instanceof Fault) { buffer.append('?'); - } - else { + } else { buffer.append(value); } @@ -418,36 +407,35 @@ public class CayenneDataObject extends P out.writeInt(persistenceState); switch (persistenceState) { - // New, modified or transient or deleted - write the whole shebang - // The other states (committed, hollow) all need just ObjectId - case PersistenceState.TRANSIENT: - case PersistenceState.NEW: - case PersistenceState.MODIFIED: - case PersistenceState.DELETED: - out.writeObject(values); - break; + // New, modified or transient or deleted - write the whole shebang + // The other states (committed, hollow) all need just ObjectId + case PersistenceState.TRANSIENT: + case PersistenceState.NEW: + case PersistenceState.MODIFIED: + case PersistenceState.DELETED: + out.writeObject(values); + break; } out.writeObject(objectId); } - private void readObject(ObjectInputStream in) throws IOException, - ClassNotFoundException { + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { this.persistenceState = in.readInt(); switch (persistenceState) { - case PersistenceState.TRANSIENT: - case PersistenceState.NEW: - case PersistenceState.MODIFIED: - case PersistenceState.DELETED: - values = (Map) in.readObject(); - break; - case PersistenceState.COMMITTED: - case PersistenceState.HOLLOW: - this.persistenceState = PersistenceState.HOLLOW; - // props will be populated when required (readProperty called) - values = new HashMap(); - break; + case PersistenceState.TRANSIENT: + case PersistenceState.NEW: + case PersistenceState.MODIFIED: + case PersistenceState.DELETED: + values = (Map) in.readObject(); + break; + case PersistenceState.COMMITTED: + case PersistenceState.HOLLOW: + this.persistenceState = PersistenceState.HOLLOW; + // props will be populated when required (readProperty called) + values = new HashMap(); + break; } this.objectId = (ObjectId) in.readObject(); @@ -458,7 +446,8 @@ public class CayenneDataObject extends P } /** - * Returns a version of a DataRow snapshot that was used to create this object. + * Returns a version of a DataRow snapshot that was used to create this + * object. * * @since 1.1 */ @@ -474,60 +463,60 @@ public class CayenneDataObject extends P } /** - * Convenience method to invoke {@link Cayenne#makePath(String...)} from within a - * DataObject subclass to create a dotted path using the generated string constants - * for attributes and relationships. + * Convenience method to invoke {@link Cayenne#makePath(String...)} from + * within a DataObject subclass to create a dotted path using the generated + * string constants for attributes and relationships. * * @see Cayenne#makePath(String...) * @since 3.1 */ - // TODO: should we deprecate this one? After all the purpose of "Cayenne" class is to - // get rid of utility methods elsewhere.. + // TODO: should we deprecate this one? After all the purpose of "Cayenne" + // class is to + // get rid of utility methods elsewhere.. public static String makePath(String... pathParts) { return Cayenne.makePath(pathParts); } /** - * Performs property validation of the object, appending any validation failures to - * the provided validationResult object. This method is invoked from "validateFor.." - * before committing a NEW or MODIFIED object to the database. Validation includes - * checking for null values and value sizes. CayenneDataObject subclasses may override - * this method, calling super. + * Performs property validation of the object, appending any validation + * failures to the provided validationResult object. This method is invoked + * from "validateFor.." before committing a NEW or MODIFIED object to the + * database. Validation includes checking for null values and value sizes. + * CayenneDataObject subclasses may override this method, calling super. * * @since 1.1 */ protected void validateForSave(ValidationResult validationResult) { - ObjEntity objEntity = getObjectContext() - .getEntityResolver() - .lookupObjEntity(this); + ObjEntity objEntity = getObjectContext().getEntityResolver().lookupObjEntity(this); if (objEntity == null) { - throw new CayenneRuntimeException( - "No ObjEntity mapping found for DataObject " + getClass().getName()); + throw new CayenneRuntimeException("No ObjEntity mapping found for DataObject " + getClass().getName()); } // validate mandatory attributes - // handling a special case - meaningful mandatory FK... defer failures until - // relationship validation is done... This is just a temporary solution, as - // handling meaningful keys within the object lifecycle requires something more, - // namely read/write methods for relationships and direct values should be + // handling a special case - meaningful mandatory FK... defer failures + // until + // relationship validation is done... This is just a temporary solution, + // as + // handling meaningful keys within the object lifecycle requires + // something more, + // namely read/write methods for relationships and direct values should + // be // synchronous with each other.. Map failedDbAttributes = null; - for (Object next : objEntity.getAttributes()) { + for (ObjAttribute next : objEntity.getAttributes()) { // TODO: andrus, 2/20/2007 - handle embedded attribute if (next instanceof EmbeddedAttribute) { continue; } - ObjAttribute objAttribute = (ObjAttribute) next; - DbAttribute dbAttribute = objAttribute.getDbAttribute(); + DbAttribute dbAttribute = next.getDbAttribute(); if (dbAttribute == null) { - throw new CayenneRuntimeException("ObjAttribute '" - + objAttribute.getName() + throw new CayenneRuntimeException("ObjAttribute '" + next.getName() + "' does not have a corresponding DbAttribute"); } @@ -536,12 +525,9 @@ public class CayenneDataObject extends P continue; } - Object value = this.readPropertyDirectly(objAttribute.getName()); + Object value = this.readPropertyDirectly(next.getName()); if (dbAttribute.isMandatory()) { - ValidationFailure failure = BeanValidationFailure.validateNotNull( - this, - objAttribute.getName(), - value); + ValidationFailure failure = BeanValidationFailure.validateNotNull(this, next.getName(), value); if (failure != null) { @@ -560,31 +546,16 @@ public class CayenneDataObject extends P if (value.getClass().isArray()) { int len = Array.getLength(value); if (len > dbAttribute.getMaxLength()) { - String message = "\"" - + objAttribute.getName() - + "\" exceeds maximum allowed length (" - + dbAttribute.getMaxLength() - + " bytes): " - + len; - validationResult.addFailure(new BeanValidationFailure( - this, - objAttribute.getName(), - message)); + String message = "\"" + next.getName() + "\" exceeds maximum allowed length (" + + dbAttribute.getMaxLength() + " bytes): " + len; + validationResult.addFailure(new BeanValidationFailure(this, next.getName(), message)); } - } - else if (value instanceof CharSequence) { + } else if (value instanceof CharSequence) { int len = ((CharSequence) value).length(); if (len > dbAttribute.getMaxLength()) { - String message = "\"" - + objAttribute.getName() - + "\" exceeds maximum allowed length (" - + dbAttribute.getMaxLength() - + " chars): " - + len; - validationResult.addFailure(new BeanValidationFailure( - this, - objAttribute.getName(), - message)); + String message = "\"" + next.getName() + "\" exceeds maximum allowed length (" + + dbAttribute.getMaxLength() + " chars): " + len; + validationResult.addFailure(new BeanValidationFailure(this, next.getName(), message)); } } } @@ -614,15 +585,15 @@ public class CayenneDataObject extends P if (failedDbAttributes != null && !failedDbAttributes.isEmpty()) { failedDbAttributes.remove(source.getName()); - // loop through all joins if there were previous mandatory + // loop through all joins if there were previous + // mandatory // attribute failures.... if (!failedDbAttributes.isEmpty()) { continue; } } - } - else { + } else { // do not validate if the relation is based on // multiple keys with some that can be nullable. validate = false; @@ -631,10 +602,7 @@ public class CayenneDataObject extends P if (validate) { Object value = this.readPropertyDirectly(relationship.getName()); - ValidationFailure failure = BeanValidationFailure.validateNotNull( - this, - relationship.getName(), - value); + ValidationFailure failure = BeanValidationFailure.validateNotNull(this, relationship.getName(), value); if (failure != null) { validationResult.addFailure(failure); @@ -652,9 +620,9 @@ public class CayenneDataObject extends P } /** - * Calls {@link #validateForSave(ValidationResult)}. CayenneDataObject subclasses may - * override it providing validation logic that should be executed for the newly - * created objects before saving them. + * Calls {@link #validateForSave(ValidationResult)}. CayenneDataObject + * subclasses may override it providing validation logic that should be + * executed for the newly created objects before saving them. * * @since 1.1 */ @@ -663,9 +631,9 @@ public class CayenneDataObject extends P } /** - * Calls {@link #validateForSave(ValidationResult)}. CayenneDataObject subclasses may - * override it providing validation logic that should be executed for the modified - * objects before saving them. + * Calls {@link #validateForSave(ValidationResult)}. CayenneDataObject + * subclasses may override it providing validation logic that should be + * executed for the modified objects before saving them. * * @since 1.1 */ @@ -674,9 +642,9 @@ public class CayenneDataObject extends P } /** - * This implementation does nothing. CayenneDataObject subclasses may override it - * providing validation logic that should be executed for the deleted objects before - * committing them. + * This implementation does nothing. CayenneDataObject subclasses may + * override it providing validation logic that should be executed for the + * deleted objects before committing them. * * @since 1.1 */ Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java Sun Aug 4 18:04:14 2013 @@ -35,7 +35,8 @@ import org.apache.cayenne.map.ObjEntity; import org.apache.cayenne.map.ObjRelationship; /** - * Processes object diffs, generating DB diffs. Can be used for both UPDATE and INSERT. + * Processes object diffs, generating DB diffs. Can be used for both UPDATE and + * INSERT. * * @since 1.2 */ @@ -58,8 +59,8 @@ class DataDomainDBDiffBuilder implements } /** - * Resets the builder to process a new object for the previously set combination of - * objEntity/dbEntity. + * Resets the builder to process a new object for the previously set + * combination of objEntity/dbEntity. */ private void reset() { currentPropertyDiff = null; @@ -92,11 +93,10 @@ class DataDomainDBDiffBuilder implements // populate changed columns if (currentPropertyDiff != null) { for (final Map.Entry entry : currentPropertyDiff.entrySet()) { - ObjAttribute attribute = (ObjAttribute) objEntity.getAttribute(entry - .getKey() - .toString()); + ObjAttribute attribute = objEntity.getAttribute(entry.getKey().toString()); - // in case of a flattened attribute, ensure that it belongs to this + // in case of a flattened attribute, ensure that it belongs to + // this // bucket... DbAttribute dbAttribute = attribute.getDbAttribute(); if (dbAttribute.getEntity() == dbEntity) { @@ -110,16 +110,14 @@ class DataDomainDBDiffBuilder implements // populate changed FKs if (currentArcDiff != null) { for (final Map.Entry entry : currentArcDiff.entrySet()) { - ObjRelationship relation = (ObjRelationship) objEntity - .getRelationship(entry.getKey().toString()); + ObjRelationship relation = objEntity.getRelationship(entry.getKey().toString()); DbRelationship dbRelation = relation.getDbRelationships().get(0); ObjectId targetId = (ObjectId) entry.getValue(); for (DbJoin join : dbRelation.getJoins()) { - Object value = (targetId != null) ? new PropagatedValueFactory( - targetId, - join.getTargetName()) : null; + Object value = (targetId != null) ? new PropagatedValueFactory(targetId, join.getTargetName()) + : null; dbDiff.put(join.getSourceName(), value); } @@ -129,7 +127,8 @@ class DataDomainDBDiffBuilder implements private void appendPrimaryKeys(Map dbDiff) { - // populate changed PKs; note that we might end up overriding some values taken + // populate changed PKs; note that we might end up overriding some + // values taken // from the object (e.g. zero PK's). if (currentId != null) { dbDiff.putAll(((ObjectId) currentId).getIdSnapshot()); @@ -140,12 +139,9 @@ class DataDomainDBDiffBuilder implements // GraphChangeHandler methods. // ================================================== - public void nodePropertyChanged( - Object nodeId, - String property, - Object oldValue, - Object newValue) { - // note - no checking for phantom mod... assuming there is no phantom diffs + public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) { + // note - no checking for phantom mod... assuming there is no phantom + // diffs if (currentPropertyDiff == null) { currentPropertyDiff = new HashMap(); @@ -156,8 +152,7 @@ class DataDomainDBDiffBuilder implements public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { - ObjRelationship relationship = (ObjRelationship) objEntity.getRelationship(arcId - .toString()); + ObjRelationship relationship = objEntity.getRelationship(arcId.toString()); if (!relationship.isSourceIndependentFromTargetChange()) { if (currentArcDiff == null) { currentArcDiff = new HashMap(); @@ -168,16 +163,15 @@ class DataDomainDBDiffBuilder implements public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) { - ObjRelationship relationship = (ObjRelationship) objEntity.getRelationship(arcId - .toString()); + ObjRelationship relationship = objEntity.getRelationship(arcId.toString()); if (!relationship.isSourceIndependentFromTargetChange()) { if (currentArcDiff == null) { currentArcDiff = new HashMap(); currentArcDiff.put(arcId, null); - } - else { - // skip deletion record if a substitute arc was created prior to deleting + } else { + // skip deletion record if a substitute arc was created prior to + // deleting // the old arc... Object existingTargetId = currentArcDiff.get(arcId); if (existingTargetId == null || targetNodeId.equals(existingTargetId)) { Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainIndirectDiffBuilder.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainIndirectDiffBuilder.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainIndirectDiffBuilder.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/DataDomainIndirectDiffBuilder.java Sun Aug 4 18:04:14 2013 @@ -32,8 +32,8 @@ import org.apache.cayenne.map.ObjEntity; import org.apache.cayenne.map.ObjRelationship; /** - * A processor of ObjectStore indirect changes, such as flattened relationships and - * to-many relationships. + * A processor of ObjectStore indirect changes, such as flattened relationships + * and to-many relationships. * * @since 1.2 */ @@ -54,7 +54,8 @@ final class DataDomainIndirectDiffBuilde } void processIndirectChanges(GraphDiff allChanges) { - // extract flattened and indirect changes and remove duplicate changes... + // extract flattened and indirect changes and remove duplicate + // changes... allChanges.apply(this); if (!flattenedInserts.isEmpty()) { @@ -75,11 +76,10 @@ final class DataDomainIndirectDiffBuilde @Override public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { ObjEntity entity = resolver.getObjEntity(((ObjectId) nodeId).getEntityName()); - ObjRelationship relationship = (ObjRelationship) entity.getRelationship(arcId - .toString()); + ObjRelationship relationship = entity.getRelationship(arcId.toString()); if (relationship.isSourceIndependentFromTargetChange()) { - + ObjectId nodeObjectId = (ObjectId) nodeId; if (!nodeObjectId.isTemporary()) { indirectModifications.add(nodeObjectId); @@ -87,32 +87,30 @@ final class DataDomainIndirectDiffBuilde if (relationship.isFlattened()) { if (relationship.isReadOnly()) { - throw new CayenneRuntimeException( - "Cannot set the read-only flattened relationship '" - + relationship.getName() + "' in ObjEntity '" + relationship.getSourceEntity().getName() + "'."); + throw new CayenneRuntimeException("Cannot set the read-only flattened relationship '" + + relationship.getName() + "' in ObjEntity '" + relationship.getSourceEntity().getName() + + "'."); } - // Register this combination (so we can remove it later if an insert + // Register this combination (so we can remove it later if an + // insert // occurs before commit) - FlattenedArcKey key = new FlattenedArcKey( - (ObjectId) nodeId, - (ObjectId) targetNodeId, - relationship); + FlattenedArcKey key = new FlattenedArcKey((ObjectId) nodeId, (ObjectId) targetNodeId, relationship); - // If this combination has already been deleted, simply undelete it. + // If this combination has already been deleted, simply undelete + // it. if (!flattenedDeletes.remove(key)) { flattenedInserts.add(key); } } } } - + @Override public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) { ObjEntity entity = resolver.getObjEntity(((ObjectId) nodeId).getEntityName()); - ObjRelationship relationship = (ObjRelationship) entity.getRelationship(arcId - .toString()); + ObjRelationship relationship = entity.getRelationship(arcId.toString()); if (relationship.isSourceIndependentFromTargetChange()) { // do not record temporary id mods... @@ -123,19 +121,17 @@ final class DataDomainIndirectDiffBuilde if (relationship.isFlattened()) { if (relationship.isReadOnly()) { - throw new CayenneRuntimeException( - "Cannot unset the read-only flattened relationship " - + relationship.getName()); + throw new CayenneRuntimeException("Cannot unset the read-only flattened relationship " + + relationship.getName()); } - // Register this combination (so we can remove it later if an insert + // Register this combination (so we can remove it later if an + // insert // occurs before commit) - FlattenedArcKey key = new FlattenedArcKey( - (ObjectId) nodeId, - (ObjectId) targetNodeId, - relationship); + FlattenedArcKey key = new FlattenedArcKey((ObjectId) nodeId, (ObjectId) targetNodeId, relationship); - // If this combination has already been inserted, simply "uninsert" it + // If this combination has already been inserted, simply + // "uninsert" it // also do not delete it twice if (!flattenedInserts.remove(key)) { flattenedDeletes.add(key); @@ -160,11 +156,7 @@ final class DataDomainIndirectDiffBuilde } @Override - public void nodePropertyChanged( - Object nodeId, - String property, - Object oldValue, - Object newValue) { + public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) { // noop } } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/ManyToManyCandidateEntity.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/ManyToManyCandidateEntity.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/ManyToManyCandidateEntity.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/ManyToManyCandidateEntity.java Sun Aug 4 18:04:14 2013 @@ -18,15 +18,14 @@ ****************************************************************/ package org.apache.cayenne.access; +import java.util.ArrayList; +import java.util.List; + import org.apache.cayenne.map.DbRelationship; import org.apache.cayenne.map.ObjEntity; import org.apache.cayenne.map.ObjRelationship; -import org.apache.cayenne.map.Relationship; import org.apache.cayenne.util.NamedObjectFactory; -import java.util.ArrayList; -import java.util.List; - /** * Class represent ObjEntity that may be optimized using flattened relationships * as many to many table @@ -54,13 +53,13 @@ class ManyToManyCandidateEntity { } private ObjRelationship getRelationship1() { - List relationships = new ArrayList(entity.getRelationships()); - return (ObjRelationship) relationships.get(0); + List relationships = new ArrayList(entity.getRelationships()); + return relationships.get(0); } private ObjRelationship getRelationship2() { - List relationships = new ArrayList(entity.getRelationships()); - return (ObjRelationship) relationships.get(1); + List relationships = new ArrayList(entity.getRelationships()); + return relationships.get(1); } private ObjEntity getTargetEntity1() { Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/DataRowPostProcessor.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/DataRowPostProcessor.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/DataRowPostProcessor.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/DataRowPostProcessor.java Sun Aug 4 18:04:14 2013 @@ -23,8 +23,8 @@ import java.sql.ResultSet; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import org.apache.cayenne.DataRow; import org.apache.cayenne.access.trans.SelectTranslator; @@ -49,21 +49,18 @@ class DataRowPostProcessor { // factory method static DataRowPostProcessor createPostProcessor(SelectTranslator translator) { - Map attributeOverrides = translator.getAttributeOverrides(); + Map attributeOverrides = translator.getAttributeOverrides(); if (attributeOverrides.isEmpty()) { return null; } ColumnDescriptor[] columns = translator.getResultColumns(); - Map> columnOverrides = new HashMap>( - 2); + Map> columnOverrides = new HashMap>(2); - Iterator it = attributeOverrides.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = (Map.Entry) it.next(); + for (Entry entry : attributeOverrides.entrySet()) { - ObjAttribute attribute = (ObjAttribute) entry.getKey(); + ObjAttribute attribute = entry.getKey(); Entity entity = attribute.getEntity(); String key = null; @@ -72,7 +69,8 @@ class DataRowPostProcessor { for (int i = 0; i < columns.length; i++) { if (columns[i] == entry.getValue()) { - // if attribute type is the same as column, there is no conflict + // if attribute type is the same as column, there is no + // conflict if (!attribute.getType().equals(columns[i].getJavaClass())) { // note that JDBC index is "1" based index = i + 1; @@ -88,10 +86,7 @@ class DataRowPostProcessor { continue; } - ExtendedType converter = translator - .getAdapter() - .getExtendedTypes() - .getRegisteredType(attribute.getType()); + ExtendedType converter = translator.getAdapter().getExtendedTypes().getRegisteredType(attribute.getType()); Collection overrides = columnOverrides.get(entity.getName()); @@ -108,9 +103,7 @@ class DataRowPostProcessor { return null; } - ClassDescriptor rootDescriptor = translator - .getQueryMetadata() - .getClassDescriptor(); + ClassDescriptor rootDescriptor = translator.getQueryMetadata().getClassDescriptor(); return new DataRowPostProcessor(rootDescriptor, columnOverrides); } @@ -121,11 +114,9 @@ class DataRowPostProcessor { if (classDescriptor != null && classDescriptor.hasSubclasses()) { this.inheritanceTree = classDescriptor.getEntityInheritanceTree(); this.columnOverrides = columnOverrides; - } - else { + } else { if (columnOverrides.size() != 1) { - throw new IllegalArgumentException( - "No inheritance - there must be only one override set"); + throw new IllegalArgumentException("No inheritance - there must be only one override set"); } defaultOverrides = columnOverrides.values().iterator().next(); @@ -139,10 +130,7 @@ class DataRowPostProcessor { if (overrides != null) { for (final ColumnOverride override : overrides) { - Object newValue = override.converter.materializeObject( - resultSet, - override.index, - override.jdbcType); + Object newValue = override.converter.materializeObject(resultSet, override.index, override.jdbcType); row.put(override.key, newValue); } } @@ -151,8 +139,7 @@ class DataRowPostProcessor { private final Collection getOverrides(DataRow row) { if (defaultOverrides != null) { return defaultOverrides; - } - else { + } else { ObjEntity entity = inheritanceTree.entityMatchingRow(row); return entity != null ? columnOverrides.get(entity.getName()) : null; } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java Sun Aug 4 18:04:14 2013 @@ -174,8 +174,7 @@ public class EJBQLConditionTranslator ex String subqueryTableName = quoter.quotedFullyQualifiedName(targetDescriptor.getEntity().getDbEntity()); String subqueryRootAlias = context.getTableAlias(subqueryId, subqueryTableName); - ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor.getEntity().getRelationship( - path.getRelativePath()); + ObjRelationship relationship = correlatedEntityDescriptor.getEntity().getRelationship(path.getRelativePath()); if (relationship.getDbRelationshipPath().contains(".")) { // if the DbRelationshipPath contains '.', the relationship is @@ -256,8 +255,7 @@ public class EJBQLConditionTranslator ex String subqueryTableName = quoter.quotedFullyQualifiedName(targetDescriptor.getEntity().getDbEntity()); String subqueryRootAlias = context.getTableAlias(subqueryId, subqueryTableName); - ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor.getEntity().getRelationship( - path.getRelativePath()); + ObjRelationship relationship = correlatedEntityDescriptor.getEntity().getRelationship(path.getRelativePath()); if (relationship.getDbRelationshipPath().contains(".")) { // if the DbRelationshipPath contains '.', the relationship is @@ -618,8 +616,8 @@ public class EJBQLConditionTranslator ex } DbEntity table = descriptor.getEntity().getDbEntity(); - String alias = context - .getTableAlias(expression.getText(), context.getQuotingStrategy().quotedFullyQualifiedName(table)); + String alias = context.getTableAlias(expression.getText(), context.getQuotingStrategy() + .quotedFullyQualifiedName(table)); Collection pks = table.getPrimaryKeys(); Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java Sun Aug 4 18:04:14 2013 @@ -152,7 +152,7 @@ public abstract class EJBQLPathTranslato } protected void processIntermediatePathComponent() { - ObjRelationship relationship = (ObjRelationship) currentEntity.getRelationship(lastPathComponent); + ObjRelationship relationship = currentEntity.getRelationship(lastPathComponent); if (relationship == null) { throw new EJBQLException("Unknown relationship '" + lastPathComponent + "' for entity '" + currentEntity.getName() + "'"); @@ -163,14 +163,14 @@ public abstract class EJBQLPathTranslato protected void processLastPathComponent() { - ObjAttribute attribute = (ObjAttribute) currentEntity.getAttribute(lastPathComponent); + ObjAttribute attribute = currentEntity.getAttribute(lastPathComponent); if (attribute != null) { processTerminatingAttribute(attribute); return; } - ObjRelationship relationship = (ObjRelationship) currentEntity.getRelationship(lastPathComponent); + ObjRelationship relationship = currentEntity.getRelationship(lastPathComponent); if (relationship != null) { processTerminatingRelationship(relationship); return; Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java Sun Aug 4 18:04:14 2013 @@ -50,8 +50,9 @@ import org.apache.cayenne.reflect.ClassD import org.apache.commons.collections.comparators.ReverseComparator; /** - * Implements dependency sorting algorithms for ObjEntities, DbEntities and DataObjects. - * Presently it works for acyclic database schemas with possible multi-reflexive tables. + * Implements dependency sorting algorithms for ObjEntities, DbEntities and + * DataObjects. Presently it works for acyclic database schemas with possible + * multi-reflexive tables. * * @since 3.1 */ @@ -79,7 +80,8 @@ public class AshwoodEntitySorter impleme // correct double check locking per Joshua Bloch // http://java.sun.com/developer/technicalArticles/Interviews/bloch_effective_08_qa.html - // (maybe we should use something like CountDownLatch or a Cyclic barrier + // (maybe we should use something like CountDownLatch or a Cyclic + // barrier // instead?) boolean localDirty = dirty; @@ -99,8 +101,7 @@ public class AshwoodEntitySorter impleme */ protected void doIndexSorter() { - Map> reflexiveDbEntities = new HashMap>( - 32); + Map> reflexiveDbEntities = new HashMap>(32); Digraph> referentialDigraph = new MapDigraph>(); @@ -115,8 +116,7 @@ public class AshwoodEntitySorter impleme for (DbEntity destination : tableMap.values()) { for (DbRelationship candidate : destination.getRelationships()) { - if ((!candidate.isToMany() && !candidate.isToDependentPK()) - || candidate.isToMasterPK()) { + if ((!candidate.isToMany() && !candidate.isToDependentPK()) || candidate.isToMasterPK()) { DbEntity origin = (DbEntity) candidate.getTargetEntity(); boolean newReflexive = destination.equals(origin); @@ -125,8 +125,7 @@ public class AshwoodEntitySorter impleme if (targetAttribute.isPrimaryKey()) { if (newReflexive) { - List reflexiveRels = reflexiveDbEntities - .get(destination); + List reflexiveRels = reflexiveDbEntities.get(destination); if (reflexiveRels == null) { reflexiveRels = new ArrayList(1); reflexiveDbEntities.put(destination, reflexiveRels); @@ -135,9 +134,7 @@ public class AshwoodEntitySorter impleme newReflexive = false; } - List fks = referentialDigraph.getArc( - origin, - destination); + List fks = referentialDigraph.getArc(origin, destination); if (fks == null) { fks = new ArrayList(); referentialDigraph.putArc(origin, destination, fks); @@ -194,10 +191,7 @@ public class AshwoodEntitySorter impleme Collections.sort(objEntities, getObjEntityComparator(deleteOrder)); } - public void sortObjectsForEntity( - ObjEntity objEntity, - List objects, - boolean deleteOrder) { + public void sortObjectsForEntity(ObjEntity objEntity, List objects, boolean deleteOrder) { indexSorter(); @@ -215,18 +209,14 @@ public class AshwoodEntitySorter impleme return; } - EntityResolver resolver = persistent - .get(0) - .getObjectContext() - .getEntityResolver(); + EntityResolver resolver = persistent.get(0).getObjectContext().getEntityResolver(); ClassDescriptor descriptor = resolver.getClassDescriptor(objEntity.getName()); List reflexiveRels = reflexiveDbEntities.get(dbEntity); String[] reflexiveRelNames = new String[reflexiveRels.size()]; for (int i = 0; i < reflexiveRelNames.length; i++) { DbRelationship dbRel = reflexiveRels.get(i); - ObjRelationship objRel = (dbRel != null ? objEntity - .getRelationshipForDbRelationship(dbRel) : null); + ObjRelationship objRel = (dbRel != null ? objEntity.getRelationshipForDbRelationship(dbRel) : null); reflexiveRelNames[i] = (objRel != null ? objRel.getName() : null); } @@ -245,14 +235,11 @@ public class AshwoodEntitySorter impleme continue; } - masters[k] = descriptor.getProperty(reflexiveRelName).readProperty( - current); + masters[k] = descriptor.getProperty(reflexiveRelName).readProperty(current); if (masters[k] == null) { - masters[k] = findReflexiveMaster( - current, - (ObjRelationship) objEntity.getRelationship(reflexiveRelName), - current.getObjectId().getEntityName()); + masters[k] = findReflexiveMaster(current, objEntity.getRelationship(reflexiveRelName), current + .getObjectId().getEntityName()); } if (masters[k] != null) { @@ -271,24 +258,19 @@ public class AshwoodEntitySorter impleme for (Object master : masters) { // if (masterCandidate.equals(master)) { if (masterCandidate == master) { - objectDependencyGraph.putArc( - masterCandidate, - current, - Boolean.TRUE); + objectDependencyGraph.putArc(masterCandidate, current, Boolean.TRUE); mastersFound++; } } } } - IndegreeTopologicalSort sorter = new IndegreeTopologicalSort( - objectDependencyGraph); + IndegreeTopologicalSort sorter = new IndegreeTopologicalSort(objectDependencyGraph); while (sorter.hasNext()) { Persistent o = sorter.next(); if (o == null) - throw new CayenneRuntimeException("Sorting objects for " - + objEntity.getClassName() + throw new CayenneRuntimeException("Sorting objects for " + objEntity.getClassName() + " failed. Cycles found."); sorted.add(o); } @@ -304,26 +286,22 @@ public class AshwoodEntitySorter impleme } } - protected Object findReflexiveMaster( - Persistent object, - ObjRelationship toOneRel, - String targetEntityName) { + protected Object findReflexiveMaster(Persistent object, ObjRelationship toOneRel, String targetEntityName) { DbRelationship finalRel = toOneRel.getDbRelationships().get(0); ObjectContext context = object.getObjectContext(); - // find committed snapshot - so we can't fetch from the context as it will return + // find committed snapshot - so we can't fetch from the context as it + // will return // dirty snapshot; must go down the stack instead - // how do we handle this for NEW objects correctly? For now bail from the method + // how do we handle this for NEW objects correctly? For now bail from + // the method if (object.getObjectId().isTemporary()) { return null; } - ObjectIdQuery query = new ObjectIdQuery( - object.getObjectId(), - true, - ObjectIdQuery.CACHE); + ObjectIdQuery query = new ObjectIdQuery(object.getObjectId(), true, ObjectIdQuery.CACHE); QueryResponse response = context.getChannel().onQuery(null, query); List result = response.firstList(); if (result == null || result.size() == 0) { @@ -334,8 +312,10 @@ public class AshwoodEntitySorter impleme ObjectId id = snapshot.createTargetObjectId(targetEntityName, finalRel); - // not using 'localObject', looking up in context instead, as within the sorter - // we only care about objects participating in transaction, so no need to create + // not using 'localObject', looking up in context instead, as within the + // sorter + // we only care about objects participating in transaction, so no need + // to create // hollow objects return (id != null) ? context.getGraphManager().getNode(id) : null; } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ClientObjRelationship.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ClientObjRelationship.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ClientObjRelationship.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ClientObjRelationship.java Sun Aug 4 18:04:14 2013 @@ -64,11 +64,11 @@ class ClientObjRelationship extends ObjR return null; } - Entity target = getTargetEntity(); + ObjEntity target = getTargetEntity(); if (target == null) { return null; } - return (ObjRelationship) target.getRelationship(reverseRelationshipName); + return target.getRelationship(reverseRelationshipName); } } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java Sun Aug 4 18:04:14 2013 @@ -967,10 +967,10 @@ public class DataMap implements Serializ if (dbEntityToDelete.getName().equals(objEnt.getDbEntityName())) { objEnt.clearDbMapping(); } else { - for (Relationship rel : objEnt.getRelationships()) { - for (DbRelationship dbRel : ((ObjRelationship) rel).getDbRelationships()) { + for (ObjRelationship rel : objEnt.getRelationships()) { + for (DbRelationship dbRel : rel.getDbRelationships()) { if (dbRel.getTargetEntity() == dbEntityToDelete) { - ((ObjRelationship) rel).clearDbRelationships(); + rel.clearDbRelationships(); break; } } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java Sun Aug 4 18:04:14 2013 @@ -88,10 +88,21 @@ public class DbEntity extends Entity imp this(); this.setName(name); } + + @Override + public DbRelationship getRelationship(String relName) { + return (DbRelationship) super.getRelationship(relName); + } + + @Override + public DbAttribute getAttribute(String attributeName) { + return (DbAttribute) super.getAttribute(attributeName); + } /** * @since 3.1 */ + @Override public T acceptVisitor(ConfigurationNodeVisitor visitor) { return visitor.visitDbEntity(this); } @@ -101,6 +112,7 @@ public class DbEntity extends Entity imp * * @since 1.1 */ + @Override public void encodeAsXML(XMLEncoder encoder) { encoder.print(" getDbFields(EntityResolver resolver) { @@ -62,13 +63,11 @@ public class EntityResult { for (FieldResult field : fields) { if (field.isDbAttribute() || field.getAttributeName().startsWith("fetch.")) { dbFields.put(field.getAttributeName(), field.getColumn()); - } - else { - ObjEntity entity = field.getEntityName() != null ? resolver - .getObjEntity(field.getEntityName()) : getRootEntity(resolver); + } else { + ObjEntity entity = field.getEntityName() != null ? resolver.getObjEntity(field.getEntityName()) + : getRootEntity(resolver); - ObjAttribute attribute = (ObjAttribute) entity.getAttribute(field - .getAttributeName()); + ObjAttribute attribute = entity.getAttribute(field.getAttributeName()); dbFields.put(attribute.getDbAttributePath(), field.getColumn()); } } @@ -79,25 +78,25 @@ public class EntityResult { private ObjEntity getRootEntity(EntityResolver resolver) { if (entityName != null) { return resolver.getObjEntity(entityName); - } - else if (entityClass != null) { + } else if (entityClass != null) { return resolver.getObjEntity(entityClass); - } - else { + } else { throw new IllegalStateException("Both entity name and class are null"); } } /** - * Adds a result set column mapping for a single object property of the root entity. + * Adds a result set column mapping for a single object property of the root + * entity. */ public void addObjectField(String attributeName, String column) { addField(new FieldResult(null, attributeName, column, false)); } /** - * Adds a result set column mapping for a single object property of a specified entity - * that may differ from the root entity if inheritance is involved. + * Adds a result set column mapping for a single object property of a + * specified entity that may differ from the root entity if inheritance is + * involved. */ public void addObjectField(String entityName, String attributeName, String column) { addField(new FieldResult(entityName, attributeName, column, false)); @@ -133,8 +132,7 @@ public class EntityResult { protected String column; protected boolean dbAttribute; - FieldResult(String entityName, String attributeName, String column, - boolean dbAttribute) { + FieldResult(String entityName, String attributeName, String column, boolean dbAttribute) { this.entityName = entityName; this.attributeName = attributeName; @@ -160,11 +158,8 @@ public class EntityResult { @Override public String toString() { - return new ToStringBuilder(this) - .append("attributeName", attributeName) - .append("column", column) - .append("db", dbAttribute) - .toString(); + return new ToStringBuilder(this).append("attributeName", attributeName).append("column", column) + .append("db", dbAttribute).toString(); } } } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java Sun Aug 4 18:04:14 2013 @@ -106,6 +106,7 @@ public class ObjEntity extends Entity im /** * @since 3.1 */ + @Override public T acceptVisitor(ConfigurationNodeVisitor visitor) { return visitor.visitObjEntity(this); } @@ -115,6 +116,7 @@ public class ObjEntity extends Entity im * * @since 1.1 */ + @Override public void encodeAsXML(XMLEncoder encoder) { encoder.print(" 0 && dot < name.length() - 1) { - Attribute embedded = getAttribute(name.substring(0, dot)); + ObjAttribute embedded = getAttribute(name.substring(0, dot)); if (embedded instanceof EmbeddedAttribute) { return ((EmbeddedAttribute) embedded).getAttribute(name.substring(dot + 1)); } @@ -702,7 +704,7 @@ public class ObjEntity extends Entity im ObjEntity superEntity = getSuperEntity(); if (superEntity != null) { - ObjAttribute superAttribute = (ObjAttribute) superEntity.getAttribute(name); + ObjAttribute superAttribute = superEntity.getAttribute(name); if (superAttribute == null) { return null; } @@ -806,7 +808,7 @@ public class ObjEntity extends Entity im * inherited. Returns null if no matching attribute is found. */ @Override - public Relationship getRelationship(String name) { + public ObjRelationship getRelationship(String name) { ObjRelationship relationship = (ObjRelationship) super.getRelationship(name); if (relationship != null) { return relationship; @@ -869,7 +871,7 @@ public class ObjEntity extends Entity im */ public ObjAttribute getAttributeForDbAttribute(DbAttribute dbAttribute) { - for (Attribute next : getAttributeMap().values()) { + for (ObjAttribute next : getAttributeMap().values()) { if (next instanceof EmbeddedAttribute) { ObjAttribute embeddedAttribute = ((EmbeddedAttribute) next) @@ -878,9 +880,8 @@ public class ObjEntity extends Entity im return embeddedAttribute; } } else { - ObjAttribute objAttr = (ObjAttribute) next; - if (objAttr.getDbAttribute() == dbAttribute) { - return objAttr; + if (next.getDbAttribute() == dbAttribute) { + return next; } } } @@ -940,16 +941,15 @@ public class ObjEntity extends Entity im if (dbEntityName == null) return; - for (Attribute attribute : getAttributeMap().values()) { - ObjAttribute objAttr = (ObjAttribute) attribute; - DbAttribute dbAttr = objAttr.getDbAttribute(); + for (ObjAttribute attribute : getAttributeMap().values()) { + DbAttribute dbAttr = attribute.getDbAttribute(); if (null != dbAttr) { - objAttr.setDbAttributePath(null); + attribute.setDbAttributePath(null); } } - for (Relationship relationship : this.getRelationships()) { - ((ObjRelationship) relationship).clearDbRelationships(); + for (ObjRelationship relationship : getRelationships()) { + relationship.clearDbRelationships(); } dbEntityName = null; @@ -1206,8 +1206,8 @@ public class ObjEntity extends Entity im DataMap map = getDataMap(); if (map != null) { ObjEntity oe = (ObjEntity) e.getEntity(); - for (Relationship relationship : oe.getRelationships()) { - relationship = ((ObjRelationship) relationship).getReverseRelationship(); + for (ObjRelationship relationship : oe.getRelationships()) { + relationship = relationship.getReverseRelationship(); if (null != relationship && relationship.targetEntityName.equals(oldName)) { relationship.targetEntityName = newName; } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java Sun Aug 4 18:04:14 2013 @@ -87,6 +87,11 @@ public class ObjRelationship extends Rel super(name); } + @Override + public ObjEntity getSourceEntity() { + return (ObjEntity) super.getSourceEntity(); + } + /** * @since 3.1 */ @@ -151,7 +156,7 @@ public class ObjRelationship extends Rel * the parent DataMap using "targetEntityName". */ @Override - public Entity getTargetEntity() { + public ObjEntity getTargetEntity() { String targetName = getTargetEntityName(); if (targetName == null) { return null; Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/AttributePropertyDecorator.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/AttributePropertyDecorator.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/AttributePropertyDecorator.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/AttributePropertyDecorator.java Sun Aug 4 18:04:14 2013 @@ -21,8 +21,8 @@ package org.apache.cayenne.reflect; import org.apache.cayenne.map.ObjAttribute; /** - * A class that presents an AttributeProperty view for an inherited attribute at a given - * subclass. It applies all needed attribute overrides. + * A class that presents an AttributeProperty view for an inherited attribute at + * a given subclass. It applies all needed attribute overrides. * * @since 3.0 */ @@ -31,12 +31,10 @@ class AttributePropertyDecorator impleme private AttributeProperty delegate; private ObjAttribute attribute; - AttributePropertyDecorator(ClassDescriptor owningClassDescriptor, - AttributeProperty delegate) { + AttributePropertyDecorator(ClassDescriptor owningClassDescriptor, AttributeProperty delegate) { this.delegate = delegate; - this.attribute = (ObjAttribute) owningClassDescriptor.getEntity().getAttribute( - delegate.getName()); + this.attribute = owningClassDescriptor.getEntity().getAttribute(delegate.getName()); } public ObjAttribute getAttribute() { @@ -63,13 +61,11 @@ class AttributePropertyDecorator impleme return delegate.readPropertyDirectly(object); } - public void writeProperty(Object object, Object oldValue, Object newValue) - throws PropertyException { + public void writeProperty(Object object, Object oldValue, Object newValue) throws PropertyException { delegate.writeProperty(object, oldValue, newValue); } - public void writePropertyDirectly(Object object, Object oldValue, Object newValue) - throws PropertyException { + public void writePropertyDirectly(Object object, Object oldValue, Object newValue) throws PropertyException { delegate.writePropertyDirectly(object, oldValue, newValue); } } Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/BaseArcProperty.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/BaseArcProperty.java?rev=1510286&r1=1510285&r2=1510286&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/BaseArcProperty.java (original) +++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/BaseArcProperty.java Sun Aug 4 18:04:14 2013 @@ -31,16 +31,14 @@ public abstract class BaseArcProperty ex protected ClassDescriptor targetDescriptor; protected ObjRelationship relationship; - public BaseArcProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor, - Accessor accessor, String reverseName) { + public BaseArcProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor, Accessor accessor, + String reverseName) { super(owner, accessor); this.targetDescriptor = targetDescriptor; this.complimentaryReverseArcName = reverseName; - this.relationship = (ObjRelationship) owner - .getEntity() - .getRelationship(getName()); + this.relationship = owner.getEntity().getRelationship(getName()); } @Override @@ -63,10 +61,7 @@ public abstract class BaseArcProperty ex /** * A convenience method to set the reverse arc used by subclasses. */ - protected void setReverse( - final Object source, - final Object oldTarget, - final Object newTarget) { + protected void setReverse(final Object source, final Object oldTarget, final Object newTarget) { ArcProperty reverseArc = getComplimentaryReverseArc();