r2618 - branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/util
Author: tchemit Date: 2012-08-16 17:56:13 +0200 (Thu, 16 Aug 2012) New Revision: 2618 Url: http://nuiton.org/repositories/revision/topia/2618 Log: fixes #2264: Add ToTopiaId function (at last) fixes #2265: Adds a method to compute the association table name for two different entity contract Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2012-08-16 12:39:27 UTC (rev 2617) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/TopiaEntityHelper.java 2012-08-16 15:56:13 UTC (rev 2618) @@ -25,6 +25,7 @@ package org.nuiton.topia.persistence.util; +import com.google.common.base.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; @@ -73,6 +74,19 @@ "%1$s[@" + TopiaEntity.TOPIA_ID + "=\"%2$s\"]"; /** + * Function to obtain {@link TopiaEntity#getTopiaId()} form any entity. + * + * @since 2.6.12 + */ + public static final Function<TopiaEntity, String> TO_TOPIAID = new Function<TopiaEntity, String>() { + + @Override + public String apply(TopiaEntity input) { + return input.getTopiaId(); + } + }; + + /** * Bind les valeurs techniques depuis une entitée vers une autre. * * @param from l'entité source @@ -958,6 +972,7 @@ } return ids; } + /** * Construit une list d'entite dont les ids sont tous dans la liste d'ids * donnee. @@ -1083,7 +1098,7 @@ Set<Class<? extends TopiaEntity>> interfaces, Class<? extends TopiaEntity> klass) { Iterator<Class<? extends TopiaEntity>> iterator = interfaces.iterator(); - for (; iterator.hasNext();) { + for (; iterator.hasNext(); ) { Class<? extends TopiaEntity> next = iterator.next(); if (next.isAssignableFrom(klass)) { // cette interface herite de klass @@ -1182,4 +1197,29 @@ index, requiredType, foundType)); } } + + /** + * Given two names (representing two types of entity), obtains the + * association table name in the format {@code X_Y} where X est the table + * name smaller (in natural order on {@link String}). + * <p/> + * Example: from {@code A} and {@code B}, we get {@code A_B}. + * + * @param table1 the first table + * @param table2 the second table + * @return the normalized association table name + * @since 2.6.12 + */ + public static String getNormalizedAssociationTableName(String table1, + String table2) { + String result; + if (table1.compareTo(table2) > 0) { + // table1 > table 2 + result = table2 + "_" + table1; + } else { + // table2 > table1 + result = table1 + "_" + table2; + } + return result; + } }
participants (1)
-
tchemit@users.nuiton.org