From 6d04c6655c13af225b32b7e0dcb2a29ae6937d64 Mon Sep 17 00:00:00 2001 From: Esteban Dugueperoux Date: Thu, 16 Oct 2014 17:57:35 +0200 Subject: [447593] Already in cache when calling twice "CDOTransaction.setBranch();" Update DBUtil.close() to throw a DBException instead of returning a Exception which will be ignored, when the "-Dorg.eclipse.net4j.db.close.noisy=true" is specified. Reapply partial fix of https://bugs.eclipse.org/bugs/show_bug.cgi?id=370105 , only the "readLists" part and not the "readValuesFromStatement" which is the original cause of bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=406766 . In addition update AllTests and GerritTests launch configuration to have the noisy close enabled during tests execution. Change-Id: I6ed6f2d6d0ead05873c37c43fa6f43b1b5095d2f Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=447593 Signed-off-by: Esteban Dugueperoux --- features/org.eclipse.net4j.db-feature/feature.xml | 2 +- .../HorizontalBranchingClassMapping.java | 42 ++++++------- .../CDO GerritTests.launch | 2 +- .../launches/CDO AllTests.launch | 2 +- .../cdo/tests/bugzilla/Bugzilla_447593_Test.java | 68 ++++++++++++++++++++++ plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF | 24 ++++---- .../src/org/eclipse/net4j/db/DBUtil.java | 66 +++++++-------------- .../org/eclipse/net4j/util/om/trace/Tracer.java | 4 +- 8 files changed, 130 insertions(+), 80 deletions(-) create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447593_Test.java diff --git a/features/org.eclipse.net4j.db-feature/feature.xml b/features/org.eclipse.net4j.db-feature/feature.xml index d21dcf14b6..7460c6f5f2 100644 --- a/features/org.eclipse.net4j.db-feature/feature.xml +++ b/features/org.eclipse.net4j.db-feature/feature.xml @@ -12,7 +12,7 @@ diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java index a26d47cdd6..a0f2454eaa 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java @@ -351,7 +351,8 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler(); IDBPreparedStatement stmt = null; - + boolean success = false; + try { if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE) @@ -370,15 +371,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp } // Read singleval-attribute table always (even without modeled attributes!) - boolean success = readValuesFromStatement(stmt, revision, accessor); - - // Read multival tables only if revision exists - if (success && revision.getVersion() >= CDOBranchVersion.FIRST_VERSION) - { - readLists(accessor, revision, listChunk); - } - - return success; + success = readValuesFromStatement(stmt, revision, accessor); } catch (SQLException ex) { @@ -388,6 +381,14 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp { DBUtil.close(stmt); } + + // Read multival tables only if revision exists + if (success && revision.getVersion() >= CDOBranchVersion.FIRST_VERSION) + { + readLists(accessor, revision, listChunk); + } + + return success; } public boolean readRevisionByVersion(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk) @@ -395,7 +396,8 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler(); IDBPreparedStatement stmt = accessor.getDBConnection().prepareStatement(sqlSelectAttributesByVersion, ReuseProbability.HIGH); - + boolean success = false; + try { idHandler.setCDOID(stmt, 1, revision.getID()); @@ -403,15 +405,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp stmt.setInt(3, revision.getVersion()); // Read singleval-attribute table always (even without modeled attributes!) - boolean success = readValuesFromStatement(stmt, revision, accessor); - - // Read multival tables only if revision exists - if (success) - { - readLists(accessor, revision, listChunk); - } - - return success; + success = readValuesFromStatement(stmt, revision, accessor); } catch (SQLException ex) { @@ -421,6 +415,14 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp { DBUtil.close(stmt); } + + // Read multival tables only if revision exists + if (success) + { + readLists(accessor, revision, listChunk); + } + + return success; } public IDBPreparedStatement createResourceQueryStatement(IDBStoreAccessor accessor, CDOID folderId, String name, diff --git a/plugins/org.eclipse.emf.cdo.tests.all/CDO GerritTests.launch b/plugins/org.eclipse.emf.cdo.tests.all/CDO GerritTests.launch index 95c757ac32..1351aabfc3 100644 --- a/plugins/org.eclipse.emf.cdo.tests.all/CDO GerritTests.launch +++ b/plugins/org.eclipse.emf.cdo.tests.all/CDO GerritTests.launch @@ -12,5 +12,5 @@ - + diff --git a/plugins/org.eclipse.emf.cdo.tests/launches/CDO AllTests.launch b/plugins/org.eclipse.emf.cdo.tests/launches/CDO AllTests.launch index 2bfc3d78ef..c85e814d7c 100644 --- a/plugins/org.eclipse.emf.cdo.tests/launches/CDO AllTests.launch +++ b/plugins/org.eclipse.emf.cdo.tests/launches/CDO AllTests.launch @@ -35,6 +35,6 @@ - + diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447593_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447593_Test.java new file mode 100644 index 0000000000..ee030fa7fd --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_447593_Test.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004-2014 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Esteban Dugueperoux - initial API and implementation + */ +package org.eclipse.emf.cdo.tests.bugzilla; + +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.tests.AbstractCDOTest; +import org.eclipse.emf.cdo.tests.config.IRepositoryConfig; +import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires; +import org.eclipse.emf.cdo.tests.model1.Category; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CDOUtil; + +/** + * Test calling to {@link CDOTransaction#setBranch(CDOBranch)} twice. It causes "IllegalStateException : Already in cache". + * + * @author Esteban Dugueperoux + */ +@Requires(IRepositoryConfig.CAPABILITY_BRANCHING) +public class Bugzilla_447593_Test extends AbstractCDOTest +{ + + public void testTwiceCDOTransactionSetBranch() throws Exception + { + CDOSession session = openSession(); + + CDOTransaction transaction = session.openTransaction(); + String resourcePath = getResourcePath("test1.model1"); + CDOResource resource = transaction.createResource(resourcePath); + Category category = getModel1Factory().createCategory(); + category.setName("categoryFromMainBranch"); + resource.getContents().add(category); + transaction.commit(); + + CDOBranch mainBranch = session.getBranchManager().getMainBranch(); + CDOBranch b1ParentBranch = mainBranch.createBranch("b1Parent"); + CDOBranch b1 = b1ParentBranch.createBranch("b1"); + + transaction.enableDurableLocking(); + CDOUtil.getCDOObject(category).cdoWriteLock().lock(); + transaction.setBranch(b1); + resource = transaction.getResource(resourcePath); + category = (Category)resource.getContents().get(0); + category.setName("categoryFromB1Branch"); + resource.getContents().add(getModel1Factory().createCategory()); + transaction.commit(); + + CDOBranch b11 = b1.createBranch("b11"); + + CDOUtil.getCDOObject(category).cdoWriteLock().lock(); + transaction.setBranch(b11); + resource = transaction.getResource(resourcePath); + category = (Category)resource.getContents().get(0); + category.setName("categoryFromB11Branch"); + resource.getContents().add(getModel1Factory().createCategory()); + transaction.commit(); + } + +} diff --git a/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF index 05b09d3243..c9b9b8558e 100644 --- a/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.net4j.db/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.net4j.db;singleton:=true -Bundle-Version: 4.3.0.qualifier +Bundle-Version: 4.4.0.qualifier Bundle-Activator: org.eclipse.net4j.internal.db.bundle.OM$Activator Bundle-Vendor: %providerName Bundle-ClassPath: . @@ -11,16 +11,16 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.net4j.util;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.net4j.db.jdbc;bundle-version="[4.0.0,5.0.0)" -Export-Package: org.eclipse.net4j.db;version="4.3.0", - org.eclipse.net4j.db.ddl;version="4.3.0", - org.eclipse.net4j.db.ddl.delta;version="4.3.0", - org.eclipse.net4j.db.dml;version="4.3.0", - org.eclipse.net4j.internal.db;version="4.3.0";x-internal:=true, - org.eclipse.net4j.internal.db.bundle;version="4.3.0";x-internal:=true, - org.eclipse.net4j.internal.db.ddl;version="4.3.0";x-internal:=true, - org.eclipse.net4j.internal.db.ddl.delta;version="4.3.0";x-internal:=true, - org.eclipse.net4j.internal.db.dml;version="4.3.0";x-internal:=true, - org.eclipse.net4j.spi.db;version="4.3.0", - org.eclipse.net4j.spi.db.ddl;version="4.3.0" +Export-Package: org.eclipse.net4j.db;version="4.4.0", + org.eclipse.net4j.db.ddl;version="4.4.0", + org.eclipse.net4j.db.ddl.delta;version="4.4.0", + org.eclipse.net4j.db.dml;version="4.4.0", + org.eclipse.net4j.internal.db;version="4.4.0";x-internal:=true, + org.eclipse.net4j.internal.db.bundle;version="4.4.0";x-internal:=true, + org.eclipse.net4j.internal.db.ddl;version="4.4.0";x-internal:=true, + org.eclipse.net4j.internal.db.ddl.delta;version="4.4.0";x-internal:=true, + org.eclipse.net4j.internal.db.dml;version="4.4.0";x-internal:=true, + org.eclipse.net4j.spi.db;version="4.4.0", + org.eclipse.net4j.spi.db.ddl;version="4.4.0" Bundle-ActivationPolicy: lazy Eclipse-BuddyPolicy: registered 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 f019877ea6..0918d52bc7 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 @@ -62,6 +62,16 @@ public final class DBUtil public static final int MAX_BATCH_SIZE = Integer.parseInt(OMPlatform.INSTANCE.getProperty( "org.eclipse.net4j.db.MAX_BATCH_SIZE", "2000")); + /** + * A system property to enable noisy close, i.e. exception catch in close methods are thrown as {@link DBException} exception. + * + * @since 4.4 + */ + public static final String PROP_ENABLE_NOISY_CLOSE = "org.eclipse.net4j.db.close.noisy"; + + private static final boolean isNoisyCloseEnabled = Boolean.valueOf(OMPlatform.INSTANCE.getProperty( + PROP_ENABLE_NOISY_CLOSE, Boolean.FALSE.toString())); + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SQL, DBUtil.class); private DBUtil() @@ -192,50 +202,6 @@ public final class DBUtil return new DBDatabase((DBAdapter)adapter, connectionProvider, schemaName, fixNullableIndexColumns); } - // /** - // * @since 4.2 - // */ - // public static T updateSchema(IDBConnectionProvider connectionProvider, RunnableWithConnection runnable) - // { - // return execute(connectionProvider, new RunnableWithConnection() - // { - // public T run(Connection connection) throws SQLException - // { - // return null; - // } - // }); - // } - // - // /** - // * @since 4.2 - // */ - // public static T updateSchema(Connection connection, RunnableWithConnection runnable) - // { - // DBConnection dbConnection = null; - // - // try - // { - // if (connection instanceof DBConnection) - // { - // dbConnection = (DBConnection)connection; - // dbConnection.getDatabase().beginSchemaAccess(true); - // } - // - // return runnable.run(connection); - // } - // catch (SQLException ex) - // { - // throw new DBException(ex); - // } - // finally - // { - // if (dbConnection != null) - // { - // - // } - // } - // } - public static IDBSchema createSchema(String name) { return new org.eclipse.net4j.internal.db.ddl.DBSchema(name); @@ -417,6 +383,10 @@ public final class DBUtil } catch (Exception ex) { + if (isNoisyCloseEnabled) + { + throw new DBException(ex); + } OM.LOG.error(ex); return ex; } @@ -435,6 +405,10 @@ public final class DBUtil } catch (Exception ex) { + if (isNoisyCloseEnabled) + { + throw new DBException(ex); + } OM.LOG.error(ex); return ex; } @@ -460,6 +434,10 @@ public final class DBUtil } catch (Exception ex) { + if (isNoisyCloseEnabled) + { + throw new DBException(ex); + } OM.LOG.error(ex); return ex; } diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/trace/Tracer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/trace/Tracer.java index 4956003b62..3edecbea51 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/trace/Tracer.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/trace/Tracer.java @@ -13,6 +13,7 @@ package org.eclipse.net4j.util.om.trace; import org.eclipse.net4j.internal.util.bundle.AbstractPlatform; import org.eclipse.net4j.util.om.OMBundle; import org.eclipse.net4j.util.om.OMBundle.DebugSupport; +import org.eclipse.net4j.util.om.OMPlatform; import java.text.MessageFormat; @@ -28,7 +29,8 @@ public class Tracer implements OMTracer */ public static final String PROP_DISABLE_TRACING = "org.eclipse.net4j.util.om.trace.disable"; - private static final boolean isGloballyDisabled = Boolean.valueOf(System.getProperty(PROP_DISABLE_TRACING, "false")); + private static final boolean isGloballyDisabled = Boolean.valueOf(OMPlatform.INSTANCE.getProperty( + PROP_DISABLE_TRACING, Boolean.FALSE.toString())); private OMBundle bundle; -- cgit v1.2.3