Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-14 16:02:25 +0000
committerEike Stepper2007-09-14 16:02:25 +0000
commitb42106615879659c36254dd3da6d5bb3ab40aa22 (patch)
tree455f7fa66b20130d41d51c5fac36fd268288232e /plugins
parentbcb4bc5dca959e9bd56911c03e0e3fdf41b0fae0 (diff)
downloadcdo-b42106615879659c36254dd3da6d5bb3ab40aa22.tar.gz
cdo-b42106615879659c36254dd3da6d5bb3ab40aa22.tar.xz
cdo-b42106615879659c36254dd3da6d5bb3ab40aa22.zip
[202833] Horizontal Mapping Strategy
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202833
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java26
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java90
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java20
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java45
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBAdapter.java5
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchema.java7
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBAdapter.java18
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchema.java14
8 files changed, 188 insertions, 37 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
index fac3f8e4a3..5ea4d5cf56 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
@@ -24,6 +24,32 @@ public class CDODBSchema extends DBSchema
public static final CDODBSchema INSTANCE = new CDODBSchema();
/**
+ * DBTable cdo_repository
+ */
+ public static final IDBTable REPOSITORY = INSTANCE.addTable("cdo_repository");
+
+ public static final IDBField REPOSITORY_NAME = //
+ REPOSITORY.addField("name", DBType.VARCHAR, 255);
+
+ public static final IDBField REPOSITORY_UUID = //
+ REPOSITORY.addField("uuid", DBType.VARCHAR, 64);
+
+ public static final IDBField REPOSITORY_STARTS = //
+ REPOSITORY.addField("starts", DBType.BIGINT);
+
+ public static final IDBField REPOSITORY_STARTED = //
+ REPOSITORY.addField("started", DBType.BIGINT);
+
+ public static final IDBField REPOSITORY_STOPPED = //
+ REPOSITORY.addField("stopped", DBType.BIGINT);
+
+ public static final IDBField REPOSITORY_NEXT_CDOID = //
+ REPOSITORY.addField("next_cdoid", DBType.BIGINT);
+
+ public static final IDBField REPOSITORY_NEXT_METAID = //
+ REPOSITORY.addField("next_metaid", DBType.BIGINT);
+
+ /**
* DBTable cdo_packages
*/
public static final IDBTable PACKAGES = INSTANCE.addTable("cdo_packages");
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index 8816a3f581..0089d5d315 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.db;
+import org.eclipse.emf.cdo.internal.server.Repository;
import org.eclipse.emf.cdo.internal.server.Store;
import org.eclipse.emf.cdo.protocol.model.CDOType;
import org.eclipse.emf.cdo.server.ISession;
@@ -23,10 +24,12 @@ import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBSchema;
+import org.eclipse.net4j.db.IDBTable;
import org.eclipse.net4j.internal.db.DBSchema;
import org.eclipse.net4j.util.ImplementationError;
import java.sql.Connection;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -136,12 +139,24 @@ public class DBStore extends Store implements IDBStore
protected void doActivate() throws Exception
{
super.doActivate();
- CDODBSchema.INSTANCE.create(dbAdapter, connectionProvider);
+ Set<IDBTable> createdTables = CDODBSchema.INSTANCE.create(dbAdapter, connectionProvider);
DBStoreAccessor writer = getWriter(null);
Connection connection = writer.getConnection();
try
{
+ if (createdTables.contains(CDODBSchema.REPOSITORY))
+ {
+ insertRepositoryRow(writer);
+ }
+ else
+ {
+ Repository repository = (Repository)getRepository();
+ repository.setNextOIDValue(DBUtil.selectMaximum(connection, CDODBSchema.REPOSITORY_NEXT_CDOID));
+ repository.setNextMetaIDValue(DBUtil.selectMaximum(connection, CDODBSchema.REPOSITORY_NEXT_METAID));
+ updateRepositoryRow(writer, true);
+ }
+
nextPackageID = DBUtil.selectMaximum(connection, CDODBSchema.PACKAGES_ID) + 1;
nextClassID = DBUtil.selectMaximum(connection, CDODBSchema.CLASSES_ID) + 1;
nextFeatureID = DBUtil.selectMaximum(connection, CDODBSchema.FEATURES_ID) + 1;
@@ -154,12 +169,85 @@ public class DBStore extends Store implements IDBStore
}
}
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ DBStoreAccessor writer = getWriter(null);
+ Connection connection = writer.getConnection();
+
+ try
+ {
+ updateRepositoryRow(writer, false);
+ writer.release();
+ }
+ finally
+ {
+ DBUtil.close(connection);
+ }
+
+ super.doDeactivate();
+ }
+
protected IDBSchema createSchema()
{
String name = getRepository().getName();
return new DBSchema(name);
}
+ protected void insertRepositoryRow(DBStoreAccessor writer)
+ {
+ Repository repository = (Repository)getRepository();
+ DBUtil.insertRow(writer.getConnection(), dbAdapter, CDODBSchema.REPOSITORY, repository.getName(), repository
+ .getUUID(), 1, System.currentTimeMillis(), 0, 0, 0);
+ }
+
+ protected void updateRepositoryRow(DBStoreAccessor writer, boolean started)
+ {
+ Repository repository = (Repository)getRepository();
+ StringBuilder builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(CDODBSchema.REPOSITORY);
+ builder.append(" SET ");
+ if (started)
+ {
+ builder.append(CDODBSchema.REPOSITORY_STARTS);
+ builder.append("=");
+ builder.append(CDODBSchema.REPOSITORY_STARTS);
+ builder.append("+1, ");
+ builder.append(CDODBSchema.REPOSITORY_STARTED);
+ builder.append("=");
+ builder.append(System.currentTimeMillis());
+ builder.append(", ");
+ builder.append(CDODBSchema.REPOSITORY_STOPPED);
+ builder.append("=0, ");
+ builder.append(CDODBSchema.REPOSITORY_NEXT_CDOID);
+ builder.append("=0, ");
+ builder.append(CDODBSchema.REPOSITORY_NEXT_METAID);
+ builder.append("=0");
+ }
+ else
+ {
+ builder.append(CDODBSchema.REPOSITORY_STOPPED);
+ builder.append("=");
+ builder.append(System.currentTimeMillis());
+ builder.append(", ");
+ builder.append(CDODBSchema.REPOSITORY_NEXT_CDOID);
+ builder.append("=");
+ builder.append(repository.getNextOIDValue());
+ builder.append(", ");
+ builder.append(CDODBSchema.REPOSITORY_NEXT_METAID);
+ builder.append("=");
+ builder.append(repository.getNextMetaIDValue());
+ }
+
+ String sql = builder.toString();
+ int count = DBUtil.update(writer.getConnection(), sql);
+ if (count == 0)
+ {
+ throw new DBException("No row updated in table " + CDODBSchema.REPOSITORY);
+ }
+ }
+
public static DBType getDBType(CDOType type)
{
if (type == CDOType.BOOLEAN || type == CDOType.BOOLEAN_OBJECT)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index ec7da52ba8..dfa8020a09 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -201,6 +201,16 @@ public class Repository extends Container<IRepositoryElement> implements IReposi
return CDOIDRangeImpl.create(lowerBound, nextMetaIDValue - 2);
}
+ public void setNextMetaIDValue(long nextMetaIDValue)
+ {
+ this.nextMetaIDValue = nextMetaIDValue;
+ }
+
+ public long getNextMetaIDValue()
+ {
+ return nextMetaIDValue;
+ }
+
public CDOID getNextCDOID()
{
CDOID id = CDOIDImpl.create(nextOIDValue);
@@ -209,6 +219,16 @@ public class Repository extends Container<IRepositoryElement> implements IReposi
return id;
}
+ public long getNextOIDValue()
+ {
+ return nextOIDValue;
+ }
+
+ public void setNextOIDValue(long nextOIDValue)
+ {
+ this.nextOIDValue = nextOIDValue;
+ }
+
@Override
public String toString()
{
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
index 0d1e83dd42..502caa0e4c 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java
@@ -186,6 +186,26 @@ public final class DBUtil
}
}
+ public static int update(Connection connection, String sql)
+ {
+ if (TRACER.isEnabled()) TRACER.trace(sql);
+ Statement statement = null;
+
+ try
+ {
+ statement = connection.createStatement();
+ return statement.executeUpdate(sql);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(statement);
+ }
+ }
+
public static void insertRow(Connection connection, IDBAdapter dbAdapter, IDBTable table, Object... args)
throws DBException
{
@@ -214,29 +234,10 @@ public final class DBUtil
builder.append(")");
String sql = builder.toString();
- if (TRACER.isEnabled())
+ int count = update(connection, sql);
+ if (count == 0)
{
- TRACER.trace(sql);
- }
-
- Statement statement = null;
-
- try
- {
- statement = connection.createStatement();
- int count = statement.executeUpdate(sql);
- if (count == 0)
- {
- throw new DBException("No row inserted into table " + table);
- }
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- close(statement);
+ throw new DBException("No row inserted into table " + table);
}
}
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 21fe31b976..2a13003c8d 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
@@ -16,6 +16,7 @@ import org.eclipse.net4j.util.registry.IRegistry;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.Statement;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -30,9 +31,9 @@ public interface IDBAdapter
public Driver getJDBCDriver();
- public void createTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException;
+ public Set<IDBTable> createTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException;
- public void createTable(IDBTable table, Statement statement) throws DBException;
+ public boolean createTable(IDBTable table, Statement statement) throws DBException;
public String mangleTableName(String name, int attempt);
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchema.java
index bfd606fa9c..2f9e90b161 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/IDBSchema.java
@@ -13,6 +13,7 @@ package org.eclipse.net4j.db;
import javax.sql.DataSource;
import java.sql.Connection;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -25,9 +26,9 @@ public interface IDBSchema extends IDBElement
public IDBTable[] getTables();
- public void create(IDBAdapter dbAdapter, Connection connection) throws DBException;
+ public Set<IDBTable> create(IDBAdapter dbAdapter, Connection connection) throws DBException;
- public void create(IDBAdapter dbAdapter, ConnectionProvider connectionProvider) throws DBException;
+ public Set<IDBTable> create(IDBAdapter dbAdapter, ConnectionProvider connectionProvider) throws DBException;
- public void create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException;
+ public Set<IDBTable> create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException;
}
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 0c06c8eb92..a2ad6c673f 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
@@ -24,6 +24,8 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -52,8 +54,9 @@ public abstract class DBAdapter implements IDBAdapter
return version;
}
- public void createTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException
+ public Set<IDBTable> createTables(Iterable<? extends IDBTable> tables, Connection connection) throws DBException
{
+ Set<IDBTable> createdTables = new HashSet<IDBTable>();
Statement statement = null;
try
@@ -61,7 +64,10 @@ public abstract class DBAdapter implements IDBAdapter
statement = connection.createStatement();
for (IDBTable table : tables)
{
- createTable(table, statement);
+ if (createTable(table, statement))
+ {
+ createdTables.add(table);
+ }
}
}
catch (SQLException ex)
@@ -72,16 +78,21 @@ public abstract class DBAdapter implements IDBAdapter
{
DBUtil.close(statement);
}
+
+ return createdTables;
}
- public void createTable(IDBTable table, Statement statement) throws DBException
+ public boolean createTable(IDBTable table, Statement statement) throws DBException
{
+ boolean created = true;
+
try
{
doCreateTable((DBTable)table, statement);
}
catch (SQLException ex)
{
+ created = false;
if (TRACER.isEnabled())
{
TRACER.trace("-- " + ex.getMessage());
@@ -89,6 +100,7 @@ public abstract class DBAdapter implements IDBAdapter
}
validateTable((DBTable)table, statement);
+ return created;
}
public String mangleTableName(String name, int attempt)
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchema.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchema.java
index 8c7778a5c7..95a372c1e6 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchema.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBSchema.java
@@ -15,12 +15,14 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBSchema;
+import org.eclipse.net4j.db.IDBTable;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -86,19 +88,19 @@ public class DBSchema extends DBElement implements IDBSchema
return locked = true;
}
- public void create(IDBAdapter dbAdapter, Connection connection) throws DBException
+ public Set<IDBTable> create(IDBAdapter dbAdapter, Connection connection) throws DBException
{
- dbAdapter.createTables(tables.values(), connection);
+ return dbAdapter.createTables(tables.values(), connection);
}
- public void create(IDBAdapter dbAdapter, ConnectionProvider connectionProvider) throws DBException
+ public Set<IDBTable> create(IDBAdapter dbAdapter, ConnectionProvider connectionProvider) throws DBException
{
Connection connection = null;
try
{
connection = connectionProvider.getConnection();
- create(dbAdapter, connection);
+ return create(dbAdapter, connection);
}
finally
{
@@ -106,9 +108,9 @@ public class DBSchema extends DBElement implements IDBSchema
}
}
- public void create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException
+ public Set<IDBTable> create(IDBAdapter dbAdapter, DataSource dataSource) throws DBException
{
- create(dbAdapter, DBUtil.createConnectionProvider(dataSource));
+ return create(dbAdapter, DBUtil.createConnectionProvider(dataSource));
}
void assertUnlocked() throws DBException

Back to the top