Author: tchemit Date: 2011-12-05 09:22:27 +0100 (Mon, 05 Dec 2011) New Revision: 141 Url: http://forge.codelutin.com/repositories/revision/echobase/141 Log: -add AssociationMeta -denormalize ExportSql and ModificationLog entities (no more FK on EchoBaseUser) -add replication service configuration (but may not be used...) -add entities order to import/export global db Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java Removed: trunk/echobase-entities/src/test/resources/echobase.properties Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java trunk/echobase-entities/src/main/resources/topia-h2.properties trunk/echobase-entities/src/main/xmi/echobase.zargo Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-12-05 08:22:27 UTC (rev 141) @@ -55,62 +55,115 @@ result.add(EchoBaseEntityEnum.Result); result.add(EchoBaseEntityEnum.Operation); result.add(EchoBaseEntityEnum.OperationMetadataValue); - result.add(EchoBaseEntityEnum.Individual); result.add(EchoBaseEntityEnum.OperationGearMetadataValue); result.add(EchoBaseEntityEnum.Sample); result.add(EchoBaseEntityEnum.SampleData); - result.add(EchoBaseEntityEnum.SampleAge); return result.toArray(new EchoBaseEntityEnum[result.size()]); } /** + * @return the entity types of data in correct order for replication + * purpose. + */ + public static EchoBaseEntityEnum[] getDataTypesforCopy() { + + List<EchoBaseEntityEnum> result = Lists.newLinkedList(); + + result.add(EchoBaseEntityEnum.SampleData); + result.add(EchoBaseEntityEnum.Sample); + + result.add(EchoBaseEntityEnum.OperationMetadataValue); + result.add(EchoBaseEntityEnum.OperationGearMetadataValue); + result.add(EchoBaseEntityEnum.Operation); + + result.add(EchoBaseEntityEnum.Data); + result.add(EchoBaseEntityEnum.Result); + result.add(EchoBaseEntityEnum.Cell); + result.add(EchoBaseEntityEnum.DataProcessing); + result.add(EchoBaseEntityEnum.DataAcquisition); + result.add(EchoBaseEntityEnum.TransectAcousticInstrument); + result.add(EchoBaseEntityEnum.Transect); + result.add(EchoBaseEntityEnum.TransitVessel); + result.add(EchoBaseEntityEnum.Transit); + result.add(EchoBaseEntityEnum.Voyage); + + return result.toArray(new EchoBaseEntityEnum[result.size()]); + } + + /** * @return the entity types of reference in correct order for replication * purpose. */ public static EchoBaseEntityEnum[] getReferenceTypes() { List<EchoBaseEntityEnum> result = Lists.newLinkedList(); - result.add(EchoBaseEntityEnum.Mission); - result.add(EchoBaseEntityEnum.Echotype); - result.add(EchoBaseEntityEnum.TSParameters); + result.add(EchoBaseEntityEnum.MeasureType); + result.add(EchoBaseEntityEnum.DataType); + result.add(EchoBaseEntityEnum.ReferenceDatumType); + result.add(EchoBaseEntityEnum.VesselType); result.add(EchoBaseEntityEnum.EchotypeCategory); + result.add(EchoBaseEntityEnum.Localisation); + result.add(EchoBaseEntityEnum.CellMethod); result.add(EchoBaseEntityEnum.AcousticInstrument); - result.add(EchoBaseEntityEnum.AreaOfOperation); - result.add(EchoBaseEntityEnum.Calibration); - result.add(EchoBaseEntityEnum.Category); + result.add(EchoBaseEntityEnum.CategoryType); + result.add(EchoBaseEntityEnum.GearType); result.add(EchoBaseEntityEnum.CategoryMeaning); - result.add(EchoBaseEntityEnum.CategoryRef); - result.add(EchoBaseEntityEnum.CategoryType); - result.add(EchoBaseEntityEnum.CellMethod); - result.add(EchoBaseEntityEnum.CellType); - result.add(EchoBaseEntityEnum.DataMetadata); - result.add(EchoBaseEntityEnum.DataType); - result.add(EchoBaseEntityEnum.DataQuality); - result.add(EchoBaseEntityEnum.DepthStratum); + result.add(EchoBaseEntityEnum.Species); result.add(EchoBaseEntityEnum.DepthStratumType); - result.add(EchoBaseEntityEnum.Gear); result.add(EchoBaseEntityEnum.GearCaracteristic); + result.add(EchoBaseEntityEnum.ReferenceDatum); + result.add(EchoBaseEntityEnum.DepthStratum); + result.add(EchoBaseEntityEnum.Category); + result.add(EchoBaseEntityEnum.ReferencingMethod); + result.add(EchoBaseEntityEnum.GearMetadataValue); result.add(EchoBaseEntityEnum.GearMetadata); - result.add(EchoBaseEntityEnum.GearMetadataValue); - result.add(EchoBaseEntityEnum.GearType); + result.add(EchoBaseEntityEnum.Calibration); + result.add(EchoBaseEntityEnum.OperationType); + result.add(EchoBaseEntityEnum.MeasurementMetadata); + result.add(EchoBaseEntityEnum.SampleDataType); + result.add(EchoBaseEntityEnum.Vessel); + result.add(EchoBaseEntityEnum.SampleRatioType); + result.add(EchoBaseEntityEnum.Echotype); + result.add(EchoBaseEntityEnum.DataMetadata); + result.add(EchoBaseEntityEnum.CellType); result.add(EchoBaseEntityEnum.Impacte); - result.add(EchoBaseEntityEnum.Localisation); - result.add(EchoBaseEntityEnum.MeasurementMetadata); - result.add(EchoBaseEntityEnum.MeasureType); + result.add(EchoBaseEntityEnum.Mission); result.add(EchoBaseEntityEnum.OperationMetadata); - result.add(EchoBaseEntityEnum.OperationType); - result.add(EchoBaseEntityEnum.ReferenceDatum); - result.add(EchoBaseEntityEnum.ReferenceDatumType); - result.add(EchoBaseEntityEnum.ReferencingMethod); + result.add(EchoBaseEntityEnum.Station); + result.add(EchoBaseEntityEnum.AreaOfOperation); + result.add(EchoBaseEntityEnum.CategoryRef); + result.add(EchoBaseEntityEnum.DataQuality); result.add(EchoBaseEntityEnum.SampleTag); - result.add(EchoBaseEntityEnum.SampleDataType); - result.add(EchoBaseEntityEnum.SampleRatioType); + result.add(EchoBaseEntityEnum.TSParameters); + result.add(EchoBaseEntityEnum.Gear); + return result.toArray(new EchoBaseEntityEnum[result.size()]); + } + + /** + * @return the entity types of reference in correct order for copy + * purpose (says import / export of all a database. + */ + public static EchoBaseEntityEnum[] getReferenceTypesForCopy() { + List<EchoBaseEntityEnum> result = Lists.newLinkedList(); + result.add(EchoBaseEntityEnum.Species); - result.add(EchoBaseEntityEnum.Station); + result.add(EchoBaseEntityEnum.Calibration); + result.add(EchoBaseEntityEnum.AcousticInstrument); + result.add(EchoBaseEntityEnum.TSParameters); + result.add(EchoBaseEntityEnum.VesselType); result.add(EchoBaseEntityEnum.Vessel); - result.add(EchoBaseEntityEnum.VesselType); + result.add(EchoBaseEntityEnum.Mission); + result.add(EchoBaseEntityEnum.DepthStratumType); + result.add(EchoBaseEntityEnum.DepthStratum); + result.add(EchoBaseEntityEnum.EchotypeCategory); + result.add(EchoBaseEntityEnum.Echotype); + result.add(EchoBaseEntityEnum.AreaOfOperation); + result.add(EchoBaseEntityEnum.ReferenceDatumType); + result.add(EchoBaseEntityEnum.ReferenceDatum); + result.add(EchoBaseEntityEnum.DataType); + result.add(EchoBaseEntityEnum.CellMethod); + result.add(EchoBaseEntityEnum.DataMetadata); return result.toArray(new EchoBaseEntityEnum[result.size()]); } - } Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java 2011-12-05 08:22:27 UTC (rev 141) @@ -40,7 +40,7 @@ result.setEntityId(getEntityId()); result.setModificationDate(getModificationDate()); result.setModificationText(getModificationText()); - result.setModificationUser(getModificationUser().toDTO()); + result.setModificationUser(getModificationUser()); return result; } } Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java 2011-12-05 08:22:27 UTC (rev 141) @@ -39,7 +39,7 @@ dto.setDescription(getDescription()); dto.setId(getTopiaId()); dto.setLastModifiedDate(getLastModifiedDate()); - dto.setLastModifiedUser(getLastModifiedUser().toDTO()); + dto.setLastModifiedUser(getLastModifiedUser()); dto.setName(getName()); dto.setSqlQuery(getSqlQuery()); return dto; Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java 2011-12-05 08:22:27 UTC (rev 141) @@ -0,0 +1,110 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.entities.meta; + +import fr.ifremer.echobase.entities.EchoBaseDAOHelper; +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.util.EntityOperator; +import org.nuiton.util.ObjectUtil; + +import java.io.Serializable; +import java.util.Collection; + +/** + * Define the meta data of a entity association field. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class AssociationMeta implements Serializable { + + private static final long serialVersionUID = 1L; + + /** Association source entity type. */ + protected EchoBaseEntityEnum source; + + /** Association target entity type. */ + protected EchoBaseEntityEnum target; + + /** Name fo the association. */ + protected String name; + + /** Operator of the source entity used to get / set associations. */ + protected transient EntityOperator<TopiaEntity> operator; + + protected static AssociationMeta newMeta(EchoBaseEntityEnum source, + EchoBaseEntityEnum target, + String name) { + return new AssociationMeta(source, target, name); + } + + public AssociationMeta(EchoBaseEntityEnum source, + EchoBaseEntityEnum target, + String name) { + this.source = source; + this.target = target; + this.name = name; + } + + public EchoBaseEntityEnum getSource() { + return source; + } + + public EchoBaseEntityEnum getTarget() { + return target; + } + + public String getName() { + return name; + } + + public TopiaEntity newEntity() { + return ObjectUtil.newInstance(source.getImplementation()); + } + + public Object newAssociation() { + return ObjectUtil.newInstance(target.getImplementation()); + } + + public Collection<TopiaEntity> getChilds(TopiaEntity entity) { + Object o = getOperator().get(name, entity); + return (Collection<TopiaEntity>) o; + } + + public void setChilds(TopiaEntity entity, Collection<TopiaEntity> childs) { + getOperator().addAllChild(name, entity, childs); + } + + public EntityOperator<TopiaEntity> getOperator() { + if (operator == null) { + operator = + (EntityOperator<TopiaEntity>) + EchoBaseDAOHelper.getOperator( + source.getContract()); + } + + return operator; + } +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java 2011-12-05 08:22:27 UTC (rev 141) @@ -23,52 +23,35 @@ */ package fr.ifremer.echobase.entities.meta; -import org.hibernate.mapping.Column; import org.nuiton.topia.persistence.TopiaEntity; import java.io.Serializable; import java.util.Date; /** - * Define the meta data. + * Define the meta data of a entity field. * * @author tchemit <chemit@codelutin.com> * @since 0.1 */ public class ColumnMeta implements Serializable { - protected static ColumnMeta newMeta(String name, String label, Class<?> type) { - return new ColumnMeta(name, label, type); + protected static ColumnMeta newMeta(String name, Class<?> type) { + return new ColumnMeta(name, type); } private static final long serialVersionUID = 1L; + /** Name of the column. */ protected String name; - protected String i18nKey; - - protected Column hibernateColumn; - + /** Type of the column. */ protected Class<?> type; - public ColumnMeta(String name, Class<?> type) { - this(name, name, type); - } - - public ColumnMeta(String name, String i18nKey, Class<?> type) { - this.name = name; - this.i18nKey = i18nKey; - this.type = type; - } - public String getName() { return name; } - public String getI18nKey() { - return i18nKey; - } - public Class<?> getType() { return type; } @@ -99,7 +82,9 @@ return boolean.class.equals(type); } - public Column getHibernateColumn() { - return hibernateColumn; + protected ColumnMeta(String name, Class<?> type) { + this.name = name; + this.type = type; } + } Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java 2011-12-05 08:22:27 UTC (rev 141) @@ -43,8 +43,8 @@ protected final EchoBaseEntityEnum[] entityEnums; - public DbMeta(EchoBaseEntityEnum[] entityEnums) { - this.entityEnums = entityEnums; + public static DbMeta newDbMeta(List<EchoBaseEntityEnum> entityEnums) { + return new DbMeta(entityEnums.toArray(new EchoBaseEntityEnum[entityEnums.size()])); } public List<String> getTableNames() { @@ -59,7 +59,7 @@ if (tables == null) { tables = Lists.newArrayList(); for (EchoBaseEntityEnum entityEnum : entityEnums) { - TableMeta tableMeta = new TableMeta(entityEnum); + TableMeta tableMeta = TableMeta.newMeta(entityEnum); tables.add(tableMeta); } } @@ -82,4 +82,8 @@ public Iterator<TableMeta> iterator() { return getTables().iterator(); } + + protected DbMeta(EchoBaseEntityEnum[] entityEnums) { + this.entityEnums = entityEnums; + } } Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java 2011-12-05 08:22:27 UTC (rev 141) @@ -33,7 +33,6 @@ import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderModelBuilder; -import java.beans.Introspector; import java.io.Serializable; import java.util.Iterator; import java.util.List; @@ -48,25 +47,22 @@ private static final long serialVersionUID = 1L; - protected final String i18nKey; + public static TableMeta newMeta(EchoBaseEntityEnum entityEnum) { + return new TableMeta(entityEnum); + } - protected final EntityOperator<?> operator; - + /** Type of the entity. */ protected final EchoBaseEntityEnum entityEnum; + /** List of columns of the entity. */ protected List<ColumnMeta> columns; + /** List of associations of the entity. */ + protected List<AssociationMeta> associations; + + /** Binder used to copy entities (lazy loaded). */ protected Binder<TopiaEntity, TopiaEntity> binder; - public TableMeta(EchoBaseEntityEnum entityEnum) { - Preconditions.checkNotNull(entityEnum); - this.entityEnum = entityEnum; - Class<? extends TopiaEntity> contract = entityEnum.getContract(); - i18nKey = "echobase.common." + - Introspector.decapitalize(contract.getSimpleName()); - operator = EchoBaseDAOHelper.getOperator(contract); - } - public String getName() { return entityEnum.name(); } @@ -79,14 +75,6 @@ return entityEnum.getContract(); } - public String getI18nKey() { - return i18nKey; - } - - public EntityOperator<?> getOperator() { - return operator; - } - public ColumnMeta getColumns(String columnName) { Preconditions.checkNotNull(columnName); ColumnMeta result = null; @@ -113,20 +101,22 @@ } public List<ColumnMeta> getColumns() { - if (columns == null) { - columns = Lists.newLinkedList(); - Class<? extends TopiaEntity> contract = entityEnum.getContract(); - EntityOperator<? extends TopiaEntity> operator = - EchoBaseDAOHelper.getOperator(contract); - List<String> properties = operator.getProperties(); - for (String property : properties) { - Class<?> propertyType = operator.getPropertyType(property); - String i18nKey = "echobase.common." + property; - ColumnMeta tableMeta = ColumnMeta.newMeta(property, i18nKey, propertyType); - columns.add(tableMeta); + return columns; + } + + public List<AssociationMeta> getAssociations() { + return associations; + } + + public AssociationMeta getAssociations(String name) { + AssociationMeta result = null; + for (AssociationMeta meta : getAssociations()) { + if (name.equals(meta.getName())) { + result = meta; + break; } } - return columns; + return result; } public void copy(TopiaEntity source, TopiaEntity target) { @@ -160,4 +150,46 @@ } return binder; } + + protected TableMeta(EchoBaseEntityEnum entityEnum) { + Preconditions.checkNotNull(entityEnum); + this.entityEnum = entityEnum; + + Class<? extends TopiaEntity> contract = entityEnum.getContract(); + EntityOperator<? extends TopiaEntity> operator = + EchoBaseDAOHelper.getOperator(contract); + + associations = Lists.newArrayList(); + columns = Lists.newLinkedList(); + + // fill associations + List<String> associationProperties = operator.getAssociationProperties(); + for (String property : associationProperties) { + Class<?> propertyType = operator.getPropertyType(property); + if (TopiaEntity.class.isAssignableFrom(propertyType)) { + + // only use it for entity + EchoBaseEntityEnum targetEnum = + EchoBaseEntityEnum.valueOf(propertyType); + + AssociationMeta meta = AssociationMeta.newMeta(entityEnum, + targetEnum, + property + ); + associations.add(meta); + } + } + + // fill properties (remove all asociations) + List<String> properties = Lists.newArrayList(operator.getProperties()); + properties.removeAll(associationProperties); + for (String property : properties) { + Class<?> propertyType = operator.getPropertyType(property); + ColumnMeta meta = ColumnMeta.newMeta(property, + propertyType); + columns.add(meta); + } + + + } } Modified: trunk/echobase-entities/src/main/resources/topia-h2.properties =================================================================== --- trunk/echobase-entities/src/main/resources/topia-h2.properties 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/main/resources/topia-h2.properties 2011-12-05 08:22:27 UTC (rev 141) @@ -24,6 +24,9 @@ hibernate.hbm2ddl.auto=update hibernate.show_sql=false +# Replication configuration +topia.service.replication=org.nuiton.topia.replication.TopiaReplicationServiceImpl + hibernate.dialect=org.hibernate.dialect.H2Dialect hibernate.connection.username=sa hibernate.connection.password=sa Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo =================================================================== (Binary files differ) Deleted: trunk/echobase-entities/src/test/resources/echobase.properties =================================================================== --- trunk/echobase-entities/src/test/resources/echobase.properties 2011-12-05 06:42:35 UTC (rev 140) +++ trunk/echobase-entities/src/test/resources/echobase.properties 2011-12-05 08:22:27 UTC (rev 141) @@ -1,34 +0,0 @@ -### -# #%L -# EchoBase :: Entities -# -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2011 Ifremer, Codelutin -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# #L% -### -hibernate.hbm2ddl.auto=update -hibernate.show_sql=false -hibernate.dialect=org.hibernate.dialect.H2Dialect - -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:file:${data.directory}/echobase/h2data -hibernate.connection.username=sa -hibernate.connection.password=sa - -war.directory=${data.directory}/war -war.location=${war.directory}/echobase-ui-${project.version}.war \ No newline at end of file