From 2a06d51331343837109c30c5161bf81cf866f811 Mon Sep 17 00:00:00 2001 From: Egidijus Vaishnora Date: Fri, 22 Jul 2011 08:43:44 +0000 Subject: 352303: [DB] null blob is not read from the DB store https://bugs.eclipse.org/bugs/show_bug.cgi?id=352303 --- .../internal/db/mapping/CoreTypeMappings.java | 10 +++ .../src/org/eclipse/emf/cdo/tests/AllConfigs.java | 1 + .../cdo/tests/bugzilla/Bugzilla_352303_Test.java | 71 ++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_352303_Test.java diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java index ee39ca785c..6c973d37a7 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/CoreTypeMappings.java @@ -169,6 +169,11 @@ public class CoreTypeMappings public Object getResultSetValue(ResultSet resultSet) throws SQLException { String str = resultSet.getString(getField().getName()); + if (str == null) + { + return null; + } + int pos = str.indexOf('-'); byte[] id = HexUtil.hexToBytes(str.substring(0, pos)); @@ -216,6 +221,11 @@ public class CoreTypeMappings public Object getResultSetValue(ResultSet resultSet) throws SQLException { String str = resultSet.getString(getField().getName()); + if (str == null) + { + return null; + } + int pos = str.indexOf('-'); byte[] id = HexUtil.hexToBytes(str.substring(0, pos)); diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java index 9235c7f25c..14f8b6beef 100644 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java @@ -235,5 +235,6 @@ public abstract class AllConfigs extends ConfigTestSuite testClasses.add(Bugzilla_351096_Test.class); testClasses.add(Bugzilla_338921_Test.class); testClasses.add(Bugzilla_351393_Test.class); + testClasses.add(Bugzilla_352303_Test.class); } } diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_352303_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_352303_Test.java new file mode 100644 index 0000000000..5f135acc86 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_352303_Test.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2004 - 2011 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.tests.bugzilla; + +import org.eclipse.emf.cdo.common.lob.CDOBlob; +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.model3.Image; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.io.IOUtil; + +import java.io.InputStream; + +/** + * @author Eike Stepper + */ +public class Bugzilla_352303_Test extends AbstractCDOTest +{ + @CleanRepositoriesBefore + public void testReadBlob() throws Exception + { + commitBlob(); + + getRepository().getRevisionManager().getCache().clear(); + + CDOSession session = openSession(); + CDOView view = session.openView(); + CDOResource resource = view.getResource(getResourcePath("res")); + + Image image = (Image)resource.getContents().get(0); + assertEquals(320, image.getWidth()); + assertEquals(200, image.getHeight()); + + CDOBlob blob = image.getData(); + assertEquals(null, blob); + } + + private void commitBlob() throws Exception + { + InputStream inputStream = null; + + try + { + Image image = getModel3Factory().createImage(); + image.setWidth(320); + image.setHeight(200); + + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.createResource(getResourcePath("res")); + resource.getContents().add(image); + + transaction.commit(); + } + finally + { + IOUtil.close(inputStream); + } + } +} -- cgit v1.2.3