summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-21 07:42:05 (EDT)
committerEike Stepper2008-05-21 07:42:05 (EDT)
commit5f791fab105d97d7c90af51fa1118141340254cc (patch)
tree82627f1ef7e3d0ca67af7d2b50138fbb17670037
parentf7caa70d4ae4cbe36c944d4a90beee7268c32fd4 (diff)
downloadcdo-5f791fab105d97d7c90af51fa1118141340254cc.zip
cdo-5f791fab105d97d7c90af51fa1118141340254cc.tar.gz
cdo-5f791fab105d97d7c90af51fa1118141340254cc.tar.bz2
[232952] An eReference named "next" can't be saved in Derby adapter
https://bugs.eclipse.org/bugs/show_bug.cgi?id=232952
-rw-r--r--plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/DerbyAdapter.java7
-rw-r--r--plugins/org.eclipse.net4j.db.hsqldb/src/org/eclipse/net4j/db/internal/hsqldb/HSQLDBAdapter.java5
-rw-r--r--plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/internal/mysql/MYSQLAdapter.java6
-rw-r--r--plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java4
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java79
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java47
7 files changed, 86 insertions, 64 deletions
diff --git a/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/DerbyAdapter.java b/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/DerbyAdapter.java
index 558fad6..4625ce3 100644
--- a/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/DerbyAdapter.java
+++ b/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/DerbyAdapter.java
@@ -15,8 +15,6 @@ import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.internal.db.DBAdapter;
import org.eclipse.net4j.internal.db.ddl.DBField;
-import java.util.Arrays;
-
/**
* @author Eike Stepper
*/
@@ -81,9 +79,8 @@ public abstract class DerbyAdapter extends DBAdapter
super.appendValue(builder, field, value);
}
- @Override
- protected boolean isReservedWord(String word)
+ public String[] getReservedWords()
{
- return Arrays.binarySearch(RESERVED_WORDS, word.toUpperCase()) >= 0;
+ return RESERVED_WORDS;
}
}
diff --git a/plugins/org.eclipse.net4j.db.hsqldb/src/org/eclipse/net4j/db/internal/hsqldb/HSQLDBAdapter.java b/plugins/org.eclipse.net4j.db.hsqldb/src/org/eclipse/net4j/db/internal/hsqldb/HSQLDBAdapter.java
index 2e37e52..1d0faec 100644
--- a/plugins/org.eclipse.net4j.db.hsqldb/src/org/eclipse/net4j/db/internal/hsqldb/HSQLDBAdapter.java
+++ b/plugins/org.eclipse.net4j.db.hsqldb/src/org/eclipse/net4j/db/internal/hsqldb/HSQLDBAdapter.java
@@ -90,4 +90,9 @@ public class HSQLDBAdapter extends DBAdapter
return super.getTypeName(field);
}
+
+ public String[] getReservedWords()
+ {
+ return getSQL92ReservedWords();
+ }
}
diff --git a/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/internal/mysql/MYSQLAdapter.java b/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/internal/mysql/MYSQLAdapter.java
index af74c4a..47b0367 100644
--- a/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/internal/mysql/MYSQLAdapter.java
+++ b/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/internal/mysql/MYSQLAdapter.java
@@ -22,7 +22,6 @@ import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import javax.sql.DataSource;
import java.sql.SQLException;
-import java.util.Arrays;
/**
* @author Eike Stepper
@@ -105,9 +104,8 @@ public class MYSQLAdapter extends DBAdapter
}
}
- @Override
- protected boolean isReservedWord(String word)
+ public String[] getReservedWords()
{
- return Arrays.binarySearch(RESERVED_WORDS, word.toUpperCase()) >= 0;
+ return RESERVED_WORDS;
}
}
diff --git a/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF
index 1d538dc..6964942 100644
--- a/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF
@@ -14,7 +14,7 @@ Export-Package: org.eclipse.net4j.db;version="0.8.0",
org.eclipse.net4j.db.ddl;version="0.8.0",
org.eclipse.net4j.db.dml;version="0.8.0",
org.eclipse.net4j.internal.db;version="0.8.0",
- org.eclipse.net4j.internal.db.bundle;version="0.8.0";x-internal:=true,
+ org.eclipse.net4j.internal.db.bundle;version="0.8.0",
org.eclipse.net4j.internal.db.ddl;version="0.8.0",
org.eclipse.net4j.internal.db.dml;version="0.8.0"
Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java
index de216e5..66466f1 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java
@@ -46,6 +46,10 @@ public interface IDBAdapter
public boolean dropTable(IDBTable table, Statement statement);
+ public String[] getReservedWords();
+
+ public boolean isReservedWord(String word);
+
public String mangleTableName(String name, int attempt);
public String mangleFieldName(String name, int attempt);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java
index 56afa34..89eea15 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java
@@ -23,13 +23,13 @@ import org.eclipse.net4j.internal.db.ddl.DBIndex;
import org.eclipse.net4j.internal.db.ddl.DBTable;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -42,8 +42,8 @@ public abstract class DBAdapter implements IDBAdapter
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SQL, DBAdapter.class);
- private static final String[] RESERVED_WORDS = { "ABSOLUTE", "ACTION", "ADD", "AFTER", "ALL", "ALLOCATE", "ALTER",
- "AND", "ANY", "ARE", "ARRAY", "AS", "ASC", "ASENSITIVE", "ASSERTION", "ASYMMETRIC", "AT", "ATOMIC",
+ private static final String[] SQL92_RESERVED_WORDS = { "ABSOLUTE", "ACTION", "ADD", "AFTER", "ALL", "ALLOCATE",
+ "ALTER", "AND", "ANY", "ARE", "ARRAY", "AS", "ASC", "ASENSITIVE", "ASSERTION", "ASYMMETRIC", "AT", "ATOMIC",
"AUTHORIZATION", "AVG", "BEFORE", "BEGIN", "BETWEEN", "BIGINT", "BINARY", "BIT", "BIT_LENGTH", "BLOB", "BOOLEAN",
"BOTH", "BREADTH", "BY", "CALL", "CALLED", "CASCADE", "CASCADED", "CASE", "CAST", "CATALOG", "CHAR", "CHARACTER",
"CHARACTER_LENGTH", "CHAR_LENGTH", "CHECK", "CLOB", "CLOSE", "COALESCE", "COLLATE", "COLLATION", "COLUMN",
@@ -80,6 +80,8 @@ public abstract class DBAdapter implements IDBAdapter
private String version;
+ private Set<String> reservedWords;
+
public DBAdapter(String name, String version)
{
this.name = name;
@@ -246,7 +248,7 @@ public abstract class DBAdapter implements IDBAdapter
builder.append("CREATE TABLE ");
builder.append(table);
builder.append(" (");
- table.appendFieldDefs(builder, createFieldDefinitions(table));
+ appendFieldDefs(builder, table, createFieldDefinitions(table));
String constraints = createConstraints(table);
if (constraints != null)
{
@@ -261,6 +263,7 @@ public abstract class DBAdapter implements IDBAdapter
TRACER.trace(sql);
}
+ System.out.println(sql);
statement.execute(sql);
DBIndex[] indices = table.getIndices();
@@ -391,9 +394,24 @@ public abstract class DBAdapter implements IDBAdapter
return name;
}
- protected boolean isReservedWord(String word)
+ public String[] getSQL92ReservedWords()
{
- return Arrays.binarySearch(RESERVED_WORDS, word.toUpperCase()) >= 0;
+ return SQL92_RESERVED_WORDS;
+ }
+
+ public boolean isReservedWord(String word)
+ {
+ if (reservedWords == null)
+ {
+ reservedWords = new HashSet<String>();
+ for (String reservedWord : getReservedWords())
+ {
+ reservedWords.add(reservedWord.toUpperCase());
+ }
+ }
+
+ word = word.toUpperCase();
+ return reservedWords.contains(word);
}
protected void validateTable(DBTable table, Statement statement) throws DBException
@@ -402,7 +420,7 @@ public abstract class DBAdapter implements IDBAdapter
{
StringBuilder builder = new StringBuilder();
builder.append("SELECT ");
- table.appendFieldNames(builder);
+ appendFieldNames(builder, table);
builder.append(" FROM ");
builder.append(table);
String sql = builder.toString();
@@ -436,4 +454,51 @@ public abstract class DBAdapter implements IDBAdapter
return result;
}
+
+ public void appendFieldNames(Appendable appendable, IDBTable table)
+ {
+ try
+ {
+ IDBField[] fields = table.getFields();
+ for (int i = 0; i < fields.length; i++)
+ {
+ IDBField field = fields[i];
+ if (i != 0)
+ {
+ appendable.append(", ");
+ }
+
+ String fieldName = field.getName();
+ appendable.append(fieldName);
+ }
+ }
+ catch (IOException canNotHappen)
+ {
+ }
+ }
+
+ private void appendFieldDefs(Appendable appendable, IDBTable table, String[] defs)
+ {
+ try
+ {
+ IDBField[] fields = table.getFields();
+ for (int i = 0; i < fields.length; i++)
+ {
+ IDBField field = fields[i];
+ if (i != 0)
+ {
+ appendable.append(", ");
+ }
+
+ // String fieldName = mangleFieldName(field.getName(), 0);
+ String fieldName = field.getName();
+ appendable.append(fieldName);
+ appendable.append(" ");
+ appendable.append(defs[i]);
+ }
+ }
+ catch (IOException canNotHappen)
+ {
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java
index acd0073..21662f9 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java
@@ -17,7 +17,6 @@ import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -147,52 +146,6 @@ public class DBTable extends DBSchemaElement implements IDBTable
return null;
}
- public void appendFieldNames(Appendable appendable)
- {
- try
- {
- boolean first = true;
- for (DBField field : fields)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- appendable.append(", ");
- }
-
- appendable.append(field.getName());
- }
- }
- catch (IOException canNotHappen)
- {
- }
- }
-
- public void appendFieldDefs(Appendable appendable, String[] defs)
- {
- try
- {
- for (int i = 0; i < fields.size(); i++)
- {
- DBField field = fields.get(i);
- if (i != 0)
- {
- appendable.append(", ");
- }
-
- appendable.append(field.getName());
- appendable.append(" ");
- appendable.append(defs[i]);
- }
- }
- catch (IOException canNotHappen)
- {
- }
- }
-
public String getFullName()
{
return name;