details: http://code.openbravo.com/erp/devel/pi/rev/152f2de78d13 changeset: 3536:152f2de78d13 user: Martin Taal <martin.taal <at> openbravo.com> date: Tue Apr 07 11:16:42 2009 +0200 summary: Fixes issue 8442: 2.50 beta Training: can not save to Main org for imported Client
diffstat: src-db/database/sourcedata/AD_COLUMN.xml | 2 +- src/org/openbravo/dal/core/DalMappingGenerator.java | 5 ++- src/org/openbravo/dal/core/SessionHandler.java | 4 +- src/org/openbravo/service/db/DataImportService.java | 48 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diffs (164 lines): diff -r 3bfd7f18ca98 -r 152f2de78d13 src-db/database/sourcedata/AD_COLUMN.xml --- a/src-db/database/sourcedata/AD_COLUMN.xml Tue Apr 07 13:06:43 2009 +0530 +++ b/src-db/database/sourcedata/AD_COLUMN.xml Tue Apr 07 11:16:42 2009 +0200 @@ -43240,7 +43240,7 @@ <!--2876--> <COLUMNNAME><![CDATA[Node_ID]]></COLUMNNAME> <!--2876--> <AD_TABLE_ID><![CDATA[289]]></AD_TABLE_ID> <!--2876--> <AD_REFERENCE_ID><![CDATA[10]]></AD_REFERENCE_ID> -<!--2876--> <FIELDLENGTH><![CDATA[22]]></FIELDLENGTH> +<!--2876--> <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH> <!--2876--> <ISKEY><![CDATA[N]]></ISKEY> <!--2876--> <ISPARENT><![CDATA[N]]></ISPARENT> <!--2876--> <ISMANDATORY><![CDATA[Y]]></ISMANDATORY> diff -r 3bfd7f18ca98 -r 152f2de78d13 src/org/openbravo/dal/core/DalMappingGenerator.java --- a/src/org/openbravo/dal/core/DalMappingGenerator.java Tue Apr 07 13:06:43 2009 +0530 +++ b/src/org/openbravo/dal/core/DalMappingGenerator.java Tue Apr 07 11:16:42 2009 +0200 @@ -182,7 +182,10 @@ // sb.append(" not-null=\"true\""); // } - if (!p.isUpdatable() || p.isInactive()) { + // ignoring isUpdatable for now as this is primarily used + // for ui and not for background processes + // if (!p.isUpdatable() || p.isInactive()) { + if (p.isInactive()) { sb.append(" update=\"false\""); } if (p.isInactive()) { diff -r 3bfd7f18ca98 -r 152f2de78d13 src/org/openbravo/dal/core/SessionHandler.java --- a/src/org/openbravo/dal/core/SessionHandler.java Tue Apr 07 13:06:43 2009 +0530 +++ b/src/org/openbravo/dal/core/SessionHandler.java Tue Apr 07 11:16:42 2009 +0200 @@ -110,9 +110,9 @@ */ public void save(Object obj) { if (Identifiable.class.isAssignableFrom(obj.getClass())) { - session.save(((Identifiable) obj).getEntityName(), obj); + session.saveOrUpdate(((Identifiable) obj).getEntityName(), obj); } else { - session.save(obj); + session.saveOrUpdate(obj); } } diff -r 3bfd7f18ca98 -r 152f2de78d13 src/org/openbravo/service/db/DataImportService.java --- a/src/org/openbravo/service/db/DataImportService.java Tue Apr 07 13:06:43 2009 +0530 +++ b/src/org/openbravo/service/db/DataImportService.java Tue Apr 07 11:16:42 2009 +0200 @@ -20,6 +20,7 @@ package org.openbravo.service.db; import java.io.Reader; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -48,6 +49,7 @@ import org.openbravo.model.ad.module.Module; import org.openbravo.model.ad.system.Client; import org.openbravo.model.ad.utility.ReferenceDataStore; +import org.openbravo.model.ad.utility.TreeNode; import org.openbravo.model.common.enterprise.Organization; /** @@ -199,6 +201,7 @@ // now save and update // do inserts and updates in opposite order, this is important // so that the objects on which other depend are inserted first + final List<TreeNode> treeNodes = new ArrayList<TreeNode>(); final List<BaseOBObject> toInsert = xec.getToInsert(); int done = 0; final Set<BaseOBObject> inserted = new HashSet<BaseOBObject>(); @@ -208,6 +211,13 @@ insertObjectGraph(ins, inserted); ir.getInsertedObjects().add(ins); done++; + + if (ins instanceof TreeNode) { + final TreeNode tn = (TreeNode) ins; + if (tn.getTree().getTypeArea().equals("OO")) { + treeNodes.add(tn); + } + } } Check.isTrue(done == toInsert.size(), "Not all objects have been inserted, check for loop: " + done + "/" + toInsert.size()); @@ -223,6 +233,13 @@ OBDal.getInstance().save(upd); ir.getUpdatedObjects().add(upd); done++; + + if (upd instanceof TreeNode) { + final TreeNode tn = (TreeNode) upd; + if (tn.getTree().getTypeArea().equals("OO")) { + treeNodes.add(tn); + } + } } Check.isTrue(done == toUpdate.size(), "Not all objects have been inserted, check for loop: " + done + "/" + toUpdate.size()); @@ -230,7 +247,18 @@ // flush to set the ids in the objects OBDal.getInstance().flush(); + // now walk through the treenodes to repair id's + for (TreeNode tn : treeNodes) { + final Organization org = (Organization) xec.getEntityResolver().resolve( + Organization.ENTITY_NAME, tn.getNode(), true); + if (!org.getId().equals(tn.getNode())) { + tn.setNode(org.getId()); + } + } + OBDal.getInstance().flush(); } catch (final Throwable t) { + OBDal.getInstance().rollbackAndClose(); + rolledBack = true; t.printStackTrace(System.err); ir.setException(t); } finally { @@ -343,6 +371,7 @@ // now save and update // do inserts and updates in opposite order, this is important // so that the objects on which other depend are inserted first + final List<TreeNode> treeNodes = new ArrayList<TreeNode>(); final List<BaseOBObject> toInsert = xec.getToInsert(); int done = 0; final Set<BaseOBObject> inserted = new HashSet<BaseOBObject>(); @@ -352,6 +381,13 @@ insertObjectGraph(ins, inserted); ir.getInsertedObjects().add(ins); done++; + + if (ins instanceof TreeNode) { + final TreeNode tn = (TreeNode) ins; + if (tn.getTree().getTypeArea().equals("OO")) { + treeNodes.add(tn); + } + } } Check.isTrue(done == toInsert.size(), "Not all objects have been inserted, check for loop: " + done + "/" + toInsert.size()); @@ -374,6 +410,16 @@ // flush to set the ids in the objects OBDal.getInstance().flush(); + // now walk through the treenodes to repair id's + for (TreeNode tn : treeNodes) { + final Organization org = (Organization) xec.getEntityResolver().resolve( + Organization.ENTITY_NAME, tn.getNode(), true); + if (!org.getId().equals(tn.getNode())) { + tn.setNode(org.getId()); + } + } + OBDal.getInstance().flush(); + // store the ad_ref_data_loaded if (!isClientImport) { OBContext.getOBContext().setInAdministratorMode(true); @@ -405,6 +451,8 @@ } } } catch (final Throwable t) { + OBDal.getInstance().rollbackAndClose(); + rolledBack = true; t.printStackTrace(System.err); ir.setException(t); } finally { ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits