Author: tchemit Date: 2014-05-23 17:26:15 +0200 (Fri, 23 May 2014) New Revision: 3136 Url: http://forge.nuiton.org/projects/topia/repository/revisions/3136 Log: fixes #3215 Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/DefaultTopiaIdFactory.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/LegacyTopiaIdFactory.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java 2014-05-23 15:10:22 UTC (rev 3135) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java 2014-05-23 15:26:15 UTC (rev 3136) @@ -53,6 +53,17 @@ <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, TopiaEntity topiaEntity); /** + * Builds a new topiaId for the given entity type and the given random part. + * + * @param entityClass type of entity (must be a not null interface) + * @param randomPart the random part of the topiaId + * @param <E> type of entity + * @return the new topiaId + */ + <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, String randomPart); + + + /** * @param topiaId the topiaId to inspect * @param <E> type of the entity * @return the FQN part of the topiaId @@ -61,7 +72,7 @@ /** * @param topiaId the topiaId to inspect - * @return the random part of the topiaId. + * @return the random part of the topiaId */ String getRandomPart(String topiaId); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/DefaultTopiaIdFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/DefaultTopiaIdFactory.java 2014-05-23 15:10:22 UTC (rev 3135) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/DefaultTopiaIdFactory.java 2014-05-23 15:26:15 UTC (rev 3136) @@ -54,6 +54,16 @@ } @Override + public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, String randomPart) { + if (!entityClass.isInterface()) { + throw new IllegalArgumentException( + "Only interface is permit to create id: " + entityClass); + } + String result = entityClass.getName() + getSeparator() + randomPart; + return result; + } + + @Override public <E extends TopiaEntity> Class<E> getClassName(String topiaId) { String className = StringUtils.substringBefore(topiaId, getSeparator()); try { Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/LegacyTopiaIdFactory.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/LegacyTopiaIdFactory.java 2014-05-23 15:10:22 UTC (rev 3135) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/LegacyTopiaIdFactory.java 2014-05-23 15:26:15 UTC (rev 3136) @@ -55,14 +55,12 @@ return entityClass.getName() + getSeparator() + System.currentTimeMillis() + '#' + random; } - /** - * Extrait la classe du topiaId. - * - * @param topiaId - * @return class - * @throws TopiaNotFoundException - */ @Override + public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, String randomPart) { + return entityClass.getName() + getSeparator() + System.currentTimeMillis() + '#' + randomPart; + } + + @Override public <E extends TopiaEntity> Class<E> getClassName(String topiaId) { String className = StringUtils.substringBefore(topiaId, getSeparator()); try {