Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2012-05-31 04:32:46 -0400
committerMartin Taal2012-05-31 04:32:46 -0400
commit4f798953b79cb54ada69b097bc359c3693826f1a (patch)
tree0af7f56ac80cabcf8516aa3e13fe23e24038b1b7 /generator/org.eclipse.emf.texo.orm
parent30138e010fc4da025ec9ffc8cdc3053430ee1187 (diff)
downloadorg.eclipse.emf.texo-4f798953b79cb54ada69b097bc359c3693826f1a.tar.gz
org.eclipse.emf.texo-4f798953b79cb54ada69b097bc359c3693826f1a.tar.xz
org.eclipse.emf.texo-4f798953b79cb54ada69b097bc359c3693826f1a.zip
Do removal of vowels in db name computation from the last to the first
Diffstat (limited to 'generator/org.eclipse.emf.texo.orm')
-rwxr-xr-xgenerator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMNamingStrategy.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMNamingStrategy.java b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMNamingStrategy.java
index 3a8164e2..969ccc3c 100755
--- a/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMNamingStrategy.java
+++ b/generator/org.eclipse.emf.texo.orm/src/org/eclipse/emf/texo/orm/annotator/ORMNamingStrategy.java
@@ -33,6 +33,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.texo.generator.GeneratorUtils;
import org.eclipse.emf.texo.orm.ormannotations.EPackageORMAnnotation;
+import org.eclipse.emf.texo.utils.Check;
/**
* The default naming strategy for entity and database schema naming.
@@ -376,15 +377,15 @@ public class ORMNamingStrategy {
protected String trunc(String name, int targetLength) {
String correctedName = name;
- // now do vowel truncation preserving the first character
+ // now do vowel truncation preserving the first character, and starting from the end
char correctedNameFirstChar = correctedName.charAt(0);
String correctedNameTail = correctedName.substring(1);
for (String vowel : getRemovableCharacters()) {
while (correctedNameTail.indexOf(vowel) != -1 || correctedNameTail.indexOf(vowel.toUpperCase()) != -1) {
if (correctedNameTail.indexOf(vowel) != -1) {
- correctedNameTail = correctedNameTail.replaceFirst(vowel, ""); //$NON-NLS-1$
+ correctedNameTail = stripLastOccurrence(correctedNameTail, vowel);
} else {
- correctedNameTail = correctedNameTail.replaceFirst(vowel.toUpperCase(), ""); //$NON-NLS-1$
+ correctedNameTail = stripLastOccurrence(correctedNameTail, vowel.toUpperCase());
}
correctedNameTail = correctedNameTail.replaceAll("__", "_"); //$NON-NLS-1$ //$NON-NLS-2$
if (correctedNameTail.length() + 1 <= targetLength) {
@@ -397,6 +398,15 @@ public class ORMNamingStrategy {
return doLengthTruncation(correctedNameFirstChar + correctedNameTail, targetLength);
}
+ private String stripLastOccurrence(String value, String toReplace) {
+ final int index = value.lastIndexOf(toReplace);
+ Check.isTrue(index != -1, "Search string " + toReplace + " not found in " + value);
+ if (value.endsWith(toReplace)) {
+ return value.substring(0, index);
+ }
+ return value.substring(0, index) + value.substring(index + toReplace.length());
+ }
+
protected String doLengthTruncation(String correctedName, int targetLength) {
// failed do length truncation with the remainder
final int underscore = correctedName.lastIndexOf('_');

Back to the top