From: Alexey L. <lou...@us...> - 2003-01-31 14:11:25
|
User: loubyansky Date: 03/01/31 06:11:24 Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge JDBCEntityBridge.java Log: fix for [675932]: modified getDirtyFields() to return instead of CMR fields its foreign key fields that are mapped to its own columns (not primary key) Revision Changes Path 1.34 +26 -19 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCEntityBridge.java Index: JDBCEntityBridge.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCEntityBridge.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- JDBCEntityBridge.java 11 Dec 2002 18:46:23 -0000 1.33 +++ JDBCEntityBridge.java 31 Jan 2003 14:11:23 -0000 1.34 @@ -61,7 +61,7 @@ * * @author <a href="mailto:da...@da...">Dain Sundstrom</a> * @author <a href="mailto:lou...@ua...">Alex Loubyansky</a> - * @version $Revision: 1.33 $ + * @version $Revision: 1.34 $ */ public class JDBCEntityBridge implements EntityBridge { private JDBCEntityMetaData metadata; @@ -148,7 +148,7 @@ fieldsByName = Collections.unmodifiableMap(fieldsByName); // ejbSelect methods - loadSelectors(metadata); + loadSelectors(metadata); } public void resolveRelationships() throws DeploymentException { @@ -227,9 +227,6 @@ /** * Loads the specified load groups. - * Note: if optimistic locking is specified then - * optimistic locking fields are added each group to - * ensure the locking fields are always loaded */ private void loadLoadGroups(JDBCEntityMetaData metadata) throws DeploymentException { @@ -416,8 +413,8 @@ return primaryKeyFields; } - public List getFields() { - return fields; + public List getFields() { + return fields; } public FieldBridge getFieldByName(String name) { @@ -433,7 +430,7 @@ } return field; } - + public List getCMPFields() { return cmpFields; } @@ -457,13 +454,13 @@ public JDBCCMPFieldBridge getCMPFieldByName(String name) { return (JDBCCMPFieldBridge)cmpFieldsByName.get(name); } - + private JDBCCMPFieldBridge getExistingCMPFieldByName(String name) throws DeploymentException { JDBCCMPFieldBridge cmpField = getCMPFieldByName(name); if(cmpField == null) { - throw new DeploymentException("cmpField not found: " + + throw new DeploymentException("cmpField not found: " + "cmpFieldName="+name + " entityName=" + getEntityName()); } return cmpField; @@ -472,7 +469,7 @@ public List getCMRFields() { return cmrFields; } - + public JDBCCMRFieldBridge getCMRFieldByName(String name) { return (JDBCCMRFieldBridge)cmrFieldsByName.get(name); } @@ -506,25 +503,35 @@ field.setClean(ctx); } } - + + /** + * Returns the list of dirty fields. + * Note: instead of CMR fields its foreign key fields are + * included + */ public List getDirtyFields(EntityEnterpriseContext ctx) { List dirtyFields = new ArrayList(fields.size()); - for(Iterator iter = fields.iterator(); iter.hasNext();) { - JDBCFieldBridge field = (JDBCFieldBridge)iter.next(); - if(field.isDirty(ctx)) { - dirtyFields.add(field); + JDBCFieldBridge field = (JDBCFieldBridge)iter.next(); + if(field instanceof JDBCCMRFieldBridge) { + List dirtyFkFields = ((JDBCCMRFieldBridge)field).getDirtyForeignKeyFields(ctx); + if(!dirtyFkFields.isEmpty()) + dirtyFields.addAll(dirtyFkFields); + } else { + if(field.isDirty(ctx)) { + dirtyFields.add(field); + } } - } + } return dirtyFields; } - + public void initPersistenceContext(EntityEnterpriseContext ctx) { // If we have an EJB 2.0 dynaymic proxy, // notify the handler of the assigned context. Object instance = ctx.getInstance(); if(instance instanceof Proxies.ProxyTarget) { - InvocationHandler handler = + InvocationHandler handler = ((Proxies.ProxyTarget)instance).getInvocationHandler(); if(handler instanceof EntityBridgeInvocationHandler) { ((EntityBridgeInvocationHandler)handler).setContext(ctx); |