Created
September 13, 2010 15:31
-
-
Save miya2000/577463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/org/insightech/er/editor/model/dbimport/ImportFromDBManagerBase.java | |
=================================================================== | |
--- src/org/insightech/er/editor/model/dbimport/ImportFromDBManagerBase.java (リビジョン 19) | |
+++ src/org/insightech/er/editor/model/dbimport/ImportFromDBManagerBase.java (作業コピー) | |
@@ -18,6 +18,8 @@ | |
import java.util.StringTokenizer; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
+import java.util.regex.Matcher; | |
+import java.util.regex.Pattern; | |
import org.eclipse.core.runtime.IProgressMonitor; | |
import org.eclipse.jface.operation.IRunnableWithProgress; | |
@@ -105,6 +107,8 @@ | |
public String description; | |
public String constraint; | |
+ | |
+ public String enumData; | |
} | |
private static class ForeignKeyData { | |
@@ -229,6 +233,25 @@ | |
columnData.defaultValue = columnSet.getString("COLUMN_DEF"); | |
columnData.description = columnSet.getString("REMARKS"); | |
+ if ((columnData.type.equals("ENUM") || columnData.type.equals("SET")) && metaData.getURL().startsWith("jdbc:mysql:")) { | |
+ String type = columnData.type.toLowerCase(); | |
+ PreparedStatement ps = null; | |
+ try { | |
+ ps = metaData.getConnection().prepareStatement("SHOW COLUMNS FROM `" + tableName + "` LIKE ?"); | |
+ ps.setString(1, columnData.columnName); | |
+ ResultSet rs = ps.executeQuery(); | |
+ if (rs.next()) { | |
+ Pattern p = Pattern.compile(type + "\\((.*)\\)"); | |
+ Matcher m = p.matcher(rs.getString("Type")); | |
+ if (m.matches()) { | |
+ columnData.enumData = m.group(1); | |
+ } | |
+ } | |
+ } finally { | |
+ if (ps != null) ps.close(); | |
+ } | |
+ } | |
+ | |
cash.put(columnData.columnName, columnData); | |
if (monitor != null && monitor.isCanceled()) { | |
@@ -704,7 +727,7 @@ | |
logicalName = this.translationResources.translate(columnName); | |
} | |
- String args = null; | |
+ String args = columnData.enumData; | |
TypeData typeData = new TypeData(length, decimal, array, | |
arrayDimension, unsigned, args); | |
Index: src/org/insightech/er/editor/TranslationResources.java | |
=================================================================== | |
--- src/org/insightech/er/editor/TranslationResources.java (リビジョン 19) | |
+++ src/org/insightech/er/editor/TranslationResources.java (作業コピー) | |
@@ -6,9 +6,12 @@ | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
-import java.util.LinkedHashMap; | |
+import java.util.Comparator; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
+import java.util.TreeMap; | |
+import java.util.regex.Matcher; | |
+import java.util.regex.Pattern; | |
import org.insightech.er.Activator; | |
import org.insightech.er.ResourceString; | |
@@ -20,7 +23,7 @@ | |
private Map<String, String> translationMap; | |
public TranslationResources(TranslationSetting translationSettings) { | |
- this.translationMap = new LinkedHashMap<String, String>(); | |
+ this.translationMap = new TreeMap<String, String>(new TranslationResourcesComparator()); | |
String defaultFileName = ResourceString | |
.getResourceString("label.translation.default"); | |
@@ -96,7 +99,7 @@ | |
String value = line.substring(index + 1).trim(); | |
this.translationMap.put(key, value); | |
- this.translationMap.put(key.replaceAll("[aiueo]", ""), value); | |
+ //this.translationMap.put(key.replaceAll("[aiueo]", ""), value); | |
} | |
} | |
@@ -111,8 +114,10 @@ | |
for (Entry<String, String> entry : translationMap.entrySet()) { | |
String key = entry.getKey(); | |
String value = entry.getValue(); | |
- str = str.replaceAll("\\_*" + key + "\\_*", value); | |
- str = str.replaceAll("\\_*" + key.toUpperCase() + "\\_*", value); | |
+ | |
+ Pattern p = Pattern.compile("_*" + Pattern.quote(key) + "_*", Pattern.CASE_INSENSITIVE); | |
+ Matcher m = p.matcher(str); | |
+ str = m.replaceAll(value); | |
} | |
return str; | |
@@ -121,4 +126,19 @@ | |
public boolean contains(String key) { | |
return this.translationMap.containsKey(key); | |
} | |
+ | |
+ /** | |
+ * 長い順に並べる。同じ長さなら辞書順。ただし [A-Z] より [_] を優先する。 | |
+ */ | |
+ private class TranslationResourcesComparator implements Comparator<String> { | |
+ public int compare(String o1, String o2) { | |
+ int diff = o2.length() - o1.length(); | |
+ if (diff != 0) { | |
+ return diff; | |
+ } | |
+ else { | |
+ return o1.replace('_', ' ').compareTo(o2.replace('_', ' ')); | |
+ } | |
+ } | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment