Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-07 12:23:16 +0000
committerEike Stepper2008-04-07 12:23:16 +0000
commit9ed6b4ad00323209fca6f542a0f2ebabfe56129c (patch)
tree1cd3b6eae25441208c18eddf90fc009f5c556390 /plugins/org.eclipse.net4j.db
parent102e6770982f5374b1099d2a76fc814163de8917 (diff)
downloadcdo-9ed6b4ad00323209fca6f542a0f2ebabfe56129c.tar.gz
cdo-9ed6b4ad00323209fca6f542a0f2ebabfe56129c.tar.xz
cdo-9ed6b4ad00323209fca6f542a0f2ebabfe56129c.zip
[214487] Use prepared statements if appropriate
https://bugs.eclipse.org/bugs/show_bug.cgi?id=214487
Diffstat (limited to 'plugins/org.eclipse.net4j.db')
-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
5 files changed, 67 insertions, 11 deletions
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 81f1d9c953..bd52178436 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 339c347d98..13f126eb0c 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 927f19276f..35ac10baf2 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 3a73c8f950..5a7e2e62ac 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 313f597054..5e59091b0f 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;
}

Back to the top