summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-07 08:23:16 (EDT)
committerEike Stepper2008-04-07 08:23:16 (EDT)
commit9ed6b4ad00323209fca6f542a0f2ebabfe56129c (patch)
tree1cd3b6eae25441208c18eddf90fc009f5c556390
parent102e6770982f5374b1099d2a76fc814163de8917 (diff)
downloadcdo-9ed6b4ad00323209fca6f542a0f2ebabfe56129c.zip
cdo-9ed6b4ad00323209fca6f542a0f2ebabfe56129c.tar.gz
cdo-9ed6b4ad00323209fca6f542a0f2ebabfe56129c.tar.bz2
[214487] Use prepared statements if appropriate
https://bugs.eclipse.org/bugs/show_bug.cgi?id=214487
-rw-r--r--features/org.eclipse.emf.cdo.server.product-feature/rootfiles/configuration/cdo-server.xml4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java2
-rw-r--r--plugins/org.eclipse.net4j.db.derby/fragment.xml11
-rw-r--r--plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/ClientDerbyAdapter.java41
-rw-r--r--plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/DerbyAdapter.java22
-rw-r--r--plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/EmbeddedDerbyAdapter.java41
-rw-r--r--plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/internal/mysql/MYSQLAdapter.java16
-rw-r--r--plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java64
-rw-r--r--plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/DerbyTest.java17
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java6
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java11
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java27
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java32
-rw-r--r--plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java4
-rw-r--r--plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java4
16 files changed, 240 insertions, 64 deletions
diff --git a/features/org.eclipse.emf.cdo.server.product-feature/rootfiles/configuration/cdo-server.xml b/features/org.eclipse.emf.cdo.server.product-feature/rootfiles/configuration/cdo-server.xml
index 26c6779..0ccae6d 100644
--- a/features/org.eclipse.emf.cdo.server.product-feature/rootfiles/configuration/cdo-server.xml
+++ b/features/org.eclipse.emf.cdo.server.product-feature/rootfiles/configuration/cdo-server.xml
@@ -27,12 +27,12 @@
<property name="mappingPrecedence" value="MODEL"/>
</mappingStrategy>
- <!--<dbAdapter name="derby"/>
+ <!--<dbAdapter name="derby-embedded"/>
<dataSource class="org.apache.derby.jdbc.EmbeddedDataSource"
databaseName="/temp/cdodb1"
createDatabase="create"/> -->
- <dbAdapter name="derby"/>
+ <dbAdapter name="derby-client"/>
<dataSource class="org.apache.derby.jdbc.ClientDataSource"
databaseName="cdodb1"
createDatabase="create"/>
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
index 4d61976..5c020fb 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
@@ -78,7 +78,7 @@ public final class CDODBUtil
// public static CDODBStoreManager getStoreManager()
// {
// Properties properties = OM.BUNDLE.getConfigProperties();
- // String adapterName = properties.getProperty("store.adapterName", "derby");
+ // String adapterName = properties.getProperty("store.adapterName", "derby-embedded");
// IDBAdapter dbAdapter = DBUtil.getDBAdapter(adapterName);
// DataSource dataSource = DBUtil.createDataSource(properties, "datasource");
// return getStoreManager(dbAdapter, dataSource);
diff --git a/plugins/org.eclipse.net4j.db.derby/fragment.xml b/plugins/org.eclipse.net4j.db.derby/fragment.xml
index 499115a..a9e4895 100644
--- a/plugins/org.eclipse.net4j.db.derby/fragment.xml
+++ b/plugins/org.eclipse.net4j.db.derby/fragment.xml
@@ -20,10 +20,13 @@
<extension
point="org.eclipse.net4j.db.dbAdapters">
<dbAdapter
- class="org.eclipse.net4j.db.internal.derby.DerbyAdapter"
- name="derby"
- version="10.3.2.1">
- </dbAdapter>
+ class="org.eclipse.net4j.db.internal.derby.EmbeddedDerbyAdapter"
+ name="derby-embedded"
+ version="10.3.2.1"/>
+ <dbAdapter
+ class="org.eclipse.net4j.db.internal.derby.ClientDerbyAdapter"
+ name="derby-client"
+ version="10.3.2.1"/>
</extension>
</plugin>
diff --git a/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/ClientDerbyAdapter.java b/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/ClientDerbyAdapter.java
new file mode 100644
index 0000000..a06242b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/ClientDerbyAdapter.java
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.db.internal.derby;
+
+import org.apache.derby.jdbc.ClientDataSource;
+import org.apache.derby.jdbc.ClientDriver;
+
+import javax.sql.DataSource;
+
+import java.sql.Driver;
+
+/**
+ * @author Eike Stepper
+ */
+public class ClientDerbyAdapter extends DerbyAdapter
+{
+ public static final String NAME = "derby-client";
+
+ public ClientDerbyAdapter()
+ {
+ super(NAME);
+ }
+
+ public Driver getJDBCDriver()
+ {
+ return new ClientDriver();
+ }
+
+ public DataSource createJDBCDataSource()
+ {
+ return new ClientDataSource();
+ }
+}
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 5120b83..558fad6 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,16 +15,15 @@ import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.internal.db.DBAdapter;
import org.eclipse.net4j.internal.db.ddl.DBField;
-import org.apache.derby.jdbc.EmbeddedDriver;
-
-import java.sql.Driver;
import java.util.Arrays;
/**
* @author Eike Stepper
*/
-public class DerbyAdapter extends DBAdapter
+public abstract class DerbyAdapter extends DBAdapter
{
+ public static final String VERSION = "10.3.2.1";
+
private static final String[] RESERVED_WORDS = { "ADD", "ALL", "ALLOCATE", "ALTER", "AND", "ANY", "ARE", "AS", "ASC",
"ASSERTION", "AT", "AUTHORIZATION", "AVG", "BEGIN", "BETWEEN", "BIGINT", "BIT", "BOOLEAN", "BOTH", "BY", "CALL",
"CASCADE", "CASCADED", "CASE", "CAST", "CHAR", "CHARACTER", "CHECK", "CLOSE", "COALESCE", "COLLATE", "COLLATION",
@@ -46,14 +45,9 @@ public class DerbyAdapter extends DBAdapter
"UPDATE", "UPPER", "USER", "USING", "VALUES", "VARCHAR", "VARYING", "VIEW", "WHENEVER", "WHERE", "WITH", "WORK",
"WRITE", "XML", "XMLEXISTS", "XMLPARSE", "XMLQUERY", "XMLSERIALIZE", "YEAR" };
- public DerbyAdapter()
- {
- super("derby", "10.2.2.0");
- }
-
- public Driver getJDBCDriver()
+ public DerbyAdapter(String name)
{
- return new EmbeddedDriver();
+ super(name, VERSION);
}
@Override
@@ -62,9 +56,15 @@ public class DerbyAdapter extends DBAdapter
DBType type = field.getType();
switch (type)
{
+ case TINYINT:
case BOOLEAN:
case BIT:
return "SMALLINT";
+
+ case LONGVARBINARY:
+ case VARBINARY:
+ case BINARY:
+ return "BLOB";
}
return super.getTypeName(field);
diff --git a/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/EmbeddedDerbyAdapter.java b/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/EmbeddedDerbyAdapter.java
new file mode 100644
index 0000000..9d49455
--- /dev/null
+++ b/plugins/org.eclipse.net4j.db.derby/src/org/eclipse/net4j/db/internal/derby/EmbeddedDerbyAdapter.java
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.db.internal.derby;
+
+import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.apache.derby.jdbc.EmbeddedDriver;
+
+import javax.sql.DataSource;
+
+import java.sql.Driver;
+
+/**
+ * @author Eike Stepper
+ */
+public class EmbeddedDerbyAdapter extends DerbyAdapter
+{
+ public static final String NAME = "derby-embedded";
+
+ public EmbeddedDerbyAdapter()
+ {
+ super(NAME);
+ }
+
+ public Driver getJDBCDriver()
+ {
+ return new EmbeddedDriver();
+ }
+
+ public DataSource createJDBCDataSource()
+ {
+ return new EmbeddedDataSource();
+ }
+}
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 c3c6196..af74c4a 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
@@ -16,7 +16,10 @@ import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.internal.db.DBAdapter;
import org.eclipse.net4j.internal.db.ddl.DBField;
-import org.gjt.mm.mysql.Driver;
+import com.mysql.jdbc.Driver;
+import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
+
+import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Arrays;
@@ -26,6 +29,10 @@ import java.util.Arrays;
*/
public class MYSQLAdapter extends DBAdapter
{
+ public static final String NAME = "mysql";
+
+ public static final String VERSION = "5.1.5";
+
private static final String[] RESERVED_WORDS = { "ACTION", "ADD", "ALL", "ALTER", "ANALYZE", "AND", "AS", "ASC",
"ASENSITIVE", "BEFORE", "BETWEEN", "BIGINT", "BINARY", "BIT", "BLOB", "BOTH", "BY", "CALL", "CASCADE", "CASE",
"CHANGE", "CHAR", "CHARACTER", "CHECK", "COLLATE", "COLUMN", "CONDITION", "CONSTRAINT", "CONTINUE", "CONVERT",
@@ -52,7 +59,7 @@ public class MYSQLAdapter extends DBAdapter
public MYSQLAdapter()
{
- super("mysql", "5.1.5");
+ super(NAME, VERSION);
}
public Driver getJDBCDriver()
@@ -67,6 +74,11 @@ public class MYSQLAdapter extends DBAdapter
}
}
+ public DataSource createJDBCDataSource()
+ {
+ return new MysqlDataSource();
+ }
+
@Override
protected String getTypeName(DBField field)
{
diff --git a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java
index c93e518..3760e79 100644
--- a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java
+++ b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/AbstractDBTest.java
@@ -20,23 +20,28 @@ import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.tests.AbstractOMTest;
+import javax.sql.DataSource;
+
import java.sql.Connection;
import java.util.Set;
/**
* @author Eike Stepper
*/
-public abstract class AbstractDBTest extends AbstractOMTest
+public abstract class AbstractDBTest<DATA_SOURCE extends DataSource> extends AbstractOMTest
{
protected IDBAdapter dbAdapter;
protected IDBConnectionProvider dbConnectionProvider;
+ @SuppressWarnings("unchecked")
@Override
protected void doSetUp() throws Exception
{
dbAdapter = createDBAdapter();
- dbConnectionProvider = createDBConnectionProvider();
+ DATA_SOURCE dataSource = (DATA_SOURCE)dbAdapter.createJDBCDataSource();
+ configureDataSourcer(dataSource);
+ dbConnectionProvider = DBUtil.createConnectionProvider(dataSource);
}
@Override
@@ -46,40 +51,63 @@ public abstract class AbstractDBTest extends AbstractOMTest
protected abstract IDBAdapter createDBAdapter();
- protected abstract IDBConnectionProvider createDBConnectionProvider();
+ protected abstract void configureDataSourcer(DATA_SOURCE dataSource);
protected Connection getConnection()
{
return dbConnectionProvider.getConnection();
}
- public void testDBTypes() throws Exception
+ public void _testDBTypes() throws Exception
{
IDBSchema schema = DBUtil.createSchema("testDBTypes");
DBType[] dbTypes = DBType.values();
+ int count = 0;
int i = 0;
for (DBType dbType : dbTypes)
{
IDBTable table = schema.addTable("table_" + i);
table.addField("field", dbType);
-
- IDBTable idx_table = schema.addTable("idx_table" + i);
- IDBField idx_field = idx_table.addField("field", dbType);
- idx_table.addIndex(IDBIndex.Type.NON_UNIQUE, idx_field);
-
- IDBTable uni_table = schema.addTable("uni_table" + i);
- IDBField uni_field = uni_table.addField("field", dbType);
- uni_table.addIndex(IDBIndex.Type.UNIQUE, uni_field);
-
- IDBTable pk_table = schema.addTable("pk_table" + i);
- IDBField pk_field = pk_table.addField("field", dbType);
- pk_table.addIndex(IDBIndex.Type.PRIMARY_KEY, pk_field);
-
+ ++count;
+
+ if (dbAdapter.isTypeIndexable(dbType))
+ {
+ IDBTable idx_table = schema.addTable("idx_table" + i);
+ IDBField idx_field = idx_table.addField("field", dbType);
+ idx_table.addIndex(IDBIndex.Type.NON_UNIQUE, idx_field);
+ ++count;
+
+ IDBTable uni_table = schema.addTable("uni_table" + i);
+ IDBField uni_field = uni_table.addField("field", dbType);
+ uni_table.addIndex(IDBIndex.Type.UNIQUE, uni_field);
+ ++count;
+
+ IDBTable pk_table = schema.addTable("pk_table" + i);
+ IDBField pk_field = pk_table.addField("field", dbType);
+ pk_table.addIndex(IDBIndex.Type.PRIMARY_KEY, pk_field);
+ ++count;
+ }
++i;
}
Set<IDBTable> tables = schema.create(dbAdapter, dbConnectionProvider);
- assertEquals(dbTypes.length * 4, tables.size());
+ assertEquals(count, tables.size());
+ }
+
+ public void testEscapeStrings() throws Exception
+ {
+ IDBSchema schema = DBUtil.createSchema("testEscapeStrings");
+ IDBTable table = schema.addTable("testtable");
+ IDBField strval = table.addField("strval", DBType.VARCHAR, 255);
+ schema.create(dbAdapter, dbConnectionProvider);
+
+ // StringBuilder builder = new StringBuilder("insert into testtable values(");
+ // dbAdapter.appendValue(builder, strval, "My name is \"nobody\", not body");
+ // builder.append(")");
+ String val = "My name is 'nobody', not body";
+ DBUtil.insertRow(getConnection(), dbAdapter, table, val);
+ Object[] result = DBUtil.select(getConnection(), (String)null, strval);
+ assertEquals(val, result[0]);
}
}
diff --git a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/DerbyTest.java b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/DerbyTest.java
index 8c6b955..f214074 100644
--- a/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/DerbyTest.java
+++ b/plugins/org.eclipse.net4j.db.tests/src/org/eclipse/net4j/db/tests/DerbyTest.java
@@ -10,10 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.db.tests;
-import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
-import org.eclipse.net4j.db.IDBConnectionProvider;
-import org.eclipse.net4j.db.internal.derby.DerbyAdapter;
+import org.eclipse.net4j.db.internal.derby.EmbeddedDerbyAdapter;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.io.TMPUtil;
@@ -24,7 +22,7 @@ import java.io.File;
/**
* @author Eike Stepper
*/
-public class DerbyTest extends AbstractDBTest
+public class DerbyTest extends AbstractDBTest<EmbeddedDataSource>
{
private File dbFolder;
@@ -38,21 +36,18 @@ public class DerbyTest extends AbstractDBTest
@Override
protected IDBAdapter createDBAdapter()
{
- return new DerbyAdapter();
+ return new EmbeddedDerbyAdapter();
}
@Override
- protected IDBConnectionProvider createDBConnectionProvider()
+ protected void configureDataSourcer(EmbeddedDataSource dataSource)
{
- dbFolder = TMPUtil.createTempFolder();
+ dbFolder = TMPUtil.createTempFolder("derby_", null, new File("/temp"));
deleteDBFolder();
msg("Using DB folder: " + dbFolder.getAbsolutePath());
- EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName(dbFolder.getAbsolutePath());
- dataSource.setCreateDatabase("true");
-
- return DBUtil.createConnectionProvider(dataSource);
+ dataSource.setCreateDatabase("create");
}
private void deleteDBFolder()
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
index 81f1d9c..bd52178 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java
@@ -129,7 +129,7 @@ public enum DBType
char c = str.charAt(i);
if (c == '\'')
{
- builder.append("\\\'");
+ builder.append("\\'");
}
else
{
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 339c347..13f126e 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
@@ -15,6 +15,8 @@ import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.internal.db.DBAdapterRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
+import javax.sql.DataSource;
+
import java.sql.Connection;
import java.sql.Driver;
import java.sql.Statement;
@@ -33,6 +35,8 @@ public interface IDBAdapter
public Driver getJDBCDriver();
+ public DataSource createJDBCDataSource();
+
public Set<IDBTable> createTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException;
public boolean createTable(IDBTable table, Statement statement) throws DBException;
@@ -42,4 +46,6 @@ public interface IDBAdapter
public String mangleFieldName(String name, int attempt);
public void appendValue(StringBuilder builder, IDBField field, Object value);
+
+ public boolean isTypeIndexable(DBType type);
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java
index 927f192..35ac10b 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java
@@ -11,7 +11,6 @@
package org.eclipse.net4j.db.ddl;
import org.eclipse.net4j.db.DBType;
-import org.eclipse.net4j.internal.db.ddl.DBField;
/**
* @author Eike Stepper
@@ -20,15 +19,15 @@ public interface IDBTable extends IDBSchemaElement
{
public IDBField addField(String name, DBType type);
- public DBField addField(String name, DBType type, boolean notNull);
+ public IDBField addField(String name, DBType type, boolean notNull);
- public DBField addField(String name, DBType type, int precision);
+ public IDBField addField(String name, DBType type, int precision);
- public DBField addField(String name, DBType type, int precision, boolean notNull);
+ public IDBField addField(String name, DBType type, int precision, boolean notNull);
- public DBField addField(String name, DBType type, int precision, int scale);
+ public IDBField addField(String name, DBType type, int precision, int scale);
- public DBField addField(String name, DBType type, int precision, int scale, boolean notNull);
+ public IDBField addField(String name, DBType type, int precision, int scale, boolean notNull);
public IDBField getField(String name);
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 3a73c8f..5a7e2e6 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
@@ -157,6 +157,23 @@ public abstract class DBAdapter implements IDBAdapter
field.appendValue(builder, value);
}
+ public boolean isTypeIndexable(DBType type)
+ {
+ switch (type)
+ {
+ case CLOB:
+ case BLOB:
+ case LONGVARCHAR:
+ case LONGVARBINARY:
+ case VARBINARY:
+ case BINARY:
+ return false;
+
+ default:
+ return true;
+ }
+ }
+
@Override
public String toString()
{
@@ -179,7 +196,10 @@ public abstract class DBAdapter implements IDBAdapter
builder.append(")");
String sql = builder.toString();
- if (TRACER.isEnabled()) TRACER.trace(sql);
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
statement.execute(sql);
DBIndex[] indices = table.getIndices();
@@ -219,7 +239,10 @@ public abstract class DBAdapter implements IDBAdapter
builder.append(")");
String sql = builder.toString();
- if (TRACER.isEnabled()) TRACER.trace(sql);
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
statement.execute(sql);
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java
index 313f597..5e59091 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBField.java
@@ -19,7 +19,13 @@ import org.eclipse.net4j.db.ddl.IDBSchema;
*/
public class DBField extends DBSchemaElement implements IDBField
{
- private static final int DEFAULT_PRECISION = 255;
+ public static final int DEFAULT_DECIMAL_PRECISION = 5;
+
+ public static final int DEFAULT_SCALE = 0;
+
+ public static final int DEFAULT_CHAR_LENGTH = 1;
+
+ public static final int DEFAULT_VARCHAR_LENGTH = 255;
private DBTable table;
@@ -78,7 +84,24 @@ public class DBField extends DBSchemaElement implements IDBField
public int getPrecision()
{
- return precision == DEFAULT ? DEFAULT_PRECISION : precision;
+ if (precision == DEFAULT)
+ {
+ switch (type)
+ {
+ case CHAR:
+ return DEFAULT_CHAR_LENGTH;
+
+ case VARCHAR:
+ case VARBINARY:
+ return DEFAULT_VARCHAR_LENGTH;
+
+ case DECIMAL:
+ case NUMERIC:
+ return DEFAULT_DECIMAL_PRECISION;
+ }
+ }
+
+ return precision;
}
public void setPrecision(int precision)
@@ -88,6 +111,11 @@ public class DBField extends DBSchemaElement implements IDBField
public int getScale()
{
+ if (scale == DEFAULT)
+ {
+ return DEFAULT_SCALE;
+ }
+
return scale;
}
diff --git a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
index c7ccaac..1af652e 100644
--- a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
+++ b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
@@ -13,7 +13,7 @@ package org.eclipse.net4j.jms.tests;
import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.db.IDBAdapter;
-import org.eclipse.net4j.db.internal.derby.DerbyAdapter;
+import org.eclipse.net4j.db.internal.derby.EmbeddedDerbyAdapter;
import org.eclipse.net4j.internal.util.container.ManagedContainer;
import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
@@ -91,7 +91,7 @@ public class JMSSeparatedTest
private static void initServer() throws Exception
{
- IDBAdapter.REGISTRY.put("derby", new DerbyAdapter());
+ IDBAdapter.REGISTRY.put(EmbeddedDerbyAdapter.NAME, new EmbeddedDerbyAdapter());
IStore store = JDBCUtil.getStore();
Server.INSTANCE.setStore(store);
Server.INSTANCE.activate();
diff --git a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java
index 8d5893e..19d76e1 100644
--- a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java
+++ b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSTest.java
@@ -13,7 +13,7 @@ package org.eclipse.net4j.jms.tests;
import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.db.IDBAdapter;
-import org.eclipse.net4j.db.internal.derby.DerbyAdapter;
+import org.eclipse.net4j.db.internal.derby.EmbeddedDerbyAdapter;
import org.eclipse.net4j.internal.util.container.ManagedContainer;
import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
@@ -84,7 +84,7 @@ public class JMSTest
OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
OMPlatform.INSTANCE.setDebugging(true);
- IDBAdapter.REGISTRY.put("derby", new DerbyAdapter());
+ IDBAdapter.REGISTRY.put(EmbeddedDerbyAdapter.NAME, new EmbeddedDerbyAdapter());
IStore store = JDBCUtil.getStore();
Server.INSTANCE.setStore(store);
Server.INSTANCE.activate();