details: /erp/devel/pi/rev/7d709e2f9e73
changeset: 8004:7d709e2f9e73
user: Martin Taal <martin.taal <at> openbravo.com>
date: Mon Aug 02 22:08:08 2010 +0200
summary: Backed out changeset 4e8a51c71835
diffstat:
src/org/openbravo/service/db/DataImportService.java | 54 +++-----------------
1 files changed, 10 insertions(+), 44 deletions(-)
diffs (97 lines):
diff -r 4e8a51c71835 -r 7d709e2f9e73
src/org/openbravo/service/db/DataImportService.java
--- a/src/org/openbravo/service/db/DataImportService.java Mon Aug 02
19:15:57 2010 +0200
+++ b/src/org/openbravo/service/db/DataImportService.java Mon Aug 02
22:08:08 2010 +0200
@@ -208,27 +208,12 @@
// so that the objects on which other depend are inserted first
final List<BaseOBObject> toInsert = xec.getToInsert();
int done = 0;
- final Set<BaseOBObject> visited = new HashSet<BaseOBObject>();
final Set<BaseOBObject> inserted = new HashSet<BaseOBObject>();
for (int i = toInsert.size() - 1; i > -1; i--) {
-
final BaseOBObject ins = toInsert.get(i);
-
- // use a temporary visited which is not used in the second round
- final Set<BaseOBObject> tempVisited = new
HashSet<BaseOBObject>(inserted);
-
- // insert the mandatory properties
- insertObjectGraph(ins, tempVisited, inserted, true);
-
- // insert the non-mandatory references
- insertObjectGraph(ins, visited, inserted, null);
-
- if ((i % 100) == 0) {
- OBDal.getInstance().flush();
- }
-
+ // for (final BaseOBObject ins : toInsert) {
+ insertObjectGraph(ins, inserted);
ir.getInsertedObjects().add(ins);
-
done++;
}
Check.isTrue(done == toInsert.size(),
@@ -526,20 +511,11 @@
final List<BaseOBObject> toInsert = xec.getToInsert();
int done = 0;
final Set<BaseOBObject> inserted = new HashSet<BaseOBObject>();
- final Set<BaseOBObject> visited = new HashSet<BaseOBObject>();
for (int i = toInsert.size() - 1; i > -1; i--) {
final BaseOBObject ins = toInsert.get(i);
-
- // use a temporary visited which is not used in the second round
- final Set<BaseOBObject> tempVisited = new
HashSet<BaseOBObject>(inserted);
-
- insertObjectGraph(ins, tempVisited, inserted, true);
- insertObjectGraph(ins, visited, inserted, null);
-
- OBDal.getInstance().flush();
-
+ // for (final BaseOBObject ins : toInsert) {
+ insertObjectGraph(ins, inserted);
ir.getInsertedObjects().add(ins);
-
done++;
}
Check.isTrue(done == toInsert.size(), "Not all objects have been inserted,
check for loop: "
@@ -605,34 +581,24 @@
// 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
- // the mandatory parameter is used to first insert only mandatory properties
- // to take care of cylic relations, i.e. that at least first the mandatory
- // properties are saved.
- // This method is called twice with first the mandatory on true and then
with the
- // value null. Between the 2 calls the inserted Set is cleared.
- private void insertObjectGraph(BaseOBObject toInsert, Set<BaseOBObject>
visited,
- Set<BaseOBObject> inserted, Boolean mandatory) {
+ private void insertObjectGraph(BaseOBObject toInsert, Set<BaseOBObject>
inserted) {
// prevent infinite looping and don't do the ones we already inserted
// in a previous objectgraph
- if (visited.contains(toInsert)) {
+ if (inserted.contains(toInsert)) {
return;
}
- visited.add(toInsert);
+ inserted.add(toInsert);
final Entity entity = toInsert.getEntity();
for (final Property property : entity.getProperties()) {
- if (!property.isPrimitive() && !property.isOneToMany()
- && (mandatory == null || property.isMandatory() == mandatory)) {
+ if (!property.isPrimitive() && !property.isOneToMany()) {
final Object value = toInsert.get(property.getName());
if (value instanceof BaseOBObject && ((BaseOBObject)
value).isNewOBObject()) {
- insertObjectGraph((BaseOBObject) value, visited, inserted,
mandatory);
+ insertObjectGraph((BaseOBObject) value, inserted);
}
}
}
try {
- if (!inserted.contains(toInsert)) {
- inserted.add(toInsert);
- OBDal.getInstance().save(toInsert);
- }
+ 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);
------------------------------------------------------------------------------
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