Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-04-28 06:42:06 +0000
committerEike Stepper2010-04-28 06:42:06 +0000
commitd94ad276700de65a984310feb9bc7aee916f3aa8 (patch)
tree4f5be89105b7defdf987e13c9fd3f9a3a9242ee2 /plugins
parent980065bbfe0c6516316d7ec756265e1922fa37ee (diff)
downloadcdo-d94ad276700de65a984310feb9bc7aee916f3aa8.tar.gz
cdo-d94ad276700de65a984310feb9bc7aee916f3aa8.tar.xz
cdo-d94ad276700de65a984310feb9bc7aee916f3aa8.zip
[256936] Support for Offline Mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256936
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java44
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java28
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java25
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java4
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBType.java553
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java27
16 files changed, 605 insertions, 166 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java
index d0aebf2297..1d0f1b0491 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBBrowser.java
@@ -286,7 +286,7 @@ public class CDODBBrowser extends Worker
pout.print("<tr>\r\n");
pout.print("<td valign=\"top\">\r\n");
- showTables(pout, connection);
+ showTables(pout, connection, repo);
pout.print("</td>\r\n");
if (table != null)
@@ -310,11 +310,11 @@ public class CDODBBrowser extends Worker
}
}
- protected void showTables(PrintStream pout, Connection connection)
+ protected void showTables(PrintStream pout, Connection connection, String repo)
{
String table = getParam("table");
- List<String> allTableNames = DBUtil.getAllTableNames(connection, null);
+ List<String> allTableNames = DBUtil.getAllTableNames(connection, repo);
for (String tableName : allTableNames)
{
String label = escape(tableName).toLowerCase();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
index ee67a69cac..5e6a584382 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
@@ -13,6 +13,8 @@
*/
package org.eclipse.emf.cdo.server.db;
+import org.eclipse.emf.cdo.common.protocol.CDODataInput;
+import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
@@ -20,6 +22,7 @@ import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EPackage;
+import java.io.IOException;
import java.sql.Connection;
import java.util.Collection;
@@ -83,4 +86,15 @@ public interface IMetaDataManager
* @since 2.0
*/
public void writePackageUnits(Connection connection, InternalCDOPackageUnit[] packageUnits, OMMonitor monitor);
+
+ /**
+ * @since 3.0
+ */
+ public void rawExport(Connection connection, CDODataOutput out, long fromCommitTime, long toCommitTime)
+ throws IOException;
+
+ /**
+ * @since 3.0
+ */
+ public void rawImport(Connection connection, CDODataInput in) throws IOException;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
index ab1ccd2577..ed75b4b994 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
@@ -44,7 +44,6 @@ import org.eclipse.emf.cdo.server.db.mapping.IClassMappingAuditSupport;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.CDOReplicationInfo;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
@@ -823,34 +822,41 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
mappingStrategy.handleRevisions(this, eClass, branch, timeStamp, new DBRevisionHandler(handler));
}
- public CDOReplicationInfo rawExport(CDODataOutput out, int lastReplicatedBranchID, long lastReplicatedCommitTime)
- throws IOException
+ public void rawExport(CDODataOutput out, int fromBranchID, final int toBranchID, long fromCommitTime,
+ final long toCommitTime) throws IOException
{
- final int lastBranchID = getStore().getLastBranchID();
- final long lastCommitTime = getStore().getLastCommitTime();
+ Connection connection = getConnection();
+ DBStore store = getStore();
- IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
- mappingStrategy
- .rawExport(this, out, lastReplicatedBranchID, lastBranchID, lastReplicatedCommitTime, lastCommitTime);
+ IMetaDataManager metaDataManager = store.getMetaDataManager();
+ metaDataManager.rawExport(connection, out, fromCommitTime, toCommitTime);
- return new CDOReplicationInfo()
- {
- public int getLastReplicatedBranchID()
- {
- return lastBranchID;
- }
+ String where = " WHERE " + CDODBSchema.COMMIT_INFOS_TIMESTAMP + " BETWEEN " + fromCommitTime + " AND "
+ + toCommitTime;
+ DBUtil.serializeTable(out, connection, CDODBSchema.COMMIT_INFOS, null, where);
- public long getLastReplicatedCommitTime()
- {
- return lastCommitTime;
- }
- };
+ IMappingStrategy mappingStrategy = store.getMappingStrategy();
+ mappingStrategy.rawExport(this, out, fromBranchID, toBranchID, fromCommitTime, toCommitTime);
}
public void rawImport(CDODataInput in) throws IOException
{
+ IMetaDataManager metaDataManager = getStore().getMetaDataManager();
+ metaDataManager.rawImport(getConnection(), in);
+
+ DBUtil.deserializeTable(in, connection, CDODBSchema.COMMIT_INFOS);
+
IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
mappingStrategy.rawImport(this, in);
+
+ try
+ {
+ connection.commit();
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
index 227bad96d0..f85f5fc3f5 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
@@ -21,6 +21,8 @@ import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.common.protocol.CDODataInput;
+import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IMetaDataManager;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -41,6 +43,7 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -164,6 +167,25 @@ public class MetaDataManager extends Lifecycle implements IMetaDataManager
}
}
+ public void rawExport(Connection connection, CDODataOutput out, long fromCommitTime, long toCommitTime)
+ throws IOException
+ {
+ String where = " WHERE p_u." + CDODBSchema.PACKAGE_UNITS_ID + "<>'" + CDOModelUtil.CORE_PACKAGE_URI + //
+ "' AND p_u." + CDODBSchema.PACKAGE_UNITS_ID + "<>'" + CDOModelUtil.RESOURCE_PACKAGE_URI + //
+ "' AND p_u." + CDODBSchema.PACKAGE_UNITS_TIME_STAMP + " BETWEEN " + fromCommitTime + " AND " + toCommitTime;
+ DBUtil.serializeTable(out, connection, CDODBSchema.PACKAGE_UNITS, "p_u", where);
+
+ String join = ", " + CDODBSchema.PACKAGE_UNITS + " p_u" + where + " AND p_i." + CDODBSchema.PACKAGE_INFOS_UNIT
+ + "=p_u." + CDODBSchema.PACKAGE_UNITS_ID;
+ DBUtil.serializeTable(out, connection, CDODBSchema.PACKAGE_INFOS, "p_i", join);
+ }
+
+ public void rawImport(Connection connection, CDODataInput in) throws IOException
+ {
+ DBUtil.deserializeTable(in, connection, CDODBSchema.PACKAGE_UNITS);
+ DBUtil.deserializeTable(in, connection, CDODBSchema.PACKAGE_INFOS);
+ }
+
protected IDBStore getStore()
{
return store;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
index e00179ca21..8a1744b369 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
@@ -187,7 +187,8 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
Set<CDOID> result = new HashSet<CDOID>();
for (IClassMapping mapping : getClassMappings().values())
{
- result.addAll(mapping.readChangeSet(accessor, segments));
+ Set<CDOID> ids = mapping.readChangeSet(accessor, segments);
+ result.addAll(ids);
}
return result;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
index 772d6a0e71..561eae50fa 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
@@ -105,18 +105,16 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
}
}
- public void rawExport(IDBStoreAccessor accessor, CDODataOutput out, int lastReplicatedBranchID, int lastBranchID,
- long lastReplicatedCommitTime, long lastCommitTime) throws IOException
+ public void rawExport(IDBStoreAccessor accessor, CDODataOutput out, int fromBranchID, int toBranchID,
+ long fromCommitTime, long toCommitTime) throws IOException
{
StringBuilder builder = new StringBuilder();
- builder.append(" WHERE "); //$NON-NLS-1$
- builder.append(lastReplicatedCommitTime);
- builder.append("<"); //$NON-NLS-1$
+ builder.append(" WHERE a_t."); //$NON-NLS-1$
builder.append(CDODBSchema.ATTRIBUTES_CREATED);
+ builder.append(" BETWEEN "); //$NON-NLS-1$
+ builder.append(fromCommitTime);
builder.append(" AND "); //$NON-NLS-1$
- builder.append(CDODBSchema.ATTRIBUTES_CREATED);
- builder.append("<="); //$NON-NLS-1$
- builder.append(lastCommitTime);
+ builder.append(toCommitTime);
String attrSuffix = builder.toString();
Connection connection = accessor.getConnection();
@@ -128,7 +126,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
out.writeCDOClassifierRef(eClass);
IDBTable table = classMapping.getDBTables().get(0);
- DBUtil.serializeTable(out, connection, table, attrSuffix);
+ DBUtil.serializeTable(out, connection, table, "a_t", attrSuffix);
for (IListMapping listMapping : classMapping.getListMappings())
{
@@ -144,14 +142,14 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
{
for (IDBTable table : listMapping.getDBTables())
{
- String listSuffix = ", " + attrTable + " cdo_2" + attrSuffix;
- String listJoin = getListJoin("cdo_2", "cdo_1");
+ String listSuffix = ", " + attrTable + " a_t" + attrSuffix;
+ String listJoin = getListJoin("a_t", "l_t");
if (listJoin != null)
{
listSuffix += listJoin;
}
- DBUtil.serializeTable(out, connection, table, listSuffix);
+ DBUtil.serializeTable(out, connection, table, "l_t", listSuffix);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
index d6923cd9a3..0bd3944562 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
@@ -33,7 +33,6 @@ import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.hibernate.IHibernateStoreAccessor;
import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.PersistableListHolder;
-import org.eclipse.emf.cdo.spi.common.CDOReplicationInfo;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision;
@@ -696,7 +695,7 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
throw new UnsupportedOperationException();
}
- public CDOReplicationInfo rawExport(CDODataOutput out, int lastReplicatedBranchID, long lastReplicatedCommitTime)
+ public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
throws IOException
{
throw new UnsupportedOperationException();
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 a00a33a640..b097f75cc1 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
@@ -1010,8 +1010,34 @@ public class Repository extends Container<Object> implements InternalRepository
public CDOReplicationInfo replicateRaw(CDODataOutput out, int lastReplicatedBranchID, long lastReplicatedCommitTime)
throws IOException
{
+ final int fromBranchID = lastReplicatedBranchID + 1;
+ final int toBranchID = getStore().getLastBranchID();
+
+ final long fromCommitTime = lastReplicatedCommitTime + 1L;
+ final long toCommitTime = getStore().getLastCommitTime();
+
+ // InternalCDOPackageRegistry packageRegistry = getPackageRegistry(false);
+ // InternalCDOPackageUnit[] packageUnits = packageRegistry.getPackageUnits(fromCommitTime, toCommitTime);
+ // out.writeInt(packageUnits.length);
+ // for (InternalCDOPackageUnit packageUnit : packageUnits)
+ // {
+ // }
+
IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- return accessor.rawExport(out, lastReplicatedBranchID, lastReplicatedCommitTime);
+ accessor.rawExport(out, fromBranchID, toBranchID, fromCommitTime, toCommitTime);
+
+ return new CDOReplicationInfo()
+ {
+ public int getLastReplicatedBranchID()
+ {
+ return toBranchID;
+ }
+
+ public long getLastReplicatedCommitTime()
+ {
+ return toCommitTime;
+ }
+ };
}
public void replicate(CDOReplicationContext context)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
index fbd7a1e242..471b833fcf 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
@@ -27,7 +27,6 @@ import org.eclipse.emf.cdo.server.IQueryContext;
import org.eclipse.emf.cdo.server.IQueryHandler;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.spi.common.CDOReplicationInfo;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
@@ -335,7 +334,7 @@ public class MEMStoreAccessor extends LongIDStoreAccessor
return null;
}
- public CDOReplicationInfo rawExport(CDODataOutput out, int lastReplicatedBranchID, long lastReplicatedCommitTime)
+ public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
throws IOException
{
// TODO: implement MEMStoreAccessor.rawExport(out, lastReplicatedBranchID, lastReplicatedCommitTime)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
index dbda4e30cf..3f9ad41bf1 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
@@ -14,6 +14,8 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
+import org.eclipse.emf.ecore.EModelElement;
+
import java.util.Map;
import java.util.Set;
@@ -77,13 +79,34 @@ public interface IStore
public long getCreationTime();
/**
- * Returns the time stamp of the last csuccessful commit operation.
+ * Returns the id of the last branch that has been created in this store.
+ *
+ * @since 3.0
+ */
+ public int getLastBranchID();
+
+ /**
+ * Returns the id of the last local branch that has been created in this store.
+ *
+ * @since 3.0
+ */
+ public int getLastLocalBranchID();
+
+ /**
+ * Returns the time stamp of the last successful commit operation.
*
* @since 3.0
*/
public long getLastCommitTime();
/**
+ * Returns the id of the last {@link EModelElement} that has been committed to this store.
+ *
+ * @since 3.0
+ */
+ public long getLastMetaID();
+
+ /**
* @since 3.0
*/
public Map<String, String> getPropertyValues(Set<String> names);
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java
index 78eb0aa037..5180b8e201 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java
@@ -20,7 +20,6 @@ import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
import org.eclipse.emf.cdo.common.revision.cache.CDORevisionCacheAdder;
import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.spi.common.CDOReplicationInfo;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager.CommitInfoLoader;
@@ -193,9 +192,11 @@ public interface IStoreAccessor extends IQueryHandlerProvider, BranchLoader, Com
public void rollback();
/**
+ * @param toBranchID TODO
+ * @param toCommitTime TODO
* @since 3.0
*/
- public CDOReplicationInfo rawExport(CDODataOutput out, int lastReplicatedBranchID, long lastReplicatedCommitTime)
+ public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
throws IOException;
/**
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java
index ad7e9cf939..62c450c8cd 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/spi/server/InternalStore.java
@@ -36,7 +36,11 @@ public interface InternalStore extends IStore, ILifecycle
public int getNextLocalBranchID();
- public long getLastCommitTime();
+ public void setLastBranchID(int lastBranchID);
+
+ public void setLastLocalBranchID(int lastLocalBranchID);
public void setLastCommitTime(long lastCommitTime);
+
+ public void setLastMetaID(long lastMetaID);
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
index 2fed5d1204..f494357bdb 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
@@ -14,7 +14,7 @@ import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
-import org.eclipse.emf.cdo.tests.OfflineDelayedTest;
+import org.eclipse.emf.cdo.tests.OfflineRawTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.net4j.db.DBUtil;
@@ -71,8 +71,8 @@ public class AllTestsDBH2Offline extends DBConfigs
{
// super.initTestClasses(testClasses);
- // testClasses.add(OfflineRawTest.class);
- testClasses.add(OfflineDelayedTest.class);
+ testClasses.add(OfflineRawTest.class);
+ // testClasses.add(OfflineDelayedTest.class);
// testClasses.add(OfflineTest.class);
// testClasses.add(FailoverTest.class);
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
index d9351a760d..2f82985be6 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/Net4jDBTest.java
@@ -397,7 +397,7 @@ public class Net4jDBTest extends AbstractCDOTest
for (Pair<DBType, Object> column : columns)
{
- column.getElement1().readValue(ins, stmt, c++);
+ column.getElement1().readValue(ins, stmt, c++, false);
}
stmt.executeUpdate();
@@ -419,7 +419,7 @@ public class Net4jDBTest extends AbstractCDOTest
int c = 1;
for (Pair<DBType, Object> column : columns)
{
- column.getElement1().writeValue(outs, resultSet, c++);
+ column.getElement1().writeValue(outs, resultSet, c++, false);
}
resultSet.close();
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 8dabc74623..a2203a69a1 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
@@ -20,8 +20,6 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
-import java.math.BigDecimal;
-import java.math.BigInteger;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.PreparedStatement;
@@ -36,52 +34,68 @@ public enum DBType
BOOLEAN(16)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- boolean value = resultSet.getBoolean(column);
- out.writeBoolean(value);
+ writeValueBoolean(out, resultSet, column, canBeNull);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- boolean value = in.readBoolean();
- statement.setBoolean(column, value);
+ readValueBoolean(in, statement, column, canBeNull, getCode());
}
},
BIT(-7)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- boolean value = resultSet.getBoolean(column);
- out.writeBoolean(value);
+ writeValueBoolean(out, resultSet, column, canBeNull);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- boolean value = in.readBoolean();
- statement.setBoolean(column, value);
+ readValueBoolean(in, statement, column, canBeNull, getCode());
}
},
TINYINT(-6)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
byte value = resultSet.getByte(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeByte(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
byte value = in.readByte();
statement.setByte(column, value);
}
@@ -90,16 +104,34 @@ public enum DBType
SMALLINT(5)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
short value = resultSet.getShort(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeShort(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
short value = in.readShort();
statement.setShort(column, value);
}
@@ -108,16 +140,34 @@ public enum DBType
INTEGER(4)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
int value = resultSet.getInt(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeInt(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
int value = in.readInt();
statement.setInt(column, value);
}
@@ -126,16 +176,34 @@ public enum DBType
BIGINT(-5)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
long value = resultSet.getLong(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeLong(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
long value = in.readLong();
statement.setLong(column, value);
}
@@ -144,16 +212,34 @@ public enum DBType
FLOAT(6)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
float value = resultSet.getFloat(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeFloat(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
float value = in.readFloat();
statement.setFloat(column, value);
}
@@ -162,16 +248,34 @@ public enum DBType
REAL(7)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
float value = resultSet.getFloat(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeFloat(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
float value = in.readFloat();
statement.setFloat(column, value);
}
@@ -180,16 +284,34 @@ public enum DBType
DOUBLE(8)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
double value = resultSet.getDouble(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeDouble(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
double value = in.readDouble();
statement.setDouble(column, value);
}
@@ -198,70 +320,77 @@ public enum DBType
NUMERIC(2)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- BigDecimal value = resultSet.getBigDecimal(column);
- BigInteger valueUnscaled = value.unscaledValue();
-
- byte[] byteArray = valueUnscaled.toByteArray();
- out.writeInt(byteArray.length);
- out.write(byteArray);
- out.writeInt(value.scale());
+ throw new UnsupportedOperationException("SQL NULL has to be considered");
+ // BigDecimal value = resultSet.getBigDecimal(column);
+ // BigInteger valueUnscaled = value.unscaledValue();
+ //
+ // byte[] byteArray = valueUnscaled.toByteArray();
+ // out.writeInt(byteArray.length);
+ // out.write(byteArray);
+ // out.writeInt(value.scale());
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- byte[] bytes = in.readByteArray();
- int scale = in.readInt();
- BigInteger valueUnscaled = new BigInteger(bytes);
- BigDecimal value = new BigDecimal(valueUnscaled, scale);
-
- // TODO: Read out the precision, scale information and bring the big decimal to the correct form.
- statement.setBigDecimal(column, value);
+ throw new UnsupportedOperationException("SQL NULL has to be considered");
+ // byte[] bytes = in.readByteArray();
+ // int scale = in.readInt();
+ // BigInteger valueUnscaled = new BigInteger(bytes);
+ // BigDecimal value = new BigDecimal(valueUnscaled, scale);
+ //
+ // // TODO: Read out the precision, scale information and bring the big decimal to the correct form.
+ // statement.setBigDecimal(column, value);
}
},
DECIMAL(3)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- BigDecimal value = resultSet.getBigDecimal(column);
- BigInteger valueUnscaled = value.unscaledValue();
-
- byte[] byteArray = valueUnscaled.toByteArray();
- out.writeInt(byteArray.length);
- out.write(byteArray);
- out.writeInt(value.scale());
+ throw new UnsupportedOperationException("SQL NULL has to be considered");
+ // BigDecimal value = resultSet.getBigDecimal(column);
+ // BigInteger valueUnscaled = value.unscaledValue();
+ //
+ // byte[] byteArray = valueUnscaled.toByteArray();
+ // out.writeInt(byteArray.length);
+ // out.write(byteArray);
+ // out.writeInt(value.scale());
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- byte[] bytes = in.readByteArray();
- int scale = in.readInt();
-
- BigInteger valueUnscaled = new BigInteger(bytes);
- BigDecimal value = new BigDecimal(valueUnscaled, scale);
- statement.setBigDecimal(column, value);
+ throw new UnsupportedOperationException("SQL NULL has to be considered");
+ // byte[] bytes = in.readByteArray();
+ // int scale = in.readInt();
+ //
+ // BigInteger valueUnscaled = new BigInteger(bytes);
+ // BigDecimal value = new BigDecimal(valueUnscaled, scale);
+ // statement.setBigDecimal(column, value);
}
},
CHAR(1)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
String value = resultSet.getString(column);
out.writeString(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
String value = in.readString();
statement.setString(column, value);
@@ -271,15 +400,16 @@ public enum DBType
VARCHAR(12)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
String value = resultSet.getString(column);
out.writeString(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
String value = in.readString();
statement.setString(column, value);
@@ -289,15 +419,16 @@ public enum DBType
LONGVARCHAR(-1, "LONG VARCHAR") //$NON-NLS-1$
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
String value = resultSet.getString(column);
out.writeString(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
String value = in.readString();
statement.setString(column, value);
@@ -307,9 +438,21 @@ public enum DBType
CLOB(2005)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
Clob value = resultSet.getClob(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
long length = value.length();
Reader reader = value.getCharacterStream();
@@ -329,9 +472,15 @@ public enum DBType
}
@Override
- public void readValue(final ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(final ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
Reader reader;
long length = in.readLong();
@@ -391,16 +540,34 @@ public enum DBType
DATE(91)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
java.sql.Date value = resultSet.getDate(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeLong(value.getTime());
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
long value = in.readLong();
statement.setDate(column, new java.sql.Date(value));
}
@@ -409,16 +576,34 @@ public enum DBType
TIME(92)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
java.sql.Time value = resultSet.getTime(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeLong(value.getTime());
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
long value = in.readLong();
statement.setTime(column, new java.sql.Time(value));
}
@@ -427,17 +612,35 @@ public enum DBType
TIMESTAMP(93)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
java.sql.Timestamp value = resultSet.getTimestamp(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeLong(value.getTime());
out.writeInt(value.getNanos());
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
long value = in.readLong();
int nanos = in.readInt();
java.sql.Timestamp timeStamp = new java.sql.Timestamp(value);
@@ -449,17 +652,35 @@ public enum DBType
BINARY(-2)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
byte[] value = resultSet.getBytes(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeInt(value.length);
out.write(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
byte[] value = in.readByteArray();
statement.setBytes(column, value);
}
@@ -468,17 +689,35 @@ public enum DBType
VARBINARY(-3)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
byte[] value = resultSet.getBytes(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeInt(value.length);
out.write(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
byte[] value = in.readByteArray();
statement.setBytes(column, value);
}
@@ -487,17 +726,35 @@ public enum DBType
LONGVARBINARY(-4, "LONG VARBINARY") //$NON-NLS-1$
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
byte[] value = resultSet.getBytes(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
out.writeInt(value.length);
out.write(value);
}
@Override
- public void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
byte[] value = in.readByteArray();
statement.setBytes(column, value);
}
@@ -506,9 +763,21 @@ public enum DBType
BLOB(2004)
{
@Override
- public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException, IOException
+ public void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
Blob value = resultSet.getBlob(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeBoolean(false);
+ return;
+ }
+
+ out.writeBoolean(true);
+ }
+
long length = value.length();
InputStream stream = value.getBinaryStream();
@@ -528,9 +797,15 @@ public enum DBType
}
@Override
- public void readValue(final ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException
+ public void readValue(final ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException
{
+ if (canBeNull && !in.readBoolean())
+ {
+ statement.setNull(column, getCode());
+ return;
+ }
+
long length = in.readLong();
InputStream value = null;
@@ -561,6 +836,12 @@ public enum DBType
}
};
+ private static final int BOOLEAN_NULL = -1;
+
+ private static final int BOOLEAN_FALSE = 0;
+
+ private static final int BOOLEAN_TRUE = 1;
+
private int code;
private String keyword;
@@ -586,22 +867,74 @@ public enum DBType
return keyword == null ? super.toString() : keyword;
}
+ @Override
+ public String toString()
+ {
+ return getKeyword();
+ }
+
/**
* @since 3.0
*/
- public abstract void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column) throws SQLException,
- IOException;
+ public abstract void writeValue(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException;
/**
* @since 3.0
*/
- public abstract void readValue(ExtendedDataInput in, PreparedStatement statement, int column) throws SQLException,
- IOException;
+ public abstract void readValue(ExtendedDataInput in, PreparedStatement statement, int column, boolean canBeNull)
+ throws SQLException, IOException;
- @Override
- public String toString()
+ private static void writeValueBoolean(ExtendedDataOutput out, ResultSet resultSet, int column, boolean canBeNull)
+ throws SQLException, IOException
{
- return getKeyword();
+ boolean value = resultSet.getBoolean(column);
+ if (canBeNull)
+ {
+ if (resultSet.wasNull())
+ {
+ out.writeByte(BOOLEAN_NULL);
+ }
+ else
+ {
+ out.writeByte(value ? BOOLEAN_TRUE : BOOLEAN_FALSE);
+ }
+ }
+ else
+ {
+ out.writeBoolean(value);
+ }
+ }
+
+ private static void readValueBoolean(ExtendedDataInput in, PreparedStatement statement, int column,
+ boolean canBeNull, int sqlType) throws IOException, SQLException
+ {
+ if (canBeNull)
+ {
+ byte opcode = in.readByte();
+ switch (opcode)
+ {
+ case BOOLEAN_NULL:
+ statement.setNull(column, sqlType);
+ break;
+
+ case BOOLEAN_FALSE:
+ statement.setBoolean(column, false);
+ break;
+
+ case BOOLEAN_TRUE:
+ statement.setBoolean(column, true);
+ break;
+
+ default:
+ throw new IOException("Invalid boolean opcode: " + opcode);
+ }
+ }
+ else
+ {
+ boolean value = in.readBoolean();
+ statement.setBoolean(column, value);
+ }
}
/**
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 077e105e67..ef59912763 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
@@ -246,7 +246,7 @@ public final class DBUtil
{
List<String> names = new ArrayList<String>();
DatabaseMetaData metaData = connection.getMetaData();
- tables = metaData.getTables(dbName, null, null, new String[] { "TABLE" }); //$NON-NLS-1$
+ tables = metaData.getTables(null, dbName.toUpperCase(), null, new String[] { "TABLE" }); //$NON-NLS-1$
while (tables.next())
{
String name = tables.getString(3);
@@ -568,8 +568,8 @@ public final class DBUtil
/**
* @since 3.0
*/
- public static void serializeTable(ExtendedDataOutput out, Connection connection, IDBTable table, String sqlSuffix)
- throws DBException, IOException
+ public static void serializeTable(ExtendedDataOutput out, Connection connection, IDBTable table, String tableAlias,
+ String sqlSuffix) throws DBException, IOException
{
IDBField[] fields = table.getFields();
@@ -582,13 +582,22 @@ public final class DBUtil
builder.append(", "); //$NON-NLS-1$
}
- builder.append("cdo_1."); //$NON-NLS-1$
+ if (tableAlias != null)
+ {
+ builder.append(tableAlias);
+ builder.append("."); //$NON-NLS-1$
+ }
+
builder.append(fields[i]);
}
builder.append(" FROM "); //$NON-NLS-1$
builder.append(table);
- builder.append(" cdo_1"); //$NON-NLS-1$
+ if (tableAlias != null)
+ {
+ builder.append(" "); //$NON-NLS-1$
+ builder.append(tableAlias);
+ }
if (sqlSuffix != null)
{
@@ -612,7 +621,9 @@ public final class DBUtil
for (int i = 0; i < fields.length; i++)
{
IDBField field = fields[i];
- field.getType().writeValue(out, resultSet, i + 1);
+ DBType type = field.getType();
+ boolean canBeNull = !field.isNotNull();
+ type.writeValue(out, resultSet, i + 1, canBeNull);
}
}
@@ -678,7 +689,9 @@ public final class DBUtil
for (int i = 0; i < fields.length; i++)
{
IDBField field = fields[i];
- field.getType().readValue(in, statement, i + 1);
+ DBType type = field.getType();
+ boolean canBeNull = !field.isNotNull();
+ type.readValue(in, statement, i + 1, canBeNull);
}
statement.addBatch();

Back to the top