Author: tchemit Date: 2012-04-10 19:45:16 +0200 (Tue, 10 Apr 2012) New Revision: 515 Url: http://forge.codelutin.com/repositories/revision/echobase/515 Log: fixes #1102: La cr?\195?\169ation d'une base embarqu?\195?\169e ne fonctionne pas avec les donn?\195?\169es 2011 Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ReplicateEntityVisitor.java Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ReplicateEntityVisitor.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ReplicateEntityVisitor.java 2012-04-10 17:06:05 UTC (rev 514) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ReplicateEntityVisitor.java 2012-04-10 17:45:16 UTC (rev 515) @@ -26,10 +26,11 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import fr.ifremer.echobase.EchoBaseTechnicalException; import fr.ifremer.echobase.csv.EntityExportContext; import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.entities.data.Cell; +import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.meta.AssociationMeta; import fr.ifremer.echobase.entities.meta.MetaFilenameAware; import fr.ifremer.echobase.entities.meta.TableMeta; @@ -44,11 +45,8 @@ import org.nuiton.util.csv.ExportModel; import java.io.File; -import java.util.ArrayDeque; import java.util.Collection; -import java.util.Deque; import java.util.Map; -import java.util.Set; /** * entity visitor to export data to csv files. @@ -65,10 +63,10 @@ public static final TimeLog TIME_LOG = new TimeLog(ReplicateEntityVisitor.class); - protected Set<String> ids = Sets.newHashSetWithExpectedSize(2000000000); +// protected Set<String> ids = Sets.newHashSetWithExpectedSize(2000000000); +// +// protected Deque<String> stack = new ArrayDeque<String>(); - protected Deque<String> stack = new ArrayDeque<String>(); - public static ReplicateEntityVisitor createVisitor(ExportService service, MetaFilenameAware[] entityMetas, Multimap<EchoBaseEntityEnum, MetaFilenameAware> associations, @@ -137,16 +135,16 @@ public void start(TopiaEntity entity) { String topiaId = entity.getTopiaId(); try { - stack.push(topiaId); - boolean added = ids.add(topiaId); - if (!added) { - - // Never do me! can not accept to treat twice an object - throw new EchoBaseTechnicalException( - "Wanted to treat twice entity " + topiaId + - "\n Current stack " + stack.toString()); - - } +// stack.push(topiaId); +// boolean added = ids.add(topiaId); +// if (!added) { +// +// // Never do me! can not accept to treat twice an object +// throw new EchoBaseTechnicalException( +// "Wanted to treat twice entity " + topiaId + +// "\n Current stack " + stack.toString()); +// +// } if (log.isDebugEnabled()) { log.debug("Starts export of entity " + topiaId); } @@ -165,7 +163,7 @@ @Override public void end(TopiaEntity entity) { - stack.pop(); +// stack.pop(); try { if (log.isDebugEnabled()) { log.debug("Starts export of association of entity " + @@ -204,17 +202,35 @@ if (CollectionUtils.isNotEmpty(cValue)) { - int i = 0; - for (Object currentValue : cValue) { - TopiaEntity currentEntity = (TopiaEntity) currentValue; - visit(entity, - propertyName, - type, - collectionType, - i++, - currentEntity - ); + if (Voyage.PROPERTY_POST_CELL.equals(propertyName) + && entity instanceof Voyage) { + // special case, when visiting cells from Voyage entity, + // let's not visit cells childs (they will be visited later + // by the DataProcessing himself) + for (Object currentValue : cValue) { + ((Cell) currentValue).acceptWithNoChilds(this); + } + } else { + int i = 0; + for (Object currentValue : cValue) { + TopiaEntity currentEntity = (TopiaEntity) currentValue; + try { + currentEntity.accept(this); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Can not visit entity " + value, e); + } + } + visit(entity, + propertyName, + type, + collectionType, + i++, + currentEntity + ); + + } } } } @@ -226,13 +242,15 @@ Class<?> collectionType, Class<?> type, int index, Object value) { - try { - ((TopiaEntity) value).accept(this); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Can not visit entity " + value, e); - } - } + + // not used here! +// try { +// ((TopiaEntity) value).accept(this); +// } catch (TopiaException e) { +// if (log.isErrorEnabled()) { +// log.error("Can not visit entity " + value, e); +// } +// } } @Override