From da567c2866d238a66127d33f231e910c11afccd5 Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Tue, 11 Jul 2006 10:17:22 +0000 Subject: [150231] Add Derby support and make it the default database --- .../src/org/eclipse/emf/cdo/server/Mapper.java | 2 + .../eclipse/emf/cdo/server/impl/MapperImpl.java | 43 +++++++++++++--------- .../protocol/CommitTransactionIndication.java | 18 +++++++-- 3 files changed, 42 insertions(+), 21 deletions(-) (limited to 'plugins/org.eclipse.emf.cdo.server') diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java index 68cee68551..ab84e8387b 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java @@ -31,6 +31,8 @@ public interface Mapper extends Service public void sql(String sql, Object[] args); + public void sql(String sql, Object[] args, int[] types); + public int getCollectionCount(long oid, int feature); public boolean lock(long oid, int oca); diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java index 2dac4c14a5..c325bd1ef4 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java @@ -391,22 +391,21 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants public void insertPackage(final PackageInfo packageInfo) { - sql(INSERT_PACKAGE, new Object[] { new Integer(packageInfo.getPid()), packageInfo.getName()}); + sql(INSERT_PACKAGE, new Object[] { packageInfo.getPid(), packageInfo.getName()}); } public void insertClass(final ClassInfo classInfo) { String parentName = classInfo.getParentName() == null ? "" : classInfo.getParentName(); - sql(INSERT_CLASS, new Object[] { new Integer(classInfo.getCID()), classInfo.getName(), - parentName, classInfo.getTableName(), new Integer(classInfo.getPackageInfo().getPid())}); + sql(INSERT_CLASS, new Object[] { classInfo.getCID(), classInfo.getName(), parentName, + classInfo.getTableName(), classInfo.getPackageInfo().getPid()}); } public void insertAttribute(final AttributeInfo attributeInfo, final int cid) { - sql(INSERT_ATTRIBUTE, - new Object[] { attributeInfo.getName(), new Integer(attributeInfo.getFeatureID()), - new Integer(attributeInfo.getDataType()), attributeInfo.getColumnName(), - new Integer(attributeInfo.getColumnType()), new Integer(cid)}); + sql(INSERT_ATTRIBUTE, new Object[] { attributeInfo.getName(), attributeInfo.getFeatureID(), + attributeInfo.getDataType(), attributeInfo.getColumnName(), attributeInfo.getColumnType(), + cid}); } public ResourceInfo selectResourceInfo(String path) @@ -505,7 +504,7 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants public ResourceInfo createResource(String resourcePath) { int rid = getNextRID(); - sql(INSERT_RESOURCE, new Object[] { new Integer(rid), resourcePath}); + sql(INSERT_RESOURCE, new Object[] { rid, resourcePath}); return resourceManager.registerResourceInfo(resourcePath, rid, 1); } @@ -528,24 +527,22 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants public void insertResource(int rid, String path) { - sql(INSERT_RESOURCE, new Object[] { new Integer(rid), path}); + sql(INSERT_RESOURCE, new Object[] { rid, path}); } public void insertReference(long oid, int feature, int ordinal, long target, boolean content) { - sql(INSERT_REFERENCE, new Object[] { new Long(oid), new Integer(feature), new Integer(ordinal), - new Long(target), new Boolean(content)}); + sql(INSERT_REFERENCE, new Object[] { oid, feature, ordinal, target, content}); } public void removeReference(long oid, int feature, int ordinal) { - sql(REMOVE_REFERENCE, new Object[] { new Long(oid), new Integer(feature), new Integer(ordinal)}); + sql(REMOVE_REFERENCE, new Object[] { oid, feature, ordinal}); } public void moveReferenceAbsolute(long oid, int feature, int toIndex, int fromIndex) { - sql(MOVE_REFERENCE_ABSOLUTE, new Object[] { new Integer(toIndex), new Long(oid), - new Integer(feature), new Integer(fromIndex)}); + sql(MOVE_REFERENCE_ABSOLUTE, new Object[] { toIndex, oid, feature, fromIndex}); } public void moveReferencesRelative(long oid, int feature, int startIndex, int endIndex, int offset) @@ -566,7 +563,7 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants protected void removeReferences(long oid) { - Object[] args = { new Long(oid)}; + Object[] args = { oid}; if (isDebugEnabled()) debug(StringHelper.replaceWildcards(REMOVE_REFERENCES, "?", args)); jdbcTemplate.update(REMOVE_REFERENCES, args); @@ -629,12 +626,12 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants public void insertContent(long oid) { - sql(INSERT_CONTENT, new Object[] { new Long(oid)}); + sql(INSERT_CONTENT, new Object[] { oid}); } public void removeContent(long oid) { - sql(REMOVE_CONTENT, new Object[] { new Long(oid)}); + sql(REMOVE_CONTENT, new Object[] { oid}); } public void sql(String sql) @@ -661,6 +658,18 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants } } + public void sql(String sql, Object[] args, int[] types) + { + if (isDebugEnabled()) debug(StringHelper.replaceWildcards(sql, "?", args)); + + int rows = jdbcTemplate.update(sql, args, types); + + if (rows != 1) + { + throw new DatabaseInconsistencyException(sql); + } + } + public void transmitContent(final Channel channel, ResourceInfo resourceInfo) { if (resourceInfo != null) diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java index da53b2867e..d53ddb5b8a 100644 --- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java +++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java @@ -39,6 +39,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.sql.Types; + public class CommitTransactionIndication extends AbstractIndicationWithResponse { @@ -519,7 +521,9 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse { int count = receiveInt(); Object[] args = new Object[count + 1]; // last element is the oid - args[count] = new Long(oid); + args[count] = oid; + int[] types = new int[count + 1]; + types[count] = Types.BIGINT; StringBuffer sql = new StringBuffer("UPDATE "); sql.append(classInfo.getTableName()); @@ -530,7 +534,9 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse int feature = receiveInt(); AttributeInfo attributeInfo = classInfo.getAttributeInfo(feature); ColumnConverter converter = getMapper().getColumnConverter(); + args[i] = converter.fromChannel(getChannel(), attributeInfo.getDataType()); + types[i] = attributeInfo.getColumnType(); if (i > 0) sql.append(", "); sql.append(attributeInfo.getColumnName()); @@ -541,7 +547,7 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse sql.append(SQLConstants.USER_OID_COLUMN); sql.append("=?"); - getMapper().sql(sql.toString(), args); + getMapper().sql(sql.toString(), args, types); } @@ -554,7 +560,10 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse AttributeInfo[] attributeInfos = classInfo.getAttributeInfos(); Object[] args = new Object[attributeInfos.length + 1]; // the first element is the oid - args[0] = new Long(oid); + args[0] = oid; + + int[] types = new int[attributeInfos.length + 1]; + types[0] = Types.BIGINT; StringBuffer sql = new StringBuffer("INSERT INTO "); sql.append(classInfo.getTableName()); @@ -567,12 +576,13 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse ColumnConverter converter = getMapper().getColumnConverter(); args[i + 1] = converter.fromChannel(getChannel(), attributeInfo.getDataType()); + types[i + 1] = attributeInfo.getColumnType(); sql.append(", ?"); } sql.append(")"); - getMapper().sql(sql.toString(), args); + getMapper().sql(sql.toString(), args, types); classInfo = classInfo.getParent(); } -- cgit v1.2.3