r2662 - branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out
Author: tchemit Date: 2012-09-13 06:51:15 +0200 (Thu, 13 Sep 2012) New Revision: 2662 Url: http://nuiton.org/repositories/revision/topia/2662 Log: fixes #2311: Improve entity visitor to export as csv files Removed: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/Entity2.java Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java Deleted: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/Entity2.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/Entity2.java 2012-09-12 15:04:21 UTC (rev 2661) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/Entity2.java 2012-09-13 04:51:15 UTC (rev 2662) @@ -1,40 +0,0 @@ -package org.nuiton.topia.persistence.csv.out; -/* - * #%L - * ToPIA :: Persistence - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.topia.persistence.EntityVisitor; -import org.nuiton.topia.persistence.TopiaEntity; - -/** - * To mark some entites visitable but not by generatl - * {@link TopiaEntity#accept(EntityVisitor)} method. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.6.12 - */ -public interface Entity2 { - - void accept2(EntityVisitor visitor); - -} Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2012-09-12 15:04:21 UTC (rev 2661) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2012-09-13 04:51:15 UTC (rev 2662) @@ -155,24 +155,26 @@ if (CollectionUtils.isNotEmpty(cValue)) { - if (isNoChildVisit(propertyName, entity) && - Entity2.class.isAssignableFrom(type)) { + visitEntityCollection(entity, + propertyName, + collectionType, + type, + cValue); + } + } + } - // special case, when visiting a entity with no child - // visisting at this time... - for (Object currentValue : cValue) { - ((Entity2) currentValue).accept2(this); - } - } else { - for (Object currentValue : cValue) { - try { - ((TopiaEntity) currentValue).accept(this); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Can not visit entity " + value, e); - } - } - } + protected void visitEntityCollection(TopiaEntity entity, + String propertyName, + Class<?> collectionType, + Class<?> type, + Collection<?> cValue) { + for (Object currentValue : cValue) { + try { + ((TopiaEntity) currentValue).accept(this); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Can not visit entity " + currentValue, e); } } } @@ -207,10 +209,4 @@ T entityEnum = persistenceHelper.getEntityEnum(entityType); return entityEnum == null ? null : entityExporters.get(entityEnum); } - - protected boolean isNoChildVisit(String propertyName, TopiaEntity entity) { - - // by default accept all associations - return false; - } }
participants (1)
-
tchemit@users.nuiton.org