Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormtaal2007-07-18 14:57:16 -0400
committermtaal2007-07-18 14:57:16 -0400
commit35801ba3ec220de26068c0ab3b6f04b4c6c603ac (patch)
tree29737bc4f42c1fd9ea997d1889503374dcf14fb0
parentff48b06feb045190b0c9c96ce003f32082586287 (diff)
downloadorg.eclipse.emf.teneo-build_200707181457.tar.gz
org.eclipse.emf.teneo-build_200707181457.tar.xz
org.eclipse.emf.teneo-build_200707181457.zip
Changed sql name strategy truncation to first remove vowels.build_200707181457
-rw-r--r--plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/TeneoSQLNameStrategy.java66
1 files changed, 54 insertions, 12 deletions
diff --git a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/TeneoSQLNameStrategy.java b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/TeneoSQLNameStrategy.java
index f82bcba4e..9cfb2406f 100644
--- a/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/TeneoSQLNameStrategy.java
+++ b/plugins/org.eclipse.emf.teneo/src/org/eclipse/emf/teneo/mapping/strategy/impl/TeneoSQLNameStrategy.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: TeneoSQLNameStrategy.java,v 1.1 2007/07/18 16:10:08 mtaal Exp $
+ * $Id: TeneoSQLNameStrategy.java,v 1.2 2007/07/18 18:57:16 mtaal Exp $
*/
package org.eclipse.emf.teneo.mapping.strategy.impl;
@@ -21,19 +21,21 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * Differences between this implementation and the ClassicSQLNameStrategy are in the way: -
- * truncation: if a name needs to be truncated because of length constraints then this class tries
- * to truncate two parts of the name (separated by _) together, for example the name child_parent
- * will be truncated to c_p.
+ * Differences between this implementation and the ClassicSQLNameStrategy is the way truncation is
+ * done if a name is longer than the sql name length constraint. To truncate a name this class will
+ * first remove vowels (in the order: u, o, a, e, i) and if that is not enough it will truncate the
+ * different parts of a name (separated by _).
*
* @author <a href="mtaal@elver.org">Martin Taal</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class TeneoSQLNameStrategy extends ClassicSQLNameStrategy {
// The logger
protected static final Log log = LogFactory.getLog(TeneoSQLNameStrategy.class);
+ private static String[] removables = new String[] { "u", "o", "a", "e", "i" };
+
/*
* (non-Javadoc)
*
@@ -41,18 +43,50 @@ public class TeneoSQLNameStrategy extends ClassicSQLNameStrategy {
* java.lang.String, boolean)
*/
@Override
- public String trunc(int optionMaximumSqlLength, String truncName, boolean truncPrefix) {
- final String correctedName = truncName.replace('.', '_');
+ public String trunc(int maxSqlLength, String truncName, boolean truncPrefix) {
+ String correctedName = truncName.replace('.', '_');
- if (optionMaximumSqlLength == -1) {
+ if (maxSqlLength == -1) {
+ return correctedName;
+ }
+ if (correctedName.length() <= maxSqlLength) {
return correctedName;
}
- if (correctedName.length() <= optionMaximumSqlLength) {
+
+ // first do some standard things
+ // truncate the standard e_id
+ correctedName = correctedName.replaceAll("e_id", "id");
+ if (correctedName.length() <= maxSqlLength) {
return correctedName;
}
+
+ // now do vowel truncation
+ for (String vowel : getRemovableCharacters()) {
+ while (correctedName.indexOf(vowel) != -1 || correctedName.indexOf(vowel.toUpperCase()) != -1) {
+ if (correctedName.indexOf(vowel) != -1) {
+ correctedName = correctedName.replaceFirst(vowel, "");
+ } else {
+ correctedName = correctedName.replaceFirst(vowel.toUpperCase(), "");
+ }
+ correctedName = correctedName.replaceAll("__", "_");
+ if (correctedName.startsWith("_")) {
+ correctedName = correctedName.substring(1);
+ }
+ if (correctedName.length() <= maxSqlLength) {
+ return correctedName;
+ }
+ }
+ }
+
+ // still failed do length truncation
+ return doLengthTruncation(maxSqlLength, correctedName);
+ }
+
+ private String doLengthTruncation(int maxSqlLength, String correctedName) {
+ // failed do length truncation with the remainder
final int underscore = correctedName.lastIndexOf('_');
if (underscore == -1) {
- return correctedName.substring(0, optionMaximumSqlLength);
+ return correctedName.substring(0, maxSqlLength);
}
// now do the complex logic to truncate different parts
@@ -66,7 +100,7 @@ public class TeneoSQLNameStrategy extends ClassicSQLNameStrategy {
// can this ever happen
int totalLength = correctedName.length();
- while (maxLength > 1 && totalLength > optionMaximumSqlLength) {
+ while (maxLength > 1 && totalLength > maxSqlLength) {
totalLength = 0;
int newMax = 0;
for (int i = 0; i < parts.length; i++) {
@@ -92,4 +126,12 @@ public class TeneoSQLNameStrategy extends ClassicSQLNameStrategy {
return result.toString();
}
+
+ /**
+ * Return the characters to remove, the character removal is done in order of the returned
+ * array. This method is provided to be overridden to pass a custom set of removable characters.
+ */
+ protected String[] getRemovableCharacters() {
+ return removables;
+ }
} \ No newline at end of file

Back to the top