Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/mysql/MYSQLAdapter.java61
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/ddl/IDBTable.java10
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DBTable.java13
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java10
4 files changed, 94 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/mysql/MYSQLAdapter.java b/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/mysql/MYSQLAdapter.java
index 87f9d0cf15..299e936543 100644
--- a/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/mysql/MYSQLAdapter.java
+++ b/plugins/org.eclipse.net4j.db.mysql/src/org/eclipse/net4j/db/mysql/MYSQLAdapter.java
@@ -14,10 +14,12 @@ import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
+import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.spi.db.DBAdapter;
import com.mysql.jdbc.ConnectionProperties;
+import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
@@ -69,9 +71,28 @@ public class MYSQLAdapter extends DBAdapter
"WHEN", "WHERE", "WHILE", "WITH", "WRITE", "X509", "XOR", "YEAR_MONTH", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"ZEROFILL" }; //$NON-NLS-1$
+ private final boolean optimizingRandomInserts;
+
public MYSQLAdapter()
{
+ this(false);
+ }
+
+ /**
+ * @since 4.2
+ */
+ public MYSQLAdapter(boolean optimizingRandomInserts)
+ {
super(NAME, VERSION);
+ this.optimizingRandomInserts = optimizingRandomInserts;
+ }
+
+ /**
+ * @since 4.2
+ */
+ public final boolean isOptimizingRandomInserts()
+ {
+ return optimizingRandomInserts;
}
/**
@@ -109,11 +130,51 @@ public class MYSQLAdapter extends DBAdapter
}
@Override
+ protected void appendFieldDefs(Appendable appendable, IDBTable table, String[] defs)
+ {
+ try
+ {
+ if (optimizingRandomInserts && !table.isInsertSequential())
+ {
+ appendable.append("CDO_PK BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, "); //$NON-NLS-1$
+ }
+
+ super.appendFieldDefs(appendable, table, defs);
+ }
+ catch (IOException canNotHappen)
+ {
+ }
+ }
+
+ @Override
+ protected void createPrimaryKey(IDBIndex index, StringBuilder builder)
+ {
+ if (optimizingRandomInserts)
+ {
+ IDBTable table = index.getTable();
+ if (!table.isInsertSequential())
+ {
+ builder.append("CREATE "); //$NON-NLS-1$
+ builder.append("UNIQUE "); //$NON-NLS-1$
+ builder.append("INDEX "); //$NON-NLS-1$
+ builder.append(index);
+ builder.append(" ON "); //$NON-NLS-1$
+ builder.append(table);
+ return;
+ }
+ }
+
+ super.createPrimaryKey(index, builder);
+ }
+
+ @Override
protected void dropPrimaryKey(IDBIndex index, StringBuilder builder)
{
builder.append("ALTER TABLE "); //$NON-NLS-1$
builder.append(index.getTable());
builder.append(" DROP PRIMARY KEY"); //$NON-NLS-1$
+
+ int xxx; // TODO Deal with optimizingRandomInserts
}
@Override
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 3b34ab7081..428bbf0487 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
@@ -110,4 +110,14 @@ public interface IDBTable extends IDBSchemaElement
public IDBIndex getPrimaryKeyIndex();
public String sqlInsert();
+
+ /**
+ * @since 4.5
+ */
+ public boolean isInsertSequential();
+
+ /**
+ * @since 4.5
+ */
+ public void setInsertSequential(boolean on);
}
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 4d128c9b10..e22be5d76a 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
@@ -40,6 +40,8 @@ public class DBTable extends DBSchemaElement implements InternalDBTable
private List<IDBIndex> indices = new ArrayList<IDBIndex>();
+ private boolean insertSequential;
+
public DBTable(IDBSchema schema, String name)
{
super(name);
@@ -336,6 +338,17 @@ public class DBTable extends DBSchemaElement implements InternalDBTable
return builder.toString();
}
+ public boolean isInsertSequential()
+ {
+ return insertSequential;
+ }
+
+ public void setInsertSequential(boolean on)
+ {
+ assertUnlocked();
+ insertSequential = on;
+ }
+
@Override
protected void collectElements(List<IDBSchemaElement> elements)
{
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java
index 147f1b4ee1..934f328c61 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/ddl/DelegatingDBTable.java
@@ -208,4 +208,14 @@ public final class DelegatingDBTable extends DelegatingDBSchemaElement implement
{
return getDelegate().sqlInsert();
}
+
+ public boolean isInsertSequential()
+ {
+ return getDelegate().isInsertSequential();
+ }
+
+ public void setInsertSequential(boolean on)
+ {
+ getDelegate().setInsertSequential(on);
+ }
}

Back to the top