details: /erp/devel/pi/rev/c1ecf803c62a
changeset: 8009:c1ecf803c62a
user: Martin Taal <martin.taal <at> openbravo.com>
date: Tue Aug 03 14:52:10 2010 +0200
summary: Fixes issue 14080: When exporting and then importing the client in
the same environment i get and error
diffstat:
src/org/openbravo/service/db/DataImportService.java | 25 ++++++++++++++++----
1 files changed, 20 insertions(+), 5 deletions(-)
diffs (68 lines):
diff -r d42db16889e8 -r c1ecf803c62a
src/org/openbravo/service/db/DataImportService.java
--- a/src/org/openbravo/service/db/DataImportService.java Tue Aug 03
17:08:58 2010 +0530
+++ b/src/org/openbravo/service/db/DataImportService.java Tue Aug 03
14:52:10 2010 +0200
@@ -211,8 +211,7 @@
final Set<BaseOBObject> inserted = new HashSet<BaseOBObject>();
for (int i = toInsert.size() - 1; i > -1; i--) {
final BaseOBObject ins = toInsert.get(i);
- // for (final BaseOBObject ins : toInsert) {
- insertObjectGraph(ins, inserted);
+ insertObjectGraph(ins, inserted, new HashSet<BaseOBObject>());
ir.getInsertedObjects().add(ins);
done++;
}
@@ -514,7 +513,7 @@
for (int i = toInsert.size() - 1; i > -1; i--) {
final BaseOBObject ins = toInsert.get(i);
// for (final BaseOBObject ins : toInsert) {
- insertObjectGraph(ins, inserted);
+ insertObjectGraph(ins, inserted, new HashSet<BaseOBObject>());
ir.getInsertedObjects().add(ins);
done++;
}
@@ -581,27 +580,43 @@
// which have not been inserted yet
// this works fine as long the graph has no cycles
// if there are cycles then Hibernate needs to resolve those
- private void insertObjectGraph(BaseOBObject toInsert, Set<BaseOBObject>
inserted) {
+ private void insertObjectGraph(BaseOBObject toInsert, Set<BaseOBObject>
inserted,
+ Set<BaseOBObject> cycleDetect) {
// prevent infinite looping and don't do the ones we already inserted
// in a previous objectgraph
+ if (cycleDetect.contains(toInsert)) {
+ // just save it for now and hope for the best...
+ try {
+ OBDal.getInstance().save(toInsert);
+ } catch (final Exception e) {
+ log.warn("There was a problem inserting data in the database.");
+ log.info("The following exception was raised: ", e);
+ throw new OBException(e);
+ }
+ cycleDetect.remove(toInsert);
+ return;
+ }
if (inserted.contains(toInsert)) {
return;
}
inserted.add(toInsert);
+ cycleDetect.add(toInsert);
final Entity entity = toInsert.getEntity();
for (final Property property : entity.getProperties()) {
if (!property.isPrimitive() && !property.isOneToMany()) {
final Object value = toInsert.get(property.getName());
if (value instanceof BaseOBObject && ((BaseOBObject)
value).isNewOBObject()) {
- insertObjectGraph((BaseOBObject) value, inserted);
+ insertObjectGraph((BaseOBObject) value, inserted, cycleDetect);
}
}
}
+ cycleDetect.remove(toInsert);
try {
OBDal.getInstance().save(toInsert);
} catch (final Exception e) {
log.warn("There was a problem inserting data in the database.");
log.info("The following exception was raised: ", e);
+ throw new OBException(e);
}
}
}
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits