r2479 - in trunk/topia-persistence/src/main: java/org/nuiton/topia/generator resources resources/org resources/org/nuiton resources/org/nuiton/topia resources/org/nuiton/topia/persistence
Author: tchemit Date: 2012-05-14 14:27:56 +0200 (Mon, 14 May 2012) New Revision: 2479 Url: http://nuiton.org/repositories/revision/topia/2479 Log: refs #2089: Use JPA (orm) mappings (add mapping for TopiaEntityAbstract + continue generator...) Added: trunk/topia-persistence/src/main/resources/org/ trunk/topia-persistence/src/main/resources/org/nuiton/ trunk/topia-persistence/src/main/resources/org/nuiton/topia/ trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/ trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-14 12:23:48 UTC (rev 2478) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityJPAMappingGenerator.java 2012-05-14 12:27:56 UTC (rev 2479) @@ -14,7 +14,6 @@ import org.nuiton.eugene.models.object.ObjectModelAttribute; import org.nuiton.eugene.models.object.ObjectModelClass; import org.nuiton.eugene.models.object.ObjectModelGenerator; -import org.nuiton.topia.persistence.TopiaEntity; import javax.persistence.AccessType; import javax.persistence.EnumType; @@ -50,6 +49,8 @@ public static final String TAG_PACKAGE = "package"; + public static final String TAG_MAPPED_SUPERCLASS = "mapped-superclass"; + public static final String TAG_ENTITY = "entity"; public static final String TAG_TABLE = "table"; @@ -88,6 +89,12 @@ public static final String TAG_JOIN_COLUMN = "join-column"; + public static final String TAG_INVERSE_JOIN_COLUMN = "inverse-join-column"; + + public static final String TAG_ORDER_COLUMN = "order-column"; + + public static final String TAG_ORDER_BY = "order-by"; + public static final String TAG_JOIN_TABLE = "join-table"; public static final String TAG_GENERATED_VALUE = "generated-value"; @@ -120,7 +127,7 @@ public static final String ATTRIBUTE_FETCH = "fetch"; - private static final String ATTRIBUTE_ORPHAN_REMOVAL = "orphan-removal"; + public static final String ATTRIBUTE_ORPHAN_REMOVAL = "orphan-removal"; public static final String ATTRIBUTE_COLUMN_DEFINITION = "column-definition"; @@ -142,29 +149,17 @@ public static final String ATTRIBUTE_REFERENCE_COLUMN_NAME = "referencedColumnName"; - private Map<String, String[]> columnNamesMap = new HashMap<String, String[]>(); + private static final String ATTRIBUTE_TARGET_ENTITY = "target-entity"; + private Map<String, String[]> columnNamesMap = + new HashMap<String, String[]>(); + @Override public String getFilenameForClass(ObjectModelClass clazz) { String result = TopiaGeneratorUtil.getDOType(clazz, model); return result.replace('.', File.separatorChar) + "-orm.xml"; } - - protected Multimap<String, ObjectModelAttribute> splitAttributes( - ObjectModelClass input, - List<ObjectModelAttribute> normalAttributes) { - Multimap<String, ObjectModelAttribute> result = ArrayListMultimap.create(); - for (ObjectModelAttribute attribute : input.getAttributes()) { - if (TopiaGeneratorUtil.isNaturalId(attribute)) { - result.put("naturalId", attribute); - } else { - normalAttributes.add(attribute); - } - } - return result; - } - @Override public void generateFromClass(Writer output, ObjectModelClass input) throws IOException { @@ -176,6 +171,19 @@ TopiaGeneratorUtil.PERSISTENCE_TYPE_HIBERNATE.equals(persistenceType)) { return; } + + // la liste des autres attributs + List<ObjectModelAttribute> attributes = + new ArrayList<ObjectModelAttribute>(); + + // Split attributes for each embeddable + Multimap<String, ObjectModelAttribute> embeddableAttributes = + splitAttributes(input, attributes); + + // get all unique constraints to add + Multimap<String, String> uniqueContraints = getUniqueConstraints( + input, attributes, embeddableAttributes); + /*{<?xml version="1.0" encoding="UTF-8"?> }*/ Map<String, String> xmlAttributes = new TreeMap<String, String>(); @@ -194,15 +202,19 @@ /*{<%=flushTag(TAG_PACKAGE, input.getPackageName())%><%=closeStrictTag(TAG_PACKAGE)%> }*/ + // -- tag 'mapped-superclass' (fields are on Abstract so use a mapped-superclass) + + addMappedSuperclass(output, input, attributes); + // -- tag 'entity' String clazzFQN = input.getQualifiedName(); addAttribute(xmlAttributes, ATTRIBUTE_NAME, clazzFQN); - addAttribute(xmlAttributes, ATTRIBUTE_CLASS, input.getName() + "Impl"); - addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD); - addAttribute(xmlAttributes, ATTRIBUTE_METADATA_COMPLETE, true); + addAttribute(xmlAttributes, ATTRIBUTE_CLASS, input.getQualifiedName() + "Impl"); +// addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD); + addAttribute(xmlAttributes, ATTRIBUTE_METADATA_COMPLETE, false); //NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_CACHEABLE, true); //NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_NAME, ""); /*{<%=flushTag(TAG_ENTITY, xmlAttributes)%> @@ -210,18 +222,6 @@ boolean haveSuper = input.getSuperclasses().size() > 0; - // la liste des autres attributs - List<ObjectModelAttribute> attributes = - new ArrayList<ObjectModelAttribute>(); - - // Split attributes for each embeddable - Multimap<String, ObjectModelAttribute> embeddableAttributes = - splitAttributes(input, attributes); - - // get all unique constraints to add - Multimap<String, String> uniqueContraints = getUniqueConstraints( - input, attributes, embeddableAttributes); - String tableName = TopiaGeneratorUtil.getDbName(input); String isAbstract = BooleanUtils.toStringTrueFalse(input.isAbstract()); String clazzDOType = TopiaGeneratorUtil.getDOType(input, model); @@ -253,10 +253,6 @@ }*/ } - // generate attributes for the entity - - generateAttributes(output, input, attributes, true); - /*{<%=closeTag(TAG_ENTITY)%> }*/ @@ -290,6 +286,26 @@ }*/ } + private void addMappedSuperclass(Writer output, + ObjectModelClass input, + List<ObjectModelAttribute> attributes) throws IOException { + + Map<String, String> xmlAttributes = new TreeMap<String, String>(); + + addAttribute(xmlAttributes, ATTRIBUTE_CLASS, input.getQualifiedName() + "Abstract"); + addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD); + addAttribute(xmlAttributes, ATTRIBUTE_METADATA_COMPLETE, false); +/*{<%=flushTag(TAG_MAPPED_SUPERCLASS, xmlAttributes)%> +}*/ + + // generate attributes for the entity + + generateAttributes(output, input, attributes, true); + +/*{<%=closeTag(TAG_MAPPED_SUPERCLASS)%> +}*/ + } + private void generateAttributes(Writer output, ObjectModelClass input, Collection<ObjectModelAttribute> attributes, @@ -305,29 +321,7 @@ /*{<%=flushTag(TAG_ATTRIBUTES)%> }*/ - if (mainEntity) { - // add id tag - - addAttribute(xmlAttributes, ATTRIBUTE_NAME, TopiaEntity.TOPIA_ID); -//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD); -/*{<%=flushTag(TAG_ID, xmlAttributes)%> -}*/ -//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_GENERATOR, "generatorFQN"); -//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_STRATEGY, GenerationType.AUTO); - -/*{<%=flushTag(TAG_GENERATED_VALUE, true, xmlAttributes)%> -<%=closeTag(TAG_ID)%> -}*/ - // add topiaCreateDate - - addAttribute(xmlAttributes, ATTRIBUTE_NAME, TopiaEntity.TOPIA_CREATE_DATE); -/*{<%=flushTag(TAG_BASIC, xmlAttributes)%> -<%=flushTag(TAG_TEMPORAL, javax.persistence.TemporalType.TIMESTAMP.name())%><%=closeStrictTag(TAG_TEMPORAL)%> -<%=closeTag(TAG_BASIC)%> -}*/ - } - // generate basic attributes Collection<ObjectModelAttribute> basicAttributes = attributesByType.get(PROPERTY_TYPE.BASIC); @@ -335,20 +329,18 @@ generateBasicAttribute(output, input, attribute); } - if (mainEntity) { - - // add version tag - addAttribute(xmlAttributes, ATTRIBUTE_NAME, TopiaEntity.TOPIA_VERSION); -//NOTUSED addAttribute(xmlAttributes, ATTRIBUTE_ACCESS, AccessType.FIELD); -/*{<%=flushTag(TAG_VERSION, true, xmlAttributes)%> -}*/ - } // generate many-to-one attributes Collection<ObjectModelAttribute> manyToOneAttributes = attributesByType.get(PROPERTY_TYPE.MANY_TO_ONE); for (ObjectModelAttribute attribute : manyToOneAttributes) { generateManyToOneAttribute(output, input, attribute, false); } + // generate one-to-one attributes + Collection<ObjectModelAttribute> oneToOneAttributes = + attributesByType.get(PROPERTY_TYPE.ONE_TO_ONE); + for (ObjectModelAttribute attribute : oneToOneAttributes) { + generateOneToOneAttribute(output, input, attribute); + } // generate one-to-many attributes Collection<ObjectModelAttribute> oneToManyAttributes = attributesByType.get(PROPERTY_TYPE.ONE_TO_MANY); @@ -356,13 +348,6 @@ generateOneToManyAttribute(output, input, attribute); } - // generate one-to-one attributes - Collection<ObjectModelAttribute> oneToOneAttributes = - attributesByType.get(PROPERTY_TYPE.ONE_TO_ONE); - for (ObjectModelAttribute attribute : oneToOneAttributes) { - generateOneToOneAttribute(output, input, attribute); - } - // generate many-to-many attributes Collection<ObjectModelAttribute> manyToManyAttributes = attributesByType.get(PROPERTY_TYPE.MANY_TO_MANY); @@ -436,7 +421,8 @@ String[] columnNames = columnNamesMap.get(attrType); // to know if specific column name mapping is given - boolean noSpecifiedColumn = columnNames == null || columnNames.length == 0; + boolean noSpecifiedColumn = columnNames == null || + columnNames.length == 0; if (noSpecifiedColumn) { @@ -467,7 +453,7 @@ attr, model); EnumType type = useEnumerationName ? EnumType.STRING : EnumType.ORDINAL; -/*{<%=flushTag(TAG_ENUMERATED, true, type.name())%> +/*{<%=flushTag(TAG_ENUMERATED, type.name())%><%=closeStrictTag(TAG_ENUMERATED)%> }*/ } /*{<%=closeTag(TAG_BASIC)%> @@ -515,6 +501,7 @@ } //NOTUSED addAttribute(columnAttributes, ATTRIBUTE_REFERENCE_COLUMN_NAME, TopiaEntity.TOPIA_ID); + addAttribute(xmlAttributes, ATTRIBUTE_TARGET_ENTITY, getType(attr)); boolean withDeleteCascade = false; if (attr.isComposite() || attr.hasAssociationClass()) { @@ -545,54 +532,165 @@ }*/ } - private void generateOneToManyAttribute(Writer output, + private void generateManyToManyAttribute(Writer output, ObjectModelClass input, ObjectModelAttribute attr) throws IOException { - Map<String, String> xmlAttributes = Maps.newTreeMap(); + + + boolean bidirection = attr.isNavigable() && + attr.getReverseAttribute().isNavigable(); + boolean isInverse=false; + if (bidirection) { + + // only use an inverse for a bidirection, otherwise no need + + // Modification FD-2010-04-01 : + // Le tagvalue "inverse" permet de spécifier qui possède le + // inverse="true". Il est impératif de l'utiliser sur les deux + // extrémités pour ne pas avoir de surprise. + String inverseValue = TopiaGeneratorUtil.getInverseTagValue(attr); + if (StringUtils.isNotEmpty(inverseValue)) { + isInverse = Boolean.parseBoolean(inverseValue); + // Si aucun tagvalue n'est défini, le choix est arbitraire : le + // premier attribut dans l'ordre alphabétique sera choisi pour porter le + // inverse="true" + } else { + isInverse = TopiaGeneratorUtil.isFirstAttribute(attr); + } + } + + // need an index boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr); - boolean isInverse = attr.getReverseAttribute().isNavigable(); - isInverse |= hasUnidirectionalRelationOnAbstractType(attr, model); + boolean needCascade = attr.isComposite() || attr.hasAssociationClass(); - Map<String, String> columnAttributes = Maps.newTreeMap(); + Map<String, String> xmlAttributes = Maps.newTreeMap(); String attrName = getName(attr); addAttribute(xmlAttributes, ATTRIBUTE_NAME, attrName); - String reverseAttrDBName = TopiaGeneratorUtil.getReverseDbName(attr); - String orderBy = TopiaGeneratorUtil.getOrderByTagValue(attr); - if ("true".equals(TopiaGeneratorUtil.getLazyTagValue(attr))) { // lazy property addAttribute(xmlAttributes, ATTRIBUTE_FETCH, FetchType.LAZY); } - if (attr.isComposite() || attr.hasAssociationClass()) { - addAttribute(xmlAttributes, ATTRIBUTE_ORPHAN_REMOVAL, true); - } - addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName); + String attrType = getType(attr); + addAttribute(xmlAttributes, ATTRIBUTE_TARGET_ENTITY, attrType); -/*{<%=flushTag(TAG_ONE_TO_MANY, xmlAttributes)%> + String reverseAttrDBName = TopiaGeneratorUtil.getReverseDbName(attr); + String attrDBName = TopiaGeneratorUtil.getDbName(attr); + +/*{<%=flushTag(TAG_MANY_TO_MANY, xmlAttributes)%> }*/ + if (needsIndex) { + // add a order-column + addAttribute(xmlAttributes, ATTRIBUTE_NAME, reverseAttrDBName + "_idx"); +// addAttribute(xmlAttributes, ATTRIBUTE_NULLABLE, true); + addAttribute(xmlAttributes, ATTRIBUTE_INSERTABLE, false); +/*{<%=flushTag(TAG_ORDER_COLUMN, true, xmlAttributes)%> +}*/ + } else { - if (StringUtils.isNotBlank(orderBy)) { - //TODO Order-by or order-column ? + String orderBy = TopiaGeneratorUtil.getOrderByTagValue(attr); + if (StringUtils.isNotBlank(orderBy)) { + // add order-by +/*{<%=flushTag(TAG_ORDER_BY, orderBy)%><%=closeStrictTag(TAG_ORDER_BY)%> +}*/ + } } - if (needsIndex) { + String schema = TopiaGeneratorUtil.getDbSchemaNameTagValue(input, model); + + if (!bidirection) { + + // master of relation add a join table + Map<String, String> columnAttributes = Maps.newTreeMap(); + + String tableName = TopiaGeneratorUtil.getManyToManyTableName(attr); + addAttribute(columnAttributes, ATTRIBUTE_NAME, tableName); + + if (schema != null) { + addAttribute(columnAttributes, ATTRIBUTE_SCHEMA, schema); + } + +/*{<%=flushTag(TAG_JOIN_TABLE, columnAttributes)%> +}*/ + // add join-column + addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName); +/*{<%=flushTag(TAG_JOIN_COLUMN, true, columnAttributes)%> +}*/ + // add a reverse-join-column + addAttribute(columnAttributes, ATTRIBUTE_NAME, attrDBName); +/*{<%=flushTag(TAG_INVERSE_JOIN_COLUMN, true, columnAttributes)%> +}*/ + +/*{<%=closeTag(TAG_JOIN_TABLE)%> +}*/ + } else { - } - if (MapUtils.isNotEmpty(columnAttributes)) { + if (isInverse) { + + // inverse of relation + + Map<String, String> columnAttributes = Maps.newTreeMap(); + + String tableName = TopiaGeneratorUtil.getManyToManyTableName(attr); + addAttribute(columnAttributes, ATTRIBUTE_NAME, tableName); + + if (schema != null) { + addAttribute(columnAttributes, ATTRIBUTE_SCHEMA, schema); + } + +/*{<%=flushTag(TAG_JOIN_TABLE, columnAttributes)%> +}*/ + // add join-column + addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName); /*{<%=flushTag(TAG_JOIN_COLUMN, true, columnAttributes)%> }*/ + // add inverse-join-column + addAttribute(columnAttributes, ATTRIBUTE_NAME, attrDBName); +/*{<%=flushTag(TAG_INVERSE_JOIN_COLUMN, true, columnAttributes)%> +}*/ +/*{<%=closeTag(TAG_JOIN_TABLE)%> +}*/ + } else { + + // master of relation + + // master of relation add a join table + Map<String, String> columnAttributes = Maps.newTreeMap(); + + String tableName = TopiaGeneratorUtil.getManyToManyTableName(attr); + addAttribute(columnAttributes, ATTRIBUTE_NAME, tableName); + + if (schema != null) { + addAttribute(columnAttributes, ATTRIBUTE_SCHEMA, schema); + } + +/*{<%=flushTag(TAG_JOIN_TABLE, columnAttributes)%> +}*/ + // add join-column + addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName); +/*{<%=flushTag(TAG_JOIN_COLUMN, true, columnAttributes)%> +}*/ + // add inverse-join-column + addAttribute(columnAttributes, ATTRIBUTE_NAME, attrDBName); +/*{<%=flushTag(TAG_INVERSE_JOIN_COLUMN, true, columnAttributes)%> +}*/ +/*{<%=closeTag(TAG_JOIN_TABLE)%> +}*/ + } } + if (needCascade) { /*{<%=flushTag(TAG_CASCADE)%> -<%=flushTag(TAG_CASCADE_ALL, true)%> +<%=flushTag(TAG_CASCADE_REMOVE, true)%> <%=closeTag(TAG_CASCADE)%> }*/ -/*{<%=closeTag(TAG_ONE_TO_MANY)%> + } + +/*{<%=closeTag(TAG_MANY_TO_MANY)%> }*/ } @@ -608,16 +706,98 @@ generateManyToOneAttribute(output, input, attr, unique); } - private void generateManyToManyAttribute(Writer output, + private void generateOneToManyAttribute(Writer output, ObjectModelClass input, ObjectModelAttribute attr) throws IOException { + Map<String, String> xmlAttributes = Maps.newTreeMap(); + boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr); +//NOTUSED (no more inverse = true) +// boolean isInverse = attr.getReverseAttribute().isNavigable(); +// isInverse |= hasUnidirectionalRelationOnAbstractType(attr, model); + + Map<String, String> columnAttributes = Maps.newTreeMap(); + + String attrName = getName(attr); + addAttribute(xmlAttributes, ATTRIBUTE_NAME, attrName); + addAttribute(xmlAttributes, ATTRIBUTE_TARGET_ENTITY, getType(attr)); + + String reverseAttrDBName = TopiaGeneratorUtil.getReverseDbName(attr); + + if ("true".equals(TopiaGeneratorUtil.getLazyTagValue(attr))) { + + // lazy property + addAttribute(xmlAttributes, ATTRIBUTE_FETCH, FetchType.LAZY); + } + if (attr.isComposite() || attr.hasAssociationClass()) { + addAttribute(xmlAttributes, ATTRIBUTE_ORPHAN_REMOVAL, true); + } + + addAttribute(columnAttributes, ATTRIBUTE_NAME, reverseAttrDBName); + +/*{<%=flushTag(TAG_ONE_TO_MANY, xmlAttributes)%> +}*/ + + if (needsIndex) { + // add a order-column + addAttribute(xmlAttributes, ATTRIBUTE_NAME, reverseAttrDBName + "_idx"); +// addAttribute(xmlAttributes, ATTRIBUTE_NULLABLE, true); + addAttribute(xmlAttributes, ATTRIBUTE_INSERTABLE, false); +/*{<%=flushTag(TAG_ORDER_COLUMN, true, xmlAttributes)%> +}*/ + } else { + + String orderBy = TopiaGeneratorUtil.getOrderByTagValue(attr); + if (StringUtils.isNotBlank(orderBy)) { + // add order-by +/*{<%=flushTag(TAG_ORDER_BY, orderBy)%><%=closeStrictTag(TAG_ORDER_BY)%> +}*/ + } + } + + if (MapUtils.isNotEmpty(columnAttributes)) { +/*{<%=flushTag(TAG_JOIN_COLUMN, true, columnAttributes)%> +}*/ + } + +/*{<%=flushTag(TAG_CASCADE)%> +<%=flushTag(TAG_CASCADE_ALL, true)%> +<%=closeTag(TAG_CASCADE)%> +}*/ +/*{<%=closeTag(TAG_ONE_TO_MANY)%> +}*/ } private void generateElementCollectionAttribute(Writer output, ObjectModelClass input, ObjectModelAttribute attr) throws IOException { + boolean needsIndex = TopiaGeneratorUtil.hasIndexedStereotype(attr); + String attrName = getName(attr); + String attrType = getType(attr); Map<String, String> xmlAttributes = Maps.newTreeMap(); + addAttribute(xmlAttributes, ATTRIBUTE_NAME, attrName); +/*{<%=flushTag(TAG_ELEMENT_COLLECTION, xmlAttributes)%> +}*/ + + boolean attrIsEnumeration = attr.getClassifier() != null + && attr.getClassifier().isEnum(); + if (attrIsEnumeration) { + + // if the user tuned the model to use name instead of + // ordinal to store the values, we must add a clause + boolean useEnumerationName = + TopiaGeneratorUtil.hasUseEnumerationNameTagValue( + attr, model); + EnumType type = useEnumerationName ? EnumType.STRING : + EnumType.ORDINAL; +/*{<%=flushTag(TAG_ENUMERATED, type.name())%><%=closeStrictTag(TAG_ENUMERATED)%> +}*/ + } + + //FIXME Do for temporal type +/*{<%=closeTag(TAG_ELEMENT_COLLECTION)%> +}*/ + } private void addAttribute(Map<String, String> attributes, @@ -705,8 +885,8 @@ Map<String, String> attributes, String textValue) { - if (log.isInfoEnabled()) { - log.info("flushTag <" + tagName + "> : level " + xmlLevel); + if (log.isDebugEnabled()) { + log.debug("flushTag <" + tagName + "> : level " + xmlLevel); } StringBuilder builder = new StringBuilder(getXmlPrefix()); xmlLevel++; @@ -738,8 +918,8 @@ private String closeStrictTag(String tagName) { xmlLevel--; String result = "</" + tagName + ">"; - if (log.isInfoEnabled()) { - log.info("closeStrictTag <" + tagName + "> : level " + xmlLevel); + if (log.isDebugEnabled()) { + log.debug("closeStrictTag <" + tagName + "> : level " + xmlLevel); } return result; } @@ -747,8 +927,8 @@ private String closeTag(String tagName) { xmlLevel--; String result = getXmlPrefix() + "</" + tagName + ">"; - if (log.isInfoEnabled()) { - log.info("closeTag <" + tagName + "> : level " + xmlLevel); + if (log.isDebugEnabled()) { + log.debug("closeTag <" + tagName + "> : level " + xmlLevel); } return result; } @@ -871,4 +1051,18 @@ } return TopiaGeneratorUtil.getDOType(type, model); } + + private Multimap<String, ObjectModelAttribute> splitAttributes( + ObjectModelClass input, + List<ObjectModelAttribute> normalAttributes) { + Multimap<String, ObjectModelAttribute> result = ArrayListMultimap.create(); + for (ObjectModelAttribute attribute : input.getAttributes()) { + if (TopiaGeneratorUtil.isNaturalId(attribute)) { + result.put("naturalId", attribute); + } else { + normalAttributes.add(attribute); + } + } + return result; + } } Added: trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml =================================================================== --- trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml (rev 0) +++ trunk/topia-persistence/src/main/resources/org/nuiton/topia/persistence/TopiaEntityAbstract-orm.xml 2012-05-14 12:27:56 UTC (rev 2479) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<entity-mappings version="2.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"> + <mapped-superclass class="org.nuiton.topia.persistence.TopiaEntityAbstract" access="FIELD"> + <attributes> + <id name="topiaId" access="FIELD"> + <generated-value strategy="IDENTITY"/> + </id> + <basic name="topiaCreateDate"> + <temporal>TIMESTAMP</temporal> + </basic> + <version name="topiaVersion"/> + </attributes> + </mapped-superclass> +</entity-mappings>
participants (1)
-
tchemit@users.nuiton.org