diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate')
34 files changed, 3183 insertions, 3183 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOHibernateConstants.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOHibernateConstants.java index d49aea2fb9..1ab819ea36 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOHibernateConstants.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOHibernateConstants.java @@ -1,50 +1,50 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-/**
- * Maintains constants used in the CDO-Hibernate integration.
- *
- * @author Martin Taal
- */
-public class CDOHibernateConstants
-{
- public static final String ID_PROPERTY = "id"; //$NON-NLS-1$
-
- public static final String COMMITTIMESTAMP_PROPERTY = "commit_TimeStamp"; //$NON-NLS-1$
-
- public static final String RESOURCE_PROPERTY = "resourceID"; //$NON-NLS-1$
-
- public static final String RESOURCE_PROPERTY_COLUMN = "resource_id"; //$NON-NLS-1$
-
- public static final String CONTAINER_PROPERTY = "containerID"; //$NON-NLS-1$
-
- public static final String CONTAINER_PROPERTY_COLUMN = "container_id"; //$NON-NLS-1$
-
- public static final String FEATUREMAP_PROPERTY_FEATURE = "fme_feature"; //$NON-NLS-1$
-
- public static final String FEATUREMAP_PROPERTY_CDATA = "fme_mixed_cdata"; //$NON-NLS-1$
-
- public static final String FEATUREMAP_PROPERTY_COMMENT = "fme_mixed_comment"; //$NON-NLS-1$
-
- public static final String FEATUREMAP_PROPERTY_TEXT = "fme_mixed_text"; //$NON-NLS-1$
-
- public static final String FEATUREMAP_PROPERTY_ANY_PRIMITIVE = "fme_any_data"; //$NON-NLS-1$
-
- public static final String FEATUREMAP_PROPERTY_ANY_REFERENCE = "fme_any_reference"; //$NON-NLS-1$
-
- public static final String PROPERTY_SEPARATOR = "_"; //$NON-NLS-1$
-
- public static final String NL = "\n"; //$NON-NLS-1$
-
- public static final String UTF8 = "UTF-8"; //$NON-NLS-1$
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +/** + * Maintains constants used in the CDO-Hibernate integration. + * + * @author Martin Taal + */ +public class CDOHibernateConstants +{ + public static final String ID_PROPERTY = "id"; //$NON-NLS-1$ + + public static final String COMMITTIMESTAMP_PROPERTY = "commit_TimeStamp"; //$NON-NLS-1$ + + public static final String RESOURCE_PROPERTY = "resourceID"; //$NON-NLS-1$ + + public static final String RESOURCE_PROPERTY_COLUMN = "resource_id"; //$NON-NLS-1$ + + public static final String CONTAINER_PROPERTY = "containerID"; //$NON-NLS-1$ + + public static final String CONTAINER_PROPERTY_COLUMN = "container_id"; //$NON-NLS-1$ + + public static final String FEATUREMAP_PROPERTY_FEATURE = "fme_feature"; //$NON-NLS-1$ + + public static final String FEATUREMAP_PROPERTY_CDATA = "fme_mixed_cdata"; //$NON-NLS-1$ + + public static final String FEATUREMAP_PROPERTY_COMMENT = "fme_mixed_comment"; //$NON-NLS-1$ + + public static final String FEATUREMAP_PROPERTY_TEXT = "fme_mixed_text"; //$NON-NLS-1$ + + public static final String FEATUREMAP_PROPERTY_ANY_PRIMITIVE = "fme_any_data"; //$NON-NLS-1$ + + public static final String FEATUREMAP_PROPERTY_ANY_REFERENCE = "fme_any_reference"; //$NON-NLS-1$ + + public static final String PROPERTY_SEPARATOR = "_"; //$NON-NLS-1$ + + public static final String NL = "\n"; //$NON-NLS-1$ + + public static final String UTF8 = "UTF-8"; //$NON-NLS-1$ +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/ContainerInfoConverter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/ContainerInfoConverter.java index e7b6f097e0..9540f8a7ca 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/ContainerInfoConverter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/ContainerInfoConverter.java @@ -1,170 +1,170 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDExternal;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject;
-
-/**
- * Is responsible for converting container related information from and to a string representation.
- *
- * @see InternalCDORevision#getContainerID()
- * @see InternalCDORevision#getContainingFeatureID()
- * @see InternalCDORevision#getContainingFeatureID()
- * @author Martin Taal
- */
-public class ContainerInfoConverter
-{
- private static String SEPARATOR = "_:_"; //$NON-NLS-1$
-
- private static String CONTAINER_PREFIX = "-"; //$NON-NLS-1$
-
- private static ContainerInfoConverter instance = new ContainerInfoConverter();
-
- /**
- * @return the instance
- */
- public static ContainerInfoConverter getInstance()
- {
- return instance;
- }
-
- /**
- * @param instance
- * the instance to set
- */
- public static void setInstance(ContainerInfoConverter instance)
- {
- ContainerInfoConverter.instance = instance;
- }
-
- /**
- * Converts the container information of a {@link InternalCDORevision} to a String representation. The container
- * information is the container id ({@link InternalCDORevision#getContainerID()} and the containingFeatureID (
- * {@link InternalCDORevision#getContainingFeatureID()}).
- *
- * @param cdoRevision
- * the InternalCDORevision which has the container information
- * @return a String representation of the container information which can be stored in a single varchar in the
- * database.
- */
- public String convertContainerRelationToString(InternalCDORevision cdoRevision)
- {
- return convertContainerRelationToString(cdoRevision, (CDOID)cdoRevision.getContainerID());
- }
-
- /**
- * Converts the container information of a {@link InternalCDORevision} to a String representation. The container
- * information is the container id ({@link InternalCDORevision#getContainerID()} and the containingFeatureID (
- * {@link InternalCDORevision#getContainingFeatureID()}).
- *
- * @param cdoRevision
- * the InternalCDORevision which has the container information
- * @param containerID
- * the CDOID of the container
- * @return a String representation of the container information which can be stored in a single varchar in the
- * database.
- */
- public String convertContainerRelationToString(InternalCDORevision cdoRevision, CDOID containerID)
- {
- if (containerID == null || containerID.isNull() || containerID.isTemporary())
- {
- return null;
- }
-
- final String strCDOID = HibernateUtil.getInstance().convertCDOIDToString(containerID);
- if (!HibernateUtil.getInstance().isStoreCreatedID(containerID))
- {
- // does not support changing models....
- return strCDOID + SEPARATOR + cdoRevision.getContainingFeatureID();
- }
-
- // get the feature name...
- if (cdoRevision.getContainingFeatureID() < 0)
- {
- final String entityName = HibernateUtil.getInstance().getEntityName(containerID);
- final HibernateStore store = HibernateThreadContext.getCurrentStoreAccessor().getStore();
- final EClass containerEClass = store.getEClass(entityName);
- final int featureID = InternalEObject.EOPPOSITE_FEATURE_BASE - cdoRevision.getContainingFeatureID();
- final EStructuralFeature eFeature = containerEClass.getEStructuralFeature(featureID);
- return strCDOID + SEPARATOR + "-" + eFeature.getName(); //$NON-NLS-1$
- }
-
- final EClass eContainedEClass = cdoRevision.getEClass();
- final EStructuralFeature eFeature = eContainedEClass.getEStructuralFeature(cdoRevision.getContainingFeatureID());
- return strCDOID + SEPARATOR + eFeature.getName();
- }
-
- /**
- * Converts the String generated by the method {@link #convertContainerRelationToString(InternalCDORevision)} back to
- * container information and sets this in the cdoRevision.
- *
- * @param cdoRevision
- * the InternalCDORevision in which the container info is stored.
- * @param containerInfo
- * the containerInfo coded as a String
- */
- public void setContainerRelationFromString(InternalCDORevision cdoRevision, String containerInfo)
- {
- if (containerInfo == null)
- {
- return;
- }
-
- final int index = containerInfo.lastIndexOf(SEPARATOR);
- if (index == -1)
- {
- // TODO: error condition?
- return;
- }
-
- // get/set the container id
- final CDOID containerID = HibernateUtil.getInstance().convertStringToCDOID(containerInfo.substring(0, index));
- cdoRevision.setContainerID(containerID);
-
- final String containerFeatureStr = containerInfo.substring(index + SEPARATOR.length());
- if (containerID instanceof CDOIDExternal)
- {
- cdoRevision.setContainingFeatureID(Integer.parseInt(containerFeatureStr));
- return;
- }
-
- if (containerFeatureStr.startsWith(CONTAINER_PREFIX))
- {
- // part of the container eClass
- final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(containerID);
- if (classifierRef == null)
- {
- throw new IllegalArgumentException("This CDOID type of " + containerID + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- final EClass containerEClass = HibernateUtil.getInstance().getEClass(classifierRef);
-
- // substring 1 because the string starts with a minus
- final EStructuralFeature eFeature = containerEClass.getEStructuralFeature(containerFeatureStr.substring(1));
- final int containerFeatureID = InternalEObject.EOPPOSITE_FEATURE_BASE - containerEClass.getFeatureID(eFeature);
- cdoRevision.setContainingFeatureID(containerFeatureID);
- return;
- }
-
- final EClass eContainedEClass = cdoRevision.getEClass();
- final EStructuralFeature eFeature = eContainedEClass.getEStructuralFeature(containerFeatureStr);
- cdoRevision.setContainingFeatureID(eContainedEClass.getFeatureID(eFeature));
- return;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDExternal; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.model.CDOClassifierRef; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject; + +/** + * Is responsible for converting container related information from and to a string representation. + * + * @see InternalCDORevision#getContainerID() + * @see InternalCDORevision#getContainingFeatureID() + * @see InternalCDORevision#getContainingFeatureID() + * @author Martin Taal + */ +public class ContainerInfoConverter +{ + private static String SEPARATOR = "_:_"; //$NON-NLS-1$ + + private static String CONTAINER_PREFIX = "-"; //$NON-NLS-1$ + + private static ContainerInfoConverter instance = new ContainerInfoConverter(); + + /** + * @return the instance + */ + public static ContainerInfoConverter getInstance() + { + return instance; + } + + /** + * @param instance + * the instance to set + */ + public static void setInstance(ContainerInfoConverter instance) + { + ContainerInfoConverter.instance = instance; + } + + /** + * Converts the container information of a {@link InternalCDORevision} to a String representation. The container + * information is the container id ({@link InternalCDORevision#getContainerID()} and the containingFeatureID ( + * {@link InternalCDORevision#getContainingFeatureID()}). + * + * @param cdoRevision + * the InternalCDORevision which has the container information + * @return a String representation of the container information which can be stored in a single varchar in the + * database. + */ + public String convertContainerRelationToString(InternalCDORevision cdoRevision) + { + return convertContainerRelationToString(cdoRevision, (CDOID)cdoRevision.getContainerID()); + } + + /** + * Converts the container information of a {@link InternalCDORevision} to a String representation. The container + * information is the container id ({@link InternalCDORevision#getContainerID()} and the containingFeatureID ( + * {@link InternalCDORevision#getContainingFeatureID()}). + * + * @param cdoRevision + * the InternalCDORevision which has the container information + * @param containerID + * the CDOID of the container + * @return a String representation of the container information which can be stored in a single varchar in the + * database. + */ + public String convertContainerRelationToString(InternalCDORevision cdoRevision, CDOID containerID) + { + if (containerID == null || containerID.isNull() || containerID.isTemporary()) + { + return null; + } + + final String strCDOID = HibernateUtil.getInstance().convertCDOIDToString(containerID); + if (!HibernateUtil.getInstance().isStoreCreatedID(containerID)) + { + // does not support changing models.... + return strCDOID + SEPARATOR + cdoRevision.getContainingFeatureID(); + } + + // get the feature name... + if (cdoRevision.getContainingFeatureID() < 0) + { + final String entityName = HibernateUtil.getInstance().getEntityName(containerID); + final HibernateStore store = HibernateThreadContext.getCurrentStoreAccessor().getStore(); + final EClass containerEClass = store.getEClass(entityName); + final int featureID = InternalEObject.EOPPOSITE_FEATURE_BASE - cdoRevision.getContainingFeatureID(); + final EStructuralFeature eFeature = containerEClass.getEStructuralFeature(featureID); + return strCDOID + SEPARATOR + "-" + eFeature.getName(); //$NON-NLS-1$ + } + + final EClass eContainedEClass = cdoRevision.getEClass(); + final EStructuralFeature eFeature = eContainedEClass.getEStructuralFeature(cdoRevision.getContainingFeatureID()); + return strCDOID + SEPARATOR + eFeature.getName(); + } + + /** + * Converts the String generated by the method {@link #convertContainerRelationToString(InternalCDORevision)} back to + * container information and sets this in the cdoRevision. + * + * @param cdoRevision + * the InternalCDORevision in which the container info is stored. + * @param containerInfo + * the containerInfo coded as a String + */ + public void setContainerRelationFromString(InternalCDORevision cdoRevision, String containerInfo) + { + if (containerInfo == null) + { + return; + } + + final int index = containerInfo.lastIndexOf(SEPARATOR); + if (index == -1) + { + // TODO: error condition? + return; + } + + // get/set the container id + final CDOID containerID = HibernateUtil.getInstance().convertStringToCDOID(containerInfo.substring(0, index)); + cdoRevision.setContainerID(containerID); + + final String containerFeatureStr = containerInfo.substring(index + SEPARATOR.length()); + if (containerID instanceof CDOIDExternal) + { + cdoRevision.setContainingFeatureID(Integer.parseInt(containerFeatureStr)); + return; + } + + if (containerFeatureStr.startsWith(CONTAINER_PREFIX)) + { + // part of the container eClass + final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(containerID); + if (classifierRef == null) + { + throw new IllegalArgumentException("This CDOID type of " + containerID + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + final EClass containerEClass = HibernateUtil.getInstance().getEClass(classifierRef); + + // substring 1 because the string starts with a minus + final EStructuralFeature eFeature = containerEClass.getEStructuralFeature(containerFeatureStr.substring(1)); + final int containerFeatureID = InternalEObject.EOPPOSITE_FEATURE_BASE - containerEClass.getFeatureID(eFeature); + cdoRevision.setContainingFeatureID(containerFeatureID); + return; + } + + final EClass eContainedEClass = cdoRevision.getEClass(); + final EStructuralFeature eFeature = eContainedEClass.getEStructuralFeature(containerFeatureStr); + cdoRevision.setContainingFeatureID(eContainedEClass.getFeatureID(eFeature)); + return; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProvider.java index c9d4f0fc3f..f94556c92d 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProvider.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProvider.java @@ -1,76 +1,76 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
-
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-/**
- * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration.
- *
- * @author Martin Taal
- */
-public class FileHibernateMappingProvider extends HibernateMappingProvider
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, FileHibernateMappingProvider.class);
-
- private final String mappingFileLocation;
-
- public FileHibernateMappingProvider(String mappingFileLocation)
- {
- if (mappingFileLocation == null || mappingFileLocation.length() == 0)
- {
- throw new IllegalArgumentException("mappingFileLocation"); //$NON-NLS-1$
- }
-
- this.mappingFileLocation = mappingFileLocation;
- }
-
- public String getMapping()
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Adding hibernate mapping from location(s): " + mappingFileLocation); //$NON-NLS-1$
- }
-
- InputStream is = null;
-
- try
- {
- is = getClass().getResourceAsStream(mappingFileLocation);
-
- StringBuilder sb = new StringBuilder();
- String line;
- BufferedReader reader = new BufferedReader(new InputStreamReader(is, CDOHibernateConstants.UTF8));
- while ((line = reader.readLine()) != null)
- {
- sb.append(line).append(CDOHibernateConstants.NL);
- }
- return sb.toString();
- }
- catch (Exception e)
- {
- throw WrappedException.wrap(e);
- }
- finally
- {
- IOUtil.close(is);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM; + +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.io.IOUtil; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +/** + * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration. + * + * @author Martin Taal + */ +public class FileHibernateMappingProvider extends HibernateMappingProvider +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, FileHibernateMappingProvider.class); + + private final String mappingFileLocation; + + public FileHibernateMappingProvider(String mappingFileLocation) + { + if (mappingFileLocation == null || mappingFileLocation.length() == 0) + { + throw new IllegalArgumentException("mappingFileLocation"); //$NON-NLS-1$ + } + + this.mappingFileLocation = mappingFileLocation; + } + + public String getMapping() + { + if (TRACER.isEnabled()) + { + TRACER.trace("Adding hibernate mapping from location(s): " + mappingFileLocation); //$NON-NLS-1$ + } + + InputStream is = null; + + try + { + is = getClass().getResourceAsStream(mappingFileLocation); + + StringBuilder sb = new StringBuilder(); + String line; + BufferedReader reader = new BufferedReader(new InputStreamReader(is, CDOHibernateConstants.UTF8)); + while ((line = reader.readLine()) != null) + { + sb.append(line).append(CDOHibernateConstants.NL); + } + return sb.toString(); + } + catch (Exception e) + { + throw WrappedException.wrap(e); + } + finally + { + IOUtil.close(is); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java index 592efafd15..cbe463a4bf 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/FileHibernateMappingProviderFactory.java @@ -1,61 +1,61 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
-
-import org.eclipse.net4j.util.StringUtil;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-/**
- * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration.
- *
- * @author Martin Taal
- */
-public class FileHibernateMappingProviderFactory implements IHibernateMappingProvider.Factory
-{
- public static final String TYPE = "file"; //$NON-NLS-1$
-
- private static final String FILE_ELEMENT_TAG_NAME = "mappingFile"; //$NON-NLS-1$
-
- private static final String LOCATION_ATTRIBUTE_NAME = "location"; //$NON-NLS-1$
-
- public FileHibernateMappingProviderFactory()
- {
- }
-
- public String getType()
- {
- return TYPE;
- }
-
- public FileHibernateMappingProvider create(Element config)
- {
- NodeList mappingFileConfigs = config.getElementsByTagName(FILE_ELEMENT_TAG_NAME);
- if (mappingFileConfigs.getLength() != 1)
- {
- throw new IllegalArgumentException(
- "Zero or More than one mapping file location specified, only one location is supported."); //$NON-NLS-1$
- }
-
- final Element mappingFile = (Element)mappingFileConfigs.item(0);
- final String location = mappingFile.getAttribute(LOCATION_ATTRIBUTE_NAME);
- if (StringUtil.isEmpty(location))
- {
- throw new IllegalArgumentException("Mapping file location is empty"); //$NON-NLS-1$
- }
-
- return new FileHibernateMappingProvider(location);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider; + +import org.eclipse.net4j.util.StringUtil; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * Reads the hibernate mapping file from one or more resource locations and adds them to the configuration. + * + * @author Martin Taal + */ +public class FileHibernateMappingProviderFactory implements IHibernateMappingProvider.Factory +{ + public static final String TYPE = "file"; //$NON-NLS-1$ + + private static final String FILE_ELEMENT_TAG_NAME = "mappingFile"; //$NON-NLS-1$ + + private static final String LOCATION_ATTRIBUTE_NAME = "location"; //$NON-NLS-1$ + + public FileHibernateMappingProviderFactory() + { + } + + public String getType() + { + return TYPE; + } + + public FileHibernateMappingProvider create(Element config) + { + NodeList mappingFileConfigs = config.getElementsByTagName(FILE_ELEMENT_TAG_NAME); + if (mappingFileConfigs.getLength() != 1) + { + throw new IllegalArgumentException( + "Zero or More than one mapping file location specified, only one location is supported."); //$NON-NLS-1$ + } + + final Element mappingFile = (Element)mappingFileConfigs.item(0); + final String location = mappingFile.getAttribute(LOCATION_ATTRIBUTE_NAME); + if (StringUtil.isEmpty(location)) + { + throw new IllegalArgumentException("Mapping file location is empty"); //$NON-NLS-1$ + } + + return new FileHibernateMappingProvider(location); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCommitContext.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCommitContext.java index 46bcc52c40..0d831599e6 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCommitContext.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCommitContext.java @@ -1,97 +1,97 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-
-import java.util.HashMap;
-
-/**
- * A HibernateCommitContext contains the commitcontext as well as support for direct (hashmap) based search for a new or
- * changed object using the id.
- *
- * @author Martin Taal
- */
-public class HibernateCommitContext
-{
- private InternalCommitContext commitContext;
-
- private HashMap<CDOID, InternalCDORevision> dirtyObjects;
-
- private HashMap<CDOID, InternalCDORevision> newObjects;
-
- public InternalCommitContext getCommitContext()
- {
- return commitContext;
- }
-
- public void setCommitContext(InternalCommitContext commitContext)
- {
- this.commitContext = commitContext;
- }
-
- // initialize is not done when the commitContext is set because it appeared
- // that at that moment the temp id's are not repaired. The initialize method
- // is called on demand.
- protected void initialize()
- {
- if (dirtyObjects != null)
- {
- return;
- }
-
- dirtyObjects = new HashMap<CDOID, InternalCDORevision>();
- for (InternalCDORevision cdoRevision : commitContext.getDirtyObjects())
- {
- dirtyObjects.put(cdoRevision.getID(), cdoRevision);
- }
-
- newObjects = new HashMap<CDOID, InternalCDORevision>();
- for (InternalCDORevision cdoRevision : commitContext.getNewObjects())
- {
- newObjects.put(cdoRevision.getID(), cdoRevision);
- }
- }
-
- public InternalCDORevision getDirtyObject(CDOID id)
- {
- initialize();
- return dirtyObjects.get(id);
- }
-
- public InternalCDORevision getNewObject(CDOID id)
- {
- initialize();
- return newObjects.get(id);
- }
-
- public void setNewID(CDOID oldId, CDOID newId)
- {
- initialize();
- InternalCDORevision cdoRevision;
- if ((cdoRevision = dirtyObjects.get(oldId)) != null)
- {
- dirtyObjects.remove(oldId);
- dirtyObjects.put(newId, cdoRevision);
- return;
- }
-
- if ((cdoRevision = newObjects.get(oldId)) != null)
- {
- newObjects.remove(oldId);
- newObjects.put(newId, cdoRevision);
- return;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.spi.server.InternalCommitContext; + +import java.util.HashMap; + +/** + * A HibernateCommitContext contains the commitcontext as well as support for direct (hashmap) based search for a new or + * changed object using the id. + * + * @author Martin Taal + */ +public class HibernateCommitContext +{ + private InternalCommitContext commitContext; + + private HashMap<CDOID, InternalCDORevision> dirtyObjects; + + private HashMap<CDOID, InternalCDORevision> newObjects; + + public InternalCommitContext getCommitContext() + { + return commitContext; + } + + public void setCommitContext(InternalCommitContext commitContext) + { + this.commitContext = commitContext; + } + + // initialize is not done when the commitContext is set because it appeared + // that at that moment the temp id's are not repaired. The initialize method + // is called on demand. + protected void initialize() + { + if (dirtyObjects != null) + { + return; + } + + dirtyObjects = new HashMap<CDOID, InternalCDORevision>(); + for (InternalCDORevision cdoRevision : commitContext.getDirtyObjects()) + { + dirtyObjects.put(cdoRevision.getID(), cdoRevision); + } + + newObjects = new HashMap<CDOID, InternalCDORevision>(); + for (InternalCDORevision cdoRevision : commitContext.getNewObjects()) + { + newObjects.put(cdoRevision.getID(), cdoRevision); + } + } + + public InternalCDORevision getDirtyObject(CDOID id) + { + initialize(); + return dirtyObjects.get(id); + } + + public InternalCDORevision getNewObject(CDOID id) + { + initialize(); + return newObjects.get(id); + } + + public void setNewID(CDOID oldId, CDOID newId) + { + initialize(); + InternalCDORevision cdoRevision; + if ((cdoRevision = dirtyObjects.get(oldId)) != null) + { + dirtyObjects.remove(oldId); + dirtyObjects.put(newId, cdoRevision); + return; + } + + if ((cdoRevision = newObjects.get(oldId)) != null) + { + newObjects.remove(oldId); + newObjects.put(newId, cdoRevision); + return; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java index ecb511ea27..967e6030bd 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateMappingProvider.java @@ -1,47 +1,47 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
-
-/**
- * @author Eike Stepper
- */
-public abstract class HibernateMappingProvider implements IHibernateMappingProvider
-{
- private IHibernateStore hibernateStore;
-
- public HibernateMappingProvider()
- {
- }
-
- /**
- * @return the hibernate store, never <code>null</code>.
- * @throws IllegalStateException
- * if the hibernate store is <code>null</code>.
- */
- public IHibernateStore getHibernateStore()
- {
- if (hibernateStore == null)
- {
- throw new IllegalStateException("hibernateStore is null"); //$NON-NLS-1$
- }
-
- return hibernateStore;
- }
-
- public void setHibernateStore(IHibernateStore hibernateStore)
- {
- this.hibernateStore = hibernateStore;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider; +import org.eclipse.emf.cdo.server.hibernate.IHibernateStore; + +/** + * @author Eike Stepper + */ +public abstract class HibernateMappingProvider implements IHibernateMappingProvider +{ + private IHibernateStore hibernateStore; + + public HibernateMappingProvider() + { + } + + /** + * @return the hibernate store, never <code>null</code>. + * @throws IllegalStateException + * if the hibernate store is <code>null</code>. + */ + public IHibernateStore getHibernateStore() + { + if (hibernateStore == null) + { + throw new IllegalStateException("hibernateStore is null"); //$NON-NLS-1$ + } + + return hibernateStore; + } + + public void setHibernateStore(IHibernateStore hibernateStore) + { + this.hibernateStore = hibernateStore; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java index 0b93eb79a0..4e1a649e34 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateQueryHandler.java @@ -1,212 +1,212 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
-import org.eclipse.emf.cdo.server.IQueryContext;
-import org.eclipse.emf.cdo.server.IQueryHandler;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
-import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.WrappedHibernateList;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import org.hibernate.Hibernate;
-import org.hibernate.Query;
-import org.hibernate.Session;
-
-import java.io.Serializable;
-
-/**
- * Implements server side HQL query execution..
- *
- * @author Martin Taal
- */
-public class HibernateQueryHandler implements IQueryHandler
-{
- /**
- * @deprecated use {@link IHibernateStore#QUERY_LANGUAGE}
- */
- @Deprecated
- public static final String QUERY_LANGUAGE = IHibernateStore.QUERY_LANGUAGE;
-
- /**
- * @deprecated use {@link IHibernateStore#FIRST_RESULT}
- */
- @Deprecated
- public static final String FIRST_RESULT = IHibernateStore.FIRST_RESULT;
-
- private HibernateStoreAccessor hibernateStoreAccessor;
-
- /**
- * Executes hql queries. Gets the session from the {@link HibernateStoreAccessor} creates a hibernate query and sets
- * the parameters taken from the {@link CDOQueryInfo#getParameters()}. Takes into account the
- * {@link CDOQueryInfo#getMaxResults()} and the {@link IHibernateStore#FIRST_RESULT} values for paging.
- *
- * @param info
- * the object containing the query and parameters
- * @param context
- * the query results are placed in the context
- * @see IQueryHandler#executeQuery(CDOQueryInfo, IQueryContext)
- */
- public void executeQuery(CDOQueryInfo info, IQueryContext context)
- {
- // get a transaction, the hibernateStoreAccessor is placed in a threadlocal
- // so all db access uses the same session.
- final Session session = hibernateStoreAccessor.getHibernateSession();
-
- // create the query
- final Query query = session.createQuery(info.getQueryString());
-
- // get the parameters with some parameter conversion
- int firstResult = -1;
- boolean cacheResults = true;
- for (String key : info.getParameters().keySet())
- {
- if (key.compareToIgnoreCase(IHibernateStore.CACHE_RESULTS) == 0)
- {
- try
- {
- cacheResults = (Boolean)info.getParameters().get(key);
- }
- catch (ClassCastException e)
- {
- throw new IllegalArgumentException(
- "Parameter " + IHibernateStore.CACHE_RESULTS + " must be a boolean. errorMessage " + e.getMessage()); //$NON-NLS-1$
- }
- }
- else if (key.compareToIgnoreCase(IHibernateStore.FIRST_RESULT) == 0)
- {
- final Object o = info.getParameters().get(key);
- if (o != null)
- {
- try
- {
- firstResult = (Integer)o;
- }
- catch (ClassCastException e)
- {
- throw new IllegalArgumentException("Parameter firstResult must be an integer but it is a " + o //$NON-NLS-1$
- + " class " + o.getClass().getName()); //$NON-NLS-1$
- }
- }
- }
- else
- {
- // in case the parameter is a CDOID get the object from the db
- final Object param = info.getParameters().get(key);
- if (param instanceof CDOID && HibernateUtil.getInstance().isStoreCreatedID((CDOID)param))
- {
- final CDOID id = (CDOID)param;
- final String entityName = HibernateUtil.getInstance().getEntityName(id);
- final Serializable idValue = HibernateUtil.getInstance().getIdValue(id);
- final CDORevision revision = (CDORevision)session.get(entityName, idValue);
- query.setEntity(key, revision);
- if (cacheResults)
- {
- addToRevisionCache(revision);
- }
- }
- else
- {
- query.setParameter(key, param);
- }
- }
- }
-
- // set the first result
- if (firstResult > -1)
- {
- query.setFirstResult(firstResult);
- }
-
- // the max result
- if (info.getMaxResults() != CDOQueryInfo.UNLIMITED_RESULTS)
- {
- query.setMaxResults(info.getMaxResults());
- }
-
- // and go for the query
- // future extension: support iterate, scroll through a parameter
- for (Object o : query.list())
- {
- final boolean addOneMore = context.addResult(o);
- if (cacheResults && o instanceof CDORevision)
- {
- addToRevisionCache((CDORevision)o);
- }
-
- if (!addOneMore)
- {
- return;
- }
- }
- }
-
- private void addToRevisionCache(CDORevision revision)
- {
- final InternalCDORevision internalRevision = (InternalCDORevision)revision;
- for (EStructuralFeature feature : revision.getEClass().getEAllStructuralFeatures())
- {
- if (!isMappedFeature(internalRevision, feature))
- {
- continue;
- }
-
- if (feature.isMany() || feature instanceof EReference)
- {
- final Object value = internalRevision.getValue(feature);
- if (value instanceof WrappedHibernateList)
- {
- Hibernate.initialize(((WrappedHibernateList)value).getDelegate());
- }
- else
- {
- Hibernate.initialize(value);
- }
- }
- }
-
- hibernateStoreAccessor.addToRevisionCache(revision);
- }
-
- private boolean isMappedFeature(InternalCDORevision revision, EStructuralFeature feature)
- {
- try
- {
- int featureID = revision.getClassInfo().getEClass().getFeatureID(feature);
- revision.getClassInfo().getFeatureIndex(featureID);
- return true;
- }
- catch (IllegalArgumentException ex)
- {
- return false;
- }
- catch (ArrayIndexOutOfBoundsException ex)
- {
- return false;
- }
- }
-
- public HibernateStoreAccessor getHibernateStoreAccessor()
- {
- return hibernateStoreAccessor;
- }
-
- public void setHibernateStoreAccessor(HibernateStoreAccessor hibernateStoreAccessor)
- {
- this.hibernateStoreAccessor = hibernateStoreAccessor;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.util.CDOQueryInfo; +import org.eclipse.emf.cdo.server.IQueryContext; +import org.eclipse.emf.cdo.server.IQueryHandler; +import org.eclipse.emf.cdo.server.hibernate.IHibernateStore; +import org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.WrappedHibernateList; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +import org.hibernate.Hibernate; +import org.hibernate.Query; +import org.hibernate.Session; + +import java.io.Serializable; + +/** + * Implements server side HQL query execution.. + * + * @author Martin Taal + */ +public class HibernateQueryHandler implements IQueryHandler +{ + /** + * @deprecated use {@link IHibernateStore#QUERY_LANGUAGE} + */ + @Deprecated + public static final String QUERY_LANGUAGE = IHibernateStore.QUERY_LANGUAGE; + + /** + * @deprecated use {@link IHibernateStore#FIRST_RESULT} + */ + @Deprecated + public static final String FIRST_RESULT = IHibernateStore.FIRST_RESULT; + + private HibernateStoreAccessor hibernateStoreAccessor; + + /** + * Executes hql queries. Gets the session from the {@link HibernateStoreAccessor} creates a hibernate query and sets + * the parameters taken from the {@link CDOQueryInfo#getParameters()}. Takes into account the + * {@link CDOQueryInfo#getMaxResults()} and the {@link IHibernateStore#FIRST_RESULT} values for paging. + * + * @param info + * the object containing the query and parameters + * @param context + * the query results are placed in the context + * @see IQueryHandler#executeQuery(CDOQueryInfo, IQueryContext) + */ + public void executeQuery(CDOQueryInfo info, IQueryContext context) + { + // get a transaction, the hibernateStoreAccessor is placed in a threadlocal + // so all db access uses the same session. + final Session session = hibernateStoreAccessor.getHibernateSession(); + + // create the query + final Query query = session.createQuery(info.getQueryString()); + + // get the parameters with some parameter conversion + int firstResult = -1; + boolean cacheResults = true; + for (String key : info.getParameters().keySet()) + { + if (key.compareToIgnoreCase(IHibernateStore.CACHE_RESULTS) == 0) + { + try + { + cacheResults = (Boolean)info.getParameters().get(key); + } + catch (ClassCastException e) + { + throw new IllegalArgumentException( + "Parameter " + IHibernateStore.CACHE_RESULTS + " must be a boolean. errorMessage " + e.getMessage()); //$NON-NLS-1$ + } + } + else if (key.compareToIgnoreCase(IHibernateStore.FIRST_RESULT) == 0) + { + final Object o = info.getParameters().get(key); + if (o != null) + { + try + { + firstResult = (Integer)o; + } + catch (ClassCastException e) + { + throw new IllegalArgumentException("Parameter firstResult must be an integer but it is a " + o //$NON-NLS-1$ + + " class " + o.getClass().getName()); //$NON-NLS-1$ + } + } + } + else + { + // in case the parameter is a CDOID get the object from the db + final Object param = info.getParameters().get(key); + if (param instanceof CDOID && HibernateUtil.getInstance().isStoreCreatedID((CDOID)param)) + { + final CDOID id = (CDOID)param; + final String entityName = HibernateUtil.getInstance().getEntityName(id); + final Serializable idValue = HibernateUtil.getInstance().getIdValue(id); + final CDORevision revision = (CDORevision)session.get(entityName, idValue); + query.setEntity(key, revision); + if (cacheResults) + { + addToRevisionCache(revision); + } + } + else + { + query.setParameter(key, param); + } + } + } + + // set the first result + if (firstResult > -1) + { + query.setFirstResult(firstResult); + } + + // the max result + if (info.getMaxResults() != CDOQueryInfo.UNLIMITED_RESULTS) + { + query.setMaxResults(info.getMaxResults()); + } + + // and go for the query + // future extension: support iterate, scroll through a parameter + for (Object o : query.list()) + { + final boolean addOneMore = context.addResult(o); + if (cacheResults && o instanceof CDORevision) + { + addToRevisionCache((CDORevision)o); + } + + if (!addOneMore) + { + return; + } + } + } + + private void addToRevisionCache(CDORevision revision) + { + final InternalCDORevision internalRevision = (InternalCDORevision)revision; + for (EStructuralFeature feature : revision.getEClass().getEAllStructuralFeatures()) + { + if (!isMappedFeature(internalRevision, feature)) + { + continue; + } + + if (feature.isMany() || feature instanceof EReference) + { + final Object value = internalRevision.getValue(feature); + if (value instanceof WrappedHibernateList) + { + Hibernate.initialize(((WrappedHibernateList)value).getDelegate()); + } + else + { + Hibernate.initialize(value); + } + } + } + + hibernateStoreAccessor.addToRevisionCache(revision); + } + + private boolean isMappedFeature(InternalCDORevision revision, EStructuralFeature feature) + { + try + { + int featureID = revision.getClassInfo().getEClass().getFeatureID(feature); + revision.getClassInfo().getFeatureIndex(featureID); + return true; + } + catch (IllegalArgumentException ex) + { + return false; + } + catch (ArrayIndexOutOfBoundsException ex) + { + return false; + } + } + + public HibernateStoreAccessor getHibernateStoreAccessor() + { + return hibernateStoreAccessor; + } + + public void setHibernateStoreAccessor(HibernateStoreAccessor hibernateStoreAccessor) + { + this.hibernateStoreAccessor = hibernateStoreAccessor; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java index 90affa120f..c233466a54 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreChunkReader.java @@ -1,55 +1,55 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateStoreChunkReader;
-import org.eclipse.emf.cdo.spi.server.StoreChunkReader;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public class HibernateStoreChunkReader extends StoreChunkReader implements IHibernateStoreChunkReader
-{
- public HibernateStoreChunkReader(HibernateStoreAccessor accessor, CDORevision revision, EStructuralFeature feature)
- {
- super(accessor, revision, feature);
- }
-
- @Override
- public HibernateStoreAccessor getAccessor()
- {
- return (HibernateStoreAccessor)super.getAccessor();
- }
-
- @Override
- public void addSimpleChunk(int index)
- {
- // super.addSimpleChunk(index);
- throw new UnsupportedOperationException(); // TODO Implement me
- }
-
- @Override
- public void addRangedChunk(int fromIndex, int toIndex)
- {
- // super.addRangedChunk(fromIndex, toIndex);
- throw new UnsupportedOperationException(); // TODO Implement me
- }
-
- public List<Chunk> executeRead()
- {
- throw new UnsupportedOperationException(); // TODO Implement me
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate; + +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.hibernate.IHibernateStoreChunkReader; +import org.eclipse.emf.cdo.spi.server.StoreChunkReader; + +import org.eclipse.emf.ecore.EStructuralFeature; + +import java.util.List; + +/** + * @author Eike Stepper + */ +public class HibernateStoreChunkReader extends StoreChunkReader implements IHibernateStoreChunkReader +{ + public HibernateStoreChunkReader(HibernateStoreAccessor accessor, CDORevision revision, EStructuralFeature feature) + { + super(accessor, revision, feature); + } + + @Override + public HibernateStoreAccessor getAccessor() + { + return (HibernateStoreAccessor)super.getAccessor(); + } + + @Override + public void addSimpleChunk(int index) + { + // super.addSimpleChunk(index); + throw new UnsupportedOperationException(); // TODO Implement me + } + + @Override + public void addRangedChunk(int fromIndex, int toIndex) + { + // super.addRangedChunk(fromIndex, toIndex); + throw new UnsupportedOperationException(); // TODO Implement me + } + + public List<Chunk> executeRead() + { + throw new UnsupportedOperationException(); // TODO Implement me + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java index 91a925bc31..13b543d6e1 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreFactory.java @@ -1,88 +1,88 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreFactory;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author Eike Stepper
- */
-public class HibernateStoreFactory implements IStoreFactory
-{
- private static final String PROPERTY_TAG = "property"; //$NON-NLS-1$
-
- private static final String MAPPINGPROVIDER_TAG = "mappingProvider"; //$NON-NLS-1$
-
- private static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
-
- private static final String VALUE_ATTRIBUTE = "value"; //$NON-NLS-1$
-
- private static final String TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$
-
- public HibernateStoreFactory()
- {
- }
-
- public String getStoreType()
- {
- return HibernateStore.TYPE;
- }
-
- public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig)
- {
- final IHibernateMappingProvider mappingProvider = getMappingProvider(storeConfig);
-
- final Properties properties = new Properties();
- final NodeList propertyNodes = storeConfig.getElementsByTagName(PROPERTY_TAG);
- for (int i = 0; i < propertyNodes.getLength(); i++)
- {
- final Element propertyElement = (Element)propertyNodes.item(i);
- properties.setProperty(propertyElement.getAttribute(NAME_ATTRIBUTE),
- propertyElement.getAttribute(VALUE_ATTRIBUTE));
- }
-
- return HibernateUtil.getInstance().createStore(mappingProvider, properties);
- }
-
- private IHibernateMappingProvider getMappingProvider(Element storeConfig)
- {
- NodeList mappingProviderConfigs = storeConfig.getElementsByTagName(MAPPINGPROVIDER_TAG);
- if (mappingProviderConfigs.getLength() != 1)
- {
- throw new IllegalStateException("Exactly one mapping provider must be configured for Hibernate store"); //$NON-NLS-1$
- }
-
- Element mappingProviderConfig = (Element)mappingProviderConfigs.item(0);
- String mappingProviderType = mappingProviderConfig.getAttribute(TYPE_ATTRIBUTE);
- IHibernateMappingProvider.Factory factory = HibernateUtil.getInstance().createMappingProviderFactory(
- mappingProviderType);
- if (factory == null)
- {
- throw new IllegalArgumentException("Unknown mapping provider type: " + mappingProviderType); //$NON-NLS-1$
- }
-
- IHibernateMappingProvider mappingProvider = factory.create(mappingProviderConfig);
- if (mappingProvider == null)
- {
- throw new IllegalArgumentException("No mapping provider created: " + mappingProviderType); //$NON-NLS-1$
- }
-
- return mappingProvider;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate; + +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.IStoreFactory; +import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import java.util.Map; +import java.util.Properties; + +/** + * @author Eike Stepper + */ +public class HibernateStoreFactory implements IStoreFactory +{ + private static final String PROPERTY_TAG = "property"; //$NON-NLS-1$ + + private static final String MAPPINGPROVIDER_TAG = "mappingProvider"; //$NON-NLS-1$ + + private static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$ + + private static final String VALUE_ATTRIBUTE = "value"; //$NON-NLS-1$ + + private static final String TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$ + + public HibernateStoreFactory() + { + } + + public String getStoreType() + { + return HibernateStore.TYPE; + } + + public IStore createStore(String repositoryName, Map<String, String> repositoryProperties, Element storeConfig) + { + final IHibernateMappingProvider mappingProvider = getMappingProvider(storeConfig); + + final Properties properties = new Properties(); + final NodeList propertyNodes = storeConfig.getElementsByTagName(PROPERTY_TAG); + for (int i = 0; i < propertyNodes.getLength(); i++) + { + final Element propertyElement = (Element)propertyNodes.item(i); + properties.setProperty(propertyElement.getAttribute(NAME_ATTRIBUTE), + propertyElement.getAttribute(VALUE_ATTRIBUTE)); + } + + return HibernateUtil.getInstance().createStore(mappingProvider, properties); + } + + private IHibernateMappingProvider getMappingProvider(Element storeConfig) + { + NodeList mappingProviderConfigs = storeConfig.getElementsByTagName(MAPPINGPROVIDER_TAG); + if (mappingProviderConfigs.getLength() != 1) + { + throw new IllegalStateException("Exactly one mapping provider must be configured for Hibernate store"); //$NON-NLS-1$ + } + + Element mappingProviderConfig = (Element)mappingProviderConfigs.item(0); + String mappingProviderType = mappingProviderConfig.getAttribute(TYPE_ATTRIBUTE); + IHibernateMappingProvider.Factory factory = HibernateUtil.getInstance().createMappingProviderFactory( + mappingProviderType); + if (factory == null) + { + throw new IllegalArgumentException("Unknown mapping provider type: " + mappingProviderType); //$NON-NLS-1$ + } + + IHibernateMappingProvider mappingProvider = factory.create(mappingProviderConfig); + if (mappingProvider == null) + { + throw new IllegalArgumentException("No mapping provider created: " + mappingProviderType); //$NON-NLS-1$ + } + + return mappingProvider; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreLob.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreLob.java index 59de44e7b0..b6de9e278f 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreLob.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreLob.java @@ -1,79 +1,79 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import java.sql.Blob;
-import java.sql.Clob;
-
-/**
- * Object used to store clob and lob.
- *
- * @author Martin Taal
- */
-public class HibernateStoreLob
-{
- // note size -1 is used to flag a new state
- private static int NEW_FLAG_SIZE = -1;
-
- private String id;
-
- private Clob clob;
-
- private Blob blob;
-
- private int size = NEW_FLAG_SIZE;
-
- public boolean isNew()
- {
- return size == NEW_FLAG_SIZE;
- }
-
- public int getSize()
- {
- return size;
- }
-
- public void setSize(int size)
- {
- this.size = size;
- }
-
- public String getId()
- {
- return id;
- }
-
- public void setId(String id)
- {
- this.id = id;
- }
-
- public Clob getClob()
- {
- return clob;
- }
-
- public void setClob(Clob clob)
- {
- this.clob = clob;
- }
-
- public Blob getBlob()
- {
- return blob;
- }
-
- public void setBlob(Blob blob)
- {
- this.blob = blob;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import java.sql.Blob; +import java.sql.Clob; + +/** + * Object used to store clob and lob. + * + * @author Martin Taal + */ +public class HibernateStoreLob +{ + // note size -1 is used to flag a new state + private static int NEW_FLAG_SIZE = -1; + + private String id; + + private Clob clob; + + private Blob blob; + + private int size = NEW_FLAG_SIZE; + + public boolean isNew() + { + return size == NEW_FLAG_SIZE; + } + + public int getSize() + { + return size; + } + + public void setSize(int size) + { + this.size = size; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public Clob getClob() + { + return clob; + } + + public void setClob(Clob clob) + { + this.clob = clob; + } + + public Blob getBlob() + { + return blob; + } + + public void setBlob(Blob blob) + { + this.blob = blob; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java index 5f1dab0322..5636773854 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateThreadContext.java @@ -1,82 +1,82 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
-import org.eclipse.emf.cdo.spi.server.InternalCommitContext;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-/**
- * @author Martin Taal
- */
-public class HibernateThreadContext
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HibernateThreadContext.class);
-
- private static ThreadLocal<HibernateCommitContext> commitContext = new ThreadLocal<HibernateCommitContext>();
-
- public static HibernateStoreAccessor getCurrentStoreAccessor()
- {
- return (HibernateStoreAccessor)StoreThreadLocal.getAccessor();
- }
-
- public static HibernateCommitContext getCommitContext()
- {
- HibernateCommitContext result = commitContext.get();
- if (result == null)
- {
- throw new IllegalStateException("CommitContext not set"); //$NON-NLS-1$
- }
-
- return result;
- }
-
- public static boolean isCommitContextSet()
- {
- return commitContext.get() != null;
- }
-
- public static void setCommitContext(InternalCommitContext newCommitContext)
- {
- // in case of xa transactions then the commit context is set again
- // if (newCommitContext != null && commitContext.get() != null)
- // {
- // throw new IllegalStateException("CommitContext already set");
- // }
-
- if (TRACER.isEnabled())
- {
- if (newCommitContext == null)
- {
- TRACER.trace("Clearing commitcontext in threadlocal"); //$NON-NLS-1$
- }
- else
- {
- TRACER.trace("Setting commitcontext in threadlocal"); //$NON-NLS-1$
- }
- }
-
- // reset the context
- if (newCommitContext == null)
- {
- commitContext.set(null);
- }
- else
- {
- final HibernateCommitContext hcc = new HibernateCommitContext();
- hcc.setCommitContext(newCommitContext);
- commitContext.set(hcc);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.server.StoreThreadLocal; +import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM; +import org.eclipse.emf.cdo.spi.server.InternalCommitContext; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +/** + * @author Martin Taal + */ +public class HibernateThreadContext +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HibernateThreadContext.class); + + private static ThreadLocal<HibernateCommitContext> commitContext = new ThreadLocal<HibernateCommitContext>(); + + public static HibernateStoreAccessor getCurrentStoreAccessor() + { + return (HibernateStoreAccessor)StoreThreadLocal.getAccessor(); + } + + public static HibernateCommitContext getCommitContext() + { + HibernateCommitContext result = commitContext.get(); + if (result == null) + { + throw new IllegalStateException("CommitContext not set"); //$NON-NLS-1$ + } + + return result; + } + + public static boolean isCommitContextSet() + { + return commitContext.get() != null; + } + + public static void setCommitContext(InternalCommitContext newCommitContext) + { + // in case of xa transactions then the commit context is set again + // if (newCommitContext != null && commitContext.get() != null) + // { + // throw new IllegalStateException("CommitContext already set"); + // } + + if (TRACER.isEnabled()) + { + if (newCommitContext == null) + { + TRACER.trace("Clearing commitcontext in threadlocal"); //$NON-NLS-1$ + } + else + { + TRACER.trace("Setting commitcontext in threadlocal"); //$NON-NLS-1$ + } + } + + // reset the context + if (newCommitContext == null) + { + commitContext.set(null); + } + else + { + final HibernateCommitContext hcc = new HibernateCommitContext(); + hcc.setCommitContext(newCommitContext); + commitContext.set(hcc); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java index ea2766ee2d..8e53904e4e 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateUtil.java @@ -1,699 +1,699 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDExternal;
-import org.eclipse.emf.cdo.common.id.CDOIDTemp;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider;
-import org.eclipse.emf.cdo.server.hibernate.IHibernateStore;
-import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.id.AbstractCDOIDLong;
-import org.eclipse.emf.cdo.spi.common.id.AbstractCDOIDString;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-import org.eclipse.emf.cdo.util.CDOUtil;
-
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.WrappedException;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-
-import org.hibernate.Session;
-import org.hibernate.proxy.HibernateProxy;
-
-import javax.xml.datatype.DatatypeConfigurationException;
-import javax.xml.datatype.DatatypeFactory;
-import javax.xml.datatype.XMLGregorianCalendar;
-
-import java.io.Serializable;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Provides several utility and convenience methods. Mostly related to {@link CDOID} and {@link CDORevision}.
- *
- * @author Martin Taal
- */
-public class HibernateUtil
-{
- private static final String EXT_POINT = "mappingProviderFactories"; //$NON-NLS-1$
-
- private static HibernateUtil instance = new HibernateUtil();
-
- private static final String SEPARATOR = "_;_"; //$NON-NLS-1$
-
- private static final String MAPPING_PROVIDER_FACTORY_TAG = "mappingProviderFactory"; //$NON-NLS-1$
-
- private static final String TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$
-
- private static final String CLASS = "class"; //$NON-NLS-1$
-
- private static IHibernateMappingProvider.Factory mappingProviderFactoryInstance = null;
-
- public static IHibernateMappingProvider.Factory getMappingProviderFactoryInstance()
- {
- return mappingProviderFactoryInstance;
- }
-
- public static void setMappingProviderFactoryInstance(
- IHibernateMappingProvider.Factory theMappingProviderFactoryInstance)
- {
- mappingProviderFactoryInstance = theMappingProviderFactoryInstance;
- }
-
- /**
- * @return the global singleton instance
- */
- public static HibernateUtil getInstance()
- {
- return instance;
- }
-
- /**
- * Sets the singleton used by the Hibernate store.
- *
- * @param instance
- * the instance to set
- */
- public static void setInstance(HibernateUtil instance)
- {
- HibernateUtil.instance = instance;
- }
-
- // Local copy of the datatype factory
- private DatatypeFactory dataTypeFactory;
-
- public HibernateUtil()
- {
- try
- {
- dataTypeFactory = DatatypeFactory.newInstance();
- }
- catch (DatatypeConfigurationException ex)
- {
- throw new IllegalStateException("Exception ", ex);
- }
- }
-
- public DatatypeFactory getDataTypeFactory()
- {
- return dataTypeFactory;
- }
-
- public void setDataTypeFactory(DatatypeFactory dataTypeFactory)
- {
- this.dataTypeFactory = dataTypeFactory;
- }
-
- /**
- * Uses the repository package repository to find the EClass of the identified by the CDOClassifierRef.
- *
- * @param classifierRef
- * {@link CDOClassifierRef} which identifies an EClass
- * @return the EClass instance identified by the EPackage nsuri and classifier name in the CDOClassifierRef
- * @throws IllegalArgumentException
- * if the EClass can not be found
- * @see IRepository#getPackageRegistry()
- */
- public EClass getEClass(CDOClassifierRef classifierRef)
- {
- final CDOPackageRegistry registry = getPackageRegistry();
- final EPackage ePackage = registry.getEPackage(classifierRef.getPackageURI());
- if (ePackage == null)
- {
- throw new IllegalArgumentException("No EPackage found with nsuri " + classifierRef.getPackageURI()); //$NON-NLS-1$
- }
-
- final EClass eClass = (EClass)ePackage.getEClassifier(classifierRef.getClassifierName());
- if (eClass == null)
- {
- throw new IllegalArgumentException("No EClass " + classifierRef.getClassifierName() + " in EPackage " //$NON-NLS-1$ //$NON-NLS-2$
- + ePackage.getNsURI());
- }
-
- return eClass;
- }
-
- /**
- * @return the package registry as present in the repository
- * @see HibernateStore#getRepository()
- * @see IRepository#getPackageRegistry()
- */
- public CDOPackageRegistry getPackageRegistry()
- {
- final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor();
- return accessor.getStore().getRepository().getPackageRegistry();
- }
-
- /**
- * Creates an instance of {@link IHibernateStore}.
- *
- * @param mappingProvider
- * the provider which generates a mapping.
- * @param properties
- * hibernate and teneo properties combined
- * @return the created HibernateStore
- * @see HibernateStore
- * @since 2.0
- */
- public IHibernateStore createStore(IHibernateMappingProvider mappingProvider, Properties properties)
- {
- HibernateStore store = new HibernateStore(mappingProvider, properties);
- mappingProvider.setHibernateStore(store);
- return store;
- }
-
- /**
- * Can only be used when Eclipse is running. In standalone scenarios create the mapping strategy instance by directly
- * calling the constructor of the mapping strategy class.
- *
- * @see #createFileMappingProvider(String)
- * @since 2.0
- */
- public IHibernateMappingProvider.Factory createMappingProviderFactory(String type)
- {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- if (registry == null)
- {
- return getMappingProviderFactoryInstance();
- }
- IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT);
- for (final IConfigurationElement element : elements)
- {
- if (MAPPING_PROVIDER_FACTORY_TAG.equals(element.getName()))
- {
- String typeAttr = element.getAttribute(TYPE_ATTRIBUTE);
- if (ObjectUtil.equals(typeAttr, type))
- {
- try
- {
- return (IHibernateMappingProvider.Factory)element.createExecutableExtension(CLASS);
- }
- catch (CoreException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
- }
- }
-
- return getMappingProviderFactoryInstance();
- }
-
- /**
- * Creates a FileMappingProvider using the passed locations.
- *
- * @param location
- * the locations to load the mappings from
- * @return a {@link FileHibernateMappingProvider}
- * @since 3.0
- */
- public IHibernateMappingProvider createFileMappingProvider(String location)
- {
- return new FileHibernateMappingProvider(location);
- }
-
- /**
- * Retrieves the Hibernate Session from the current {@link HibernateStoreAccessor}. The current HibernateStoreAccessor
- * is maintained in the {@link HibernateThreadContext}.
- *
- * @return the current hibernate session, if none is there a new one is created and a transaction is started.
- * @since 2.0
- */
- public Session getHibernateSession()
- {
- final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor();
- return accessor.getHibernateSession();
- }
-
- /**
- * Convenience method to convert the properties of the {@link IStore#getRepository()} to a real java Properties
- * object.
- *
- * @param store
- * the properties of this store are converted to a real Properties object
- * @return a Properties object with the store properties
- */
- public Properties getPropertiesFromStore(IHibernateStore store)
- {
- final Properties props = new Properties();
-
- final Map<String, String> storeProps = store.getRepository().getProperties();
- for (String key : storeProps.keySet())
- {
- props.setProperty(key, storeProps.get(key));
- }
-
- return props;
- }
-
- /**
- * Checks if the object is a HibernateProxy. If so creates the CDOID without resolving the hibernate proxy. If it not
- * a proxy then the id is retrieved from the object itself. It is assumed to be a CDORevision then.
- */
- public CDOID getCDOID(Object o)
- {
- if (o instanceof HibernateProxy)
- {
- final Object idValue = ((HibernateProxy)o).getHibernateLazyInitializer().getIdentifier();
- final String entityName = ((HibernateProxy)o).getHibernateLazyInitializer().getEntityName();
- final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor();
- final EClass eClass = accessor.getStore().getEClass(entityName);
- return HibernateUtil.getInstance().createCDOID(new CDOClassifierRef(eClass), idValue);
- }
-
- return ((CDORevision)o).getID();
- }
-
- /**
- * Reads the entity name while taking account the fact that the object maybe a Hibernate proxy.
- */
- public String getEntityName(Object o)
- {
- if (o instanceof HibernateProxy)
- {
- return ((HibernateProxy)o).getHibernateLazyInitializer().getEntityName();
- }
-
- final EClass eClass = ((CDORevision)o).getEClass();
- final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor();
- return accessor.getStore().getEntityName(eClass);
- }
-
- /**
- * Deprecated method use: {@link HibernateStore#getEntityName(EClass)}.
- */
- @Deprecated
- public String getEntityName(CDORevision revision)
- {
- return HibernateThreadContext.getCurrentStoreAccessor().getStore().getEntityName(revision.getEClass());
- }
-
- /**
- * Converts a CDOID to an unique String representations. Null, {@link CDOIDTemp} and null CDOID's are returned as null
- * value. Supports {@link CDOID} and {@link CDOIDExternal}.
- *
- * @param id
- * the id to convert
- * @return a unique String
- */
- public String convertCDOIDToString(CDOID id)
- {
- if (id == null || id.isNull() || id.isTemporary())
- {
- return null;
- }
-
- final StringBuilder sb = new StringBuilder();
- CDOIDUtil.write(sb, id);
- return sb.toString();
- }
-
- /**
- * Converts a String back to its CDOID representation. The same types as in the {@link #convertCDOIDToString(CDOID)}
- * method are supported.
- *
- * @param strID
- * the String representation of the CDOID
- * @return a valid CDOID, can be null
- */
- public CDOID convertStringToCDOID(String strID)
- {
- if (strID == null)
- {
- return null;
- }
-
- return CDOIDUtil.read(strID);
- }
-
- /**
- * Translates a temporary {@link CDOID} into a hibernate ID, by finding the object it refers to in the
- * {@link CommitContext} and then returning or by persisting the object. Note assumes that the hibernate session and
- * CommitContext are set in HibernateThreadContext.
- *
- * @param id
- * the CDOID to translate to a valid id, if the id is already valid then it is returned.
- * @return the passed id or an instance of CDOID which is valid.
- */
- public CDOID getCDOIDHibernate(CDOID id)
- {
- if (isStoreCreatedID(id))
- {
- return id;
- }
-
- final CDORevision revision = getCDORevision(id);
- if (isStoreCreatedID(revision.getID()))
- {
- return revision.getID();
- }
-
- return getCDOIDHibernate(revision);
- }
-
- /**
- * Retrieves a {@link CDOID} from the passed CDORevision. If the revision has a non-supported CDOID then the revision
- * is saved to the database.
- *
- * @param revision
- * the revision to get the id from
- * @return a CDOID supported by this store
- */
- public CDOID getCDOIDHibernate(final CDORevision revision)
- {
- final Session session = getHibernateSession();
- if (!isStoreCreatedID(revision.getID()))
- {
- session.saveOrUpdate(revision);
- }
-
- checkIsSupportedID(revision.getID());
-
- return revision.getID();
- }
-
- /**
- * Retrieves the {@link InternalCDORevision} if the target is a {@link CDOObject} then the CDORevision is retrieved
- * using: {@link CDOObject#cdoRevision()}.
- *
- * @param target
- * the object which can be a CDOObject or an InternalCDORevision
- * @return the found {@link InternalCDORevision}
- */
- public InternalCDORevision getCDORevision(Object target)
- {
- if (target instanceof CDOObject)
- {
- return (InternalCDORevision)CDOUtil.getCDOObject((EObject)target).cdoRevision();
- }
- return (InternalCDORevision)target;
- }
-
- /**
- * Gets a current object, first checks the new and dirty objects from the {@link CommitContext}. Otherwise reads it
- * from the session.
- *
- * @param id
- * the {@link CDOID}, the {@link CDOIDTemp} is resolved against the CommitContext.
- * @return the retrieved {@link CDORevision} or null if the id is a null ({@link CDOIDUtil#isNull(CDOID)})
- */
- public InternalCDORevision getCDORevision(CDOID id)
- {
- if (CDOIDUtil.isNull(id))
- {
- return null;
- }
-
- if (HibernateThreadContext.isCommitContextSet())
- {
- final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext();
- InternalCDORevision revision;
- // if ((revision = commitContext.getDirtyObject(id)) != null)
- // {
- // return revision;
- // }
-
- if ((revision = commitContext.getNewObject(id)) != null)
- {
- return revision;
- }
-
- // maybe the temp was already translated
- if (id instanceof CDOIDTemp)
- {
- final CDOID newID = commitContext.getCommitContext().getIDMappings().get(id);
- if (newID != null)
- {
- return getCDORevision(newID);
- }
- }
- }
-
- checkIsSupportedID(id);
-
- final String entityName = getEntityName(id);
- final Serializable idValue = getIdValue(id);
- return (InternalCDORevision)getHibernateSession().get(entityName, idValue);
- }
-
- /**
- * Retrieves a {@link InternalCDORevision} from the {@link CommitContext} or from the database/hibernate session.
- * Resolves temporary id's: {@link CDOIDTemp}.
- *
- * @param id
- * the {@link CDOID} identifying the object,
- * @return the retrieved CDORevision or null if the revision is not found
- */
- public InternalCDORevision getCDORevisionNullable(CDOID id)
- {
- if (CDOIDUtil.isNull(id))
- {
- return null;
- }
-
- if (HibernateThreadContext.isCommitContextSet())
- {
- final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext();
- InternalCDORevision revision;
- if ((revision = commitContext.getDirtyObject(id)) != null)
- {
- return revision;
- }
-
- if ((revision = commitContext.getNewObject(id)) != null)
- {
- return revision;
- }
-
- // maybe the temp was already translated
- if (id instanceof CDOIDTemp)
- {
- final CDOID newID = commitContext.getCommitContext().getIDMappings().get(id);
- if (newID != null)
- {
- return getCDORevision(newID);
- }
- }
- }
-
- if (!isStoreCreatedID(id))
- {
- return null;
- }
-
- final String entityName = getEntityName(id);
- final Serializable idValue = getIdValue(id);
- return (InternalCDORevision)getHibernateSession().get(entityName, idValue);
- }
-
- /**
- * Converts a String to a containing feature id. Note this is not the same as the feature id. The feature is the
- * containing feature of the passed EObject.
- *
- * @param contained
- * the object which is contained
- * @param value
- * the value to convert
- * @return the containing feature id.
- * @see #getContainerFeatureId(EClass, EObject, EStructuralFeature)
- */
- public int convertStringToFeatureID(EObject contained, String value)
- {
- final String[] values = value.split(SEPARATOR);
- final String nsuri = values[0];
- final EPackage eContainerPackage = getPackageRegistry().getEPackage(nsuri);
- final String eContainerEClassName = values[1];
- final EClass eContainingClass = (EClass)eContainerPackage.getEClassifier(eContainerEClassName);
-
- final EPackage eFeaturePackage = getPackageRegistry().getEPackage(values[2]);
-
- final String eClassifierName = values[3];
- final EClassifier eClassifier = eFeaturePackage.getEClassifier(eClassifierName);
- final EClass eFeatureClass = (EClass)eClassifier;
- final String eFeatureName = values[4];
- final EStructuralFeature eFeature = eFeatureClass.getEStructuralFeature(eFeatureName);
- return getContainerFeatureId(eContainingClass, contained, eFeature);
- }
-
- /**
- * Computes a valid containing feature id for a passed containing EClass, the contained object and the
- * EStructuralFeature which can be the container or the containment feature.
- *
- * @param containingEClass
- * the EClass representing the container
- * @param contained
- * the EObject which is contained
- * @param eFeature
- * the EStructuralFeature, can be the efeature of the containingEClass or of the contained.
- */
- public int getContainerFeatureId(EClass containingEClass, EObject contained, EStructuralFeature eFeature)
- {
- if (eFeature instanceof EAttribute)
- {
- // featuremap??
- return InternalEObject.EOPPOSITE_FEATURE_BASE - containingEClass.getFeatureID(eFeature);
- }
-
- final EReference eReference = (EReference)eFeature;
- if (eReference.getEOpposite() != null)
- {
- final EReference containerEReference = eReference.getEOpposite();
- return contained.eClass().getFeatureID(containerEReference);
- }
- return InternalEObject.EOPPOSITE_FEATURE_BASE - containingEClass.getFeatureID(eReference);
- }
-
- /**
- * Creates the correct subclass of {@link CDOID} for the passed EClass and hibernate id object.
- *
- * @param classifierRef
- * the EClass to set in the CDOID
- * @param idValue
- * the real id value
- * @return a supported instance of CDOID.
- * @see CDOIDUtil
- */
- public CDOID createCDOID(CDOClassifierRef classifierRef, Object idValue)
- {
- if (idValue instanceof String)
- {
- return CDOIDUtil.createStringWithClassifier(classifierRef, (String)idValue);
- }
-
- if (idValue instanceof Long)
- {
- return CDOIDUtil.createLongWithClassifier(classifierRef, (Long)idValue);
- }
-
- throw new IllegalArgumentException("The ID value type " + idValue.getClass() //$NON-NLS-1$
- + " is not supported by this store. Method called with " + classifierRef); //$NON-NLS-1$
- }
-
- /**
- * Checks if the passed id is created/used by this store.
- *
- * @param id
- * the {@link CDOID} to check
- * @return true if this is a CDOID which is used/created by this store.
- */
- public boolean isStoreCreatedID(CDOID id)
- {
- // TODO: not the nicest check but we know that only these are supported
- // by the hibernatestore
- return id instanceof CDOClassifierRef.Provider || id instanceof CDOIDExternal;
- }
-
- /**
- * Checks if the passed {@link CDOID} is a type supported by this store.
- *
- * @param id
- * the CDOID instance to check
- * @throws IllegalArgumentException
- * if the passed type is not supported.
- */
- public void checkIsSupportedID(CDOID id)
- {
- if (!isStoreCreatedID(id))
- {
- throw new IllegalArgumentException("This CDOID type " + id + " is not supported by this store. " //$NON-NLS-1$ //$NON-NLS-2$
- + id.getClass().getName());
- }
- }
-
- /**
- * @param id
- * CDOID to get the internal id from
- * @return the id used by Hibernate, the String or Long value in the CDOID object.
- */
- public Serializable getIdValue(CDOID id)
- {
- if (id instanceof AbstractCDOIDString)
- {
- return ((AbstractCDOIDString)id).getStringValue();
- }
-
- if (id instanceof AbstractCDOIDLong)
- {
- return ((AbstractCDOIDLong)id).getLongValue();
- }
-
- throw new IllegalArgumentException("This CDOID type " + id + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Retrieves the entity name for the EClass present in the CDOID.
- *
- * @param id
- * the {@link CDOID} to get the EClass from
- * @return the entity name for the EClass of the CDOID.
- * @see HibernateStore#getEntityName(EClass)
- */
- public String getEntityName(CDOID id)
- {
- final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(id);
- if (classifierRef == null)
- {
- throw new IllegalArgumentException("This CDOID type of " + id + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor();
- return accessor.getStore().getEntityName(classifierRef);
- }
-
- /**
- * Create a {@link XMLGregorianCalendar} from a {@link Date} instance.
- */
- public XMLGregorianCalendar getXMLGregorianCalendarDate(Date date, boolean dateTime)
- {
- final XMLGregorianCalendar gregCalendar = dataTypeFactory.newXMLGregorianCalendar();
- final Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
-
- gregCalendar.setYear(calendar.get(Calendar.YEAR));
- gregCalendar.setMonth(calendar.get(Calendar.MONTH) + 1); // correct with 1 on purpose
- gregCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH));
-
- if (dateTime)
- {
- gregCalendar.setHour(calendar.get(Calendar.HOUR_OF_DAY));
- gregCalendar.setMinute(calendar.get(Calendar.MINUTE));
- gregCalendar.setSecond(calendar.get(Calendar.SECOND));
- gregCalendar.setMillisecond(calendar.get(Calendar.MILLISECOND));
- }
-
- return gregCalendar;
- }
-
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDExternal; +import org.eclipse.emf.cdo.common.id.CDOIDTemp; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.model.CDOClassifierRef; +import org.eclipse.emf.cdo.common.model.CDOPackageRegistry; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.IRepository; +import org.eclipse.emf.cdo.server.IStore; +import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext; +import org.eclipse.emf.cdo.server.hibernate.IHibernateMappingProvider; +import org.eclipse.emf.cdo.server.hibernate.IHibernateStore; +import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM; +import org.eclipse.emf.cdo.spi.common.id.AbstractCDOIDLong; +import org.eclipse.emf.cdo.spi.common.id.AbstractCDOIDString; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.WrappedException; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.InternalEObject; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import org.hibernate.Session; +import org.hibernate.proxy.HibernateProxy; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import java.io.Serializable; +import java.util.Calendar; +import java.util.Date; +import java.util.Map; +import java.util.Properties; + +/** + * Provides several utility and convenience methods. Mostly related to {@link CDOID} and {@link CDORevision}. + * + * @author Martin Taal + */ +public class HibernateUtil +{ + private static final String EXT_POINT = "mappingProviderFactories"; //$NON-NLS-1$ + + private static HibernateUtil instance = new HibernateUtil(); + + private static final String SEPARATOR = "_;_"; //$NON-NLS-1$ + + private static final String MAPPING_PROVIDER_FACTORY_TAG = "mappingProviderFactory"; //$NON-NLS-1$ + + private static final String TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$ + + private static final String CLASS = "class"; //$NON-NLS-1$ + + private static IHibernateMappingProvider.Factory mappingProviderFactoryInstance = null; + + public static IHibernateMappingProvider.Factory getMappingProviderFactoryInstance() + { + return mappingProviderFactoryInstance; + } + + public static void setMappingProviderFactoryInstance( + IHibernateMappingProvider.Factory theMappingProviderFactoryInstance) + { + mappingProviderFactoryInstance = theMappingProviderFactoryInstance; + } + + /** + * @return the global singleton instance + */ + public static HibernateUtil getInstance() + { + return instance; + } + + /** + * Sets the singleton used by the Hibernate store. + * + * @param instance + * the instance to set + */ + public static void setInstance(HibernateUtil instance) + { + HibernateUtil.instance = instance; + } + + // Local copy of the datatype factory + private DatatypeFactory dataTypeFactory; + + public HibernateUtil() + { + try + { + dataTypeFactory = DatatypeFactory.newInstance(); + } + catch (DatatypeConfigurationException ex) + { + throw new IllegalStateException("Exception ", ex); + } + } + + public DatatypeFactory getDataTypeFactory() + { + return dataTypeFactory; + } + + public void setDataTypeFactory(DatatypeFactory dataTypeFactory) + { + this.dataTypeFactory = dataTypeFactory; + } + + /** + * Uses the repository package repository to find the EClass of the identified by the CDOClassifierRef. + * + * @param classifierRef + * {@link CDOClassifierRef} which identifies an EClass + * @return the EClass instance identified by the EPackage nsuri and classifier name in the CDOClassifierRef + * @throws IllegalArgumentException + * if the EClass can not be found + * @see IRepository#getPackageRegistry() + */ + public EClass getEClass(CDOClassifierRef classifierRef) + { + final CDOPackageRegistry registry = getPackageRegistry(); + final EPackage ePackage = registry.getEPackage(classifierRef.getPackageURI()); + if (ePackage == null) + { + throw new IllegalArgumentException("No EPackage found with nsuri " + classifierRef.getPackageURI()); //$NON-NLS-1$ + } + + final EClass eClass = (EClass)ePackage.getEClassifier(classifierRef.getClassifierName()); + if (eClass == null) + { + throw new IllegalArgumentException("No EClass " + classifierRef.getClassifierName() + " in EPackage " //$NON-NLS-1$ //$NON-NLS-2$ + + ePackage.getNsURI()); + } + + return eClass; + } + + /** + * @return the package registry as present in the repository + * @see HibernateStore#getRepository() + * @see IRepository#getPackageRegistry() + */ + public CDOPackageRegistry getPackageRegistry() + { + final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor(); + return accessor.getStore().getRepository().getPackageRegistry(); + } + + /** + * Creates an instance of {@link IHibernateStore}. + * + * @param mappingProvider + * the provider which generates a mapping. + * @param properties + * hibernate and teneo properties combined + * @return the created HibernateStore + * @see HibernateStore + * @since 2.0 + */ + public IHibernateStore createStore(IHibernateMappingProvider mappingProvider, Properties properties) + { + HibernateStore store = new HibernateStore(mappingProvider, properties); + mappingProvider.setHibernateStore(store); + return store; + } + + /** + * Can only be used when Eclipse is running. In standalone scenarios create the mapping strategy instance by directly + * calling the constructor of the mapping strategy class. + * + * @see #createFileMappingProvider(String) + * @since 2.0 + */ + public IHibernateMappingProvider.Factory createMappingProviderFactory(String type) + { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + if (registry == null) + { + return getMappingProviderFactoryInstance(); + } + IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT); + for (final IConfigurationElement element : elements) + { + if (MAPPING_PROVIDER_FACTORY_TAG.equals(element.getName())) + { + String typeAttr = element.getAttribute(TYPE_ATTRIBUTE); + if (ObjectUtil.equals(typeAttr, type)) + { + try + { + return (IHibernateMappingProvider.Factory)element.createExecutableExtension(CLASS); + } + catch (CoreException ex) + { + throw WrappedException.wrap(ex); + } + } + } + } + + return getMappingProviderFactoryInstance(); + } + + /** + * Creates a FileMappingProvider using the passed locations. + * + * @param location + * the locations to load the mappings from + * @return a {@link FileHibernateMappingProvider} + * @since 3.0 + */ + public IHibernateMappingProvider createFileMappingProvider(String location) + { + return new FileHibernateMappingProvider(location); + } + + /** + * Retrieves the Hibernate Session from the current {@link HibernateStoreAccessor}. The current HibernateStoreAccessor + * is maintained in the {@link HibernateThreadContext}. + * + * @return the current hibernate session, if none is there a new one is created and a transaction is started. + * @since 2.0 + */ + public Session getHibernateSession() + { + final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor(); + return accessor.getHibernateSession(); + } + + /** + * Convenience method to convert the properties of the {@link IStore#getRepository()} to a real java Properties + * object. + * + * @param store + * the properties of this store are converted to a real Properties object + * @return a Properties object with the store properties + */ + public Properties getPropertiesFromStore(IHibernateStore store) + { + final Properties props = new Properties(); + + final Map<String, String> storeProps = store.getRepository().getProperties(); + for (String key : storeProps.keySet()) + { + props.setProperty(key, storeProps.get(key)); + } + + return props; + } + + /** + * Checks if the object is a HibernateProxy. If so creates the CDOID without resolving the hibernate proxy. If it not + * a proxy then the id is retrieved from the object itself. It is assumed to be a CDORevision then. + */ + public CDOID getCDOID(Object o) + { + if (o instanceof HibernateProxy) + { + final Object idValue = ((HibernateProxy)o).getHibernateLazyInitializer().getIdentifier(); + final String entityName = ((HibernateProxy)o).getHibernateLazyInitializer().getEntityName(); + final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor(); + final EClass eClass = accessor.getStore().getEClass(entityName); + return HibernateUtil.getInstance().createCDOID(new CDOClassifierRef(eClass), idValue); + } + + return ((CDORevision)o).getID(); + } + + /** + * Reads the entity name while taking account the fact that the object maybe a Hibernate proxy. + */ + public String getEntityName(Object o) + { + if (o instanceof HibernateProxy) + { + return ((HibernateProxy)o).getHibernateLazyInitializer().getEntityName(); + } + + final EClass eClass = ((CDORevision)o).getEClass(); + final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor(); + return accessor.getStore().getEntityName(eClass); + } + + /** + * Deprecated method use: {@link HibernateStore#getEntityName(EClass)}. + */ + @Deprecated + public String getEntityName(CDORevision revision) + { + return HibernateThreadContext.getCurrentStoreAccessor().getStore().getEntityName(revision.getEClass()); + } + + /** + * Converts a CDOID to an unique String representations. Null, {@link CDOIDTemp} and null CDOID's are returned as null + * value. Supports {@link CDOID} and {@link CDOIDExternal}. + * + * @param id + * the id to convert + * @return a unique String + */ + public String convertCDOIDToString(CDOID id) + { + if (id == null || id.isNull() || id.isTemporary()) + { + return null; + } + + final StringBuilder sb = new StringBuilder(); + CDOIDUtil.write(sb, id); + return sb.toString(); + } + + /** + * Converts a String back to its CDOID representation. The same types as in the {@link #convertCDOIDToString(CDOID)} + * method are supported. + * + * @param strID + * the String representation of the CDOID + * @return a valid CDOID, can be null + */ + public CDOID convertStringToCDOID(String strID) + { + if (strID == null) + { + return null; + } + + return CDOIDUtil.read(strID); + } + + /** + * Translates a temporary {@link CDOID} into a hibernate ID, by finding the object it refers to in the + * {@link CommitContext} and then returning or by persisting the object. Note assumes that the hibernate session and + * CommitContext are set in HibernateThreadContext. + * + * @param id + * the CDOID to translate to a valid id, if the id is already valid then it is returned. + * @return the passed id or an instance of CDOID which is valid. + */ + public CDOID getCDOIDHibernate(CDOID id) + { + if (isStoreCreatedID(id)) + { + return id; + } + + final CDORevision revision = getCDORevision(id); + if (isStoreCreatedID(revision.getID())) + { + return revision.getID(); + } + + return getCDOIDHibernate(revision); + } + + /** + * Retrieves a {@link CDOID} from the passed CDORevision. If the revision has a non-supported CDOID then the revision + * is saved to the database. + * + * @param revision + * the revision to get the id from + * @return a CDOID supported by this store + */ + public CDOID getCDOIDHibernate(final CDORevision revision) + { + final Session session = getHibernateSession(); + if (!isStoreCreatedID(revision.getID())) + { + session.saveOrUpdate(revision); + } + + checkIsSupportedID(revision.getID()); + + return revision.getID(); + } + + /** + * Retrieves the {@link InternalCDORevision} if the target is a {@link CDOObject} then the CDORevision is retrieved + * using: {@link CDOObject#cdoRevision()}. + * + * @param target + * the object which can be a CDOObject or an InternalCDORevision + * @return the found {@link InternalCDORevision} + */ + public InternalCDORevision getCDORevision(Object target) + { + if (target instanceof CDOObject) + { + return (InternalCDORevision)CDOUtil.getCDOObject((EObject)target).cdoRevision(); + } + return (InternalCDORevision)target; + } + + /** + * Gets a current object, first checks the new and dirty objects from the {@link CommitContext}. Otherwise reads it + * from the session. + * + * @param id + * the {@link CDOID}, the {@link CDOIDTemp} is resolved against the CommitContext. + * @return the retrieved {@link CDORevision} or null if the id is a null ({@link CDOIDUtil#isNull(CDOID)}) + */ + public InternalCDORevision getCDORevision(CDOID id) + { + if (CDOIDUtil.isNull(id)) + { + return null; + } + + if (HibernateThreadContext.isCommitContextSet()) + { + final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext(); + InternalCDORevision revision; + // if ((revision = commitContext.getDirtyObject(id)) != null) + // { + // return revision; + // } + + if ((revision = commitContext.getNewObject(id)) != null) + { + return revision; + } + + // maybe the temp was already translated + if (id instanceof CDOIDTemp) + { + final CDOID newID = commitContext.getCommitContext().getIDMappings().get(id); + if (newID != null) + { + return getCDORevision(newID); + } + } + } + + checkIsSupportedID(id); + + final String entityName = getEntityName(id); + final Serializable idValue = getIdValue(id); + return (InternalCDORevision)getHibernateSession().get(entityName, idValue); + } + + /** + * Retrieves a {@link InternalCDORevision} from the {@link CommitContext} or from the database/hibernate session. + * Resolves temporary id's: {@link CDOIDTemp}. + * + * @param id + * the {@link CDOID} identifying the object, + * @return the retrieved CDORevision or null if the revision is not found + */ + public InternalCDORevision getCDORevisionNullable(CDOID id) + { + if (CDOIDUtil.isNull(id)) + { + return null; + } + + if (HibernateThreadContext.isCommitContextSet()) + { + final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext(); + InternalCDORevision revision; + if ((revision = commitContext.getDirtyObject(id)) != null) + { + return revision; + } + + if ((revision = commitContext.getNewObject(id)) != null) + { + return revision; + } + + // maybe the temp was already translated + if (id instanceof CDOIDTemp) + { + final CDOID newID = commitContext.getCommitContext().getIDMappings().get(id); + if (newID != null) + { + return getCDORevision(newID); + } + } + } + + if (!isStoreCreatedID(id)) + { + return null; + } + + final String entityName = getEntityName(id); + final Serializable idValue = getIdValue(id); + return (InternalCDORevision)getHibernateSession().get(entityName, idValue); + } + + /** + * Converts a String to a containing feature id. Note this is not the same as the feature id. The feature is the + * containing feature of the passed EObject. + * + * @param contained + * the object which is contained + * @param value + * the value to convert + * @return the containing feature id. + * @see #getContainerFeatureId(EClass, EObject, EStructuralFeature) + */ + public int convertStringToFeatureID(EObject contained, String value) + { + final String[] values = value.split(SEPARATOR); + final String nsuri = values[0]; + final EPackage eContainerPackage = getPackageRegistry().getEPackage(nsuri); + final String eContainerEClassName = values[1]; + final EClass eContainingClass = (EClass)eContainerPackage.getEClassifier(eContainerEClassName); + + final EPackage eFeaturePackage = getPackageRegistry().getEPackage(values[2]); + + final String eClassifierName = values[3]; + final EClassifier eClassifier = eFeaturePackage.getEClassifier(eClassifierName); + final EClass eFeatureClass = (EClass)eClassifier; + final String eFeatureName = values[4]; + final EStructuralFeature eFeature = eFeatureClass.getEStructuralFeature(eFeatureName); + return getContainerFeatureId(eContainingClass, contained, eFeature); + } + + /** + * Computes a valid containing feature id for a passed containing EClass, the contained object and the + * EStructuralFeature which can be the container or the containment feature. + * + * @param containingEClass + * the EClass representing the container + * @param contained + * the EObject which is contained + * @param eFeature + * the EStructuralFeature, can be the efeature of the containingEClass or of the contained. + */ + public int getContainerFeatureId(EClass containingEClass, EObject contained, EStructuralFeature eFeature) + { + if (eFeature instanceof EAttribute) + { + // featuremap?? + return InternalEObject.EOPPOSITE_FEATURE_BASE - containingEClass.getFeatureID(eFeature); + } + + final EReference eReference = (EReference)eFeature; + if (eReference.getEOpposite() != null) + { + final EReference containerEReference = eReference.getEOpposite(); + return contained.eClass().getFeatureID(containerEReference); + } + return InternalEObject.EOPPOSITE_FEATURE_BASE - containingEClass.getFeatureID(eReference); + } + + /** + * Creates the correct subclass of {@link CDOID} for the passed EClass and hibernate id object. + * + * @param classifierRef + * the EClass to set in the CDOID + * @param idValue + * the real id value + * @return a supported instance of CDOID. + * @see CDOIDUtil + */ + public CDOID createCDOID(CDOClassifierRef classifierRef, Object idValue) + { + if (idValue instanceof String) + { + return CDOIDUtil.createStringWithClassifier(classifierRef, (String)idValue); + } + + if (idValue instanceof Long) + { + return CDOIDUtil.createLongWithClassifier(classifierRef, (Long)idValue); + } + + throw new IllegalArgumentException("The ID value type " + idValue.getClass() //$NON-NLS-1$ + + " is not supported by this store. Method called with " + classifierRef); //$NON-NLS-1$ + } + + /** + * Checks if the passed id is created/used by this store. + * + * @param id + * the {@link CDOID} to check + * @return true if this is a CDOID which is used/created by this store. + */ + public boolean isStoreCreatedID(CDOID id) + { + // TODO: not the nicest check but we know that only these are supported + // by the hibernatestore + return id instanceof CDOClassifierRef.Provider || id instanceof CDOIDExternal; + } + + /** + * Checks if the passed {@link CDOID} is a type supported by this store. + * + * @param id + * the CDOID instance to check + * @throws IllegalArgumentException + * if the passed type is not supported. + */ + public void checkIsSupportedID(CDOID id) + { + if (!isStoreCreatedID(id)) + { + throw new IllegalArgumentException("This CDOID type " + id + " is not supported by this store. " //$NON-NLS-1$ //$NON-NLS-2$ + + id.getClass().getName()); + } + } + + /** + * @param id + * CDOID to get the internal id from + * @return the id used by Hibernate, the String or Long value in the CDOID object. + */ + public Serializable getIdValue(CDOID id) + { + if (id instanceof AbstractCDOIDString) + { + return ((AbstractCDOIDString)id).getStringValue(); + } + + if (id instanceof AbstractCDOIDLong) + { + return ((AbstractCDOIDLong)id).getLongValue(); + } + + throw new IllegalArgumentException("This CDOID type " + id + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Retrieves the entity name for the EClass present in the CDOID. + * + * @param id + * the {@link CDOID} to get the EClass from + * @return the entity name for the EClass of the CDOID. + * @see HibernateStore#getEntityName(EClass) + */ + public String getEntityName(CDOID id) + { + final CDOClassifierRef classifierRef = CDOIDUtil.getClassifierRef(id); + if (classifierRef == null) + { + throw new IllegalArgumentException("This CDOID type of " + id + " is not supported by this store."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + final HibernateStoreAccessor accessor = HibernateThreadContext.getCurrentStoreAccessor(); + return accessor.getStore().getEntityName(classifierRef); + } + + /** + * Create a {@link XMLGregorianCalendar} from a {@link Date} instance. + */ + public XMLGregorianCalendar getXMLGregorianCalendarDate(Date date, boolean dateTime) + { + final XMLGregorianCalendar gregCalendar = dataTypeFactory.newXMLGregorianCalendar(); + final Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + gregCalendar.setYear(calendar.get(Calendar.YEAR)); + gregCalendar.setMonth(calendar.get(Calendar.MONTH) + 1); // correct with 1 on purpose + gregCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH)); + + if (dateTime) + { + gregCalendar.setHour(calendar.get(Calendar.HOUR_OF_DAY)); + gregCalendar.setMinute(calendar.get(Calendar.MINUTE)); + gregCalendar.setSecond(calendar.get(Calendar.SECOND)); + gregCalendar.setMillisecond(calendar.get(Calendar.MILLISECOND)); + } + + return gregCalendar; + } + +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemInformation.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemInformation.java index ae7e543b92..897c2e0753 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemInformation.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemInformation.java @@ -1,58 +1,58 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-/**
- * Stores system related information, is used to keep track that CDO is started for the first time. There should only be
- * one SystemInformation object in the database.
- *
- * @author Martin Taal
- */
-public class SystemInformation
-{
- private long id = 1;
-
- private long creationTime;
-
- private boolean firstTime;
-
- public boolean isFirstTime()
- {
- return firstTime;
- }
-
- public void setFirstTime(boolean firstTime)
- {
- this.firstTime = firstTime;
- }
-
- public long getId()
- {
- return id;
- }
-
- public void setId(long id)
- {
- // on purposely not changing the id
- // this.id = id;
- }
-
- public long getCreationTime()
- {
- return creationTime;
- }
-
- public void setCreationTime(long creationTime)
- {
- this.creationTime = creationTime;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +/** + * Stores system related information, is used to keep track that CDO is started for the first time. There should only be + * one SystemInformation object in the database. + * + * @author Martin Taal + */ +public class SystemInformation +{ + private long id = 1; + + private long creationTime; + + private boolean firstTime; + + public boolean isFirstTime() + { + return firstTime; + } + + public void setFirstTime(boolean firstTime) + { + this.firstTime = firstTime; + } + + public long getId() + { + return id; + } + + public void setId(long id) + { + // on purposely not changing the id + // this.id = id; + } + + public long getCreationTime() + { + return creationTime; + } + + public void setCreationTime(long creationTime) + { + this.creationTime = creationTime; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemProperty.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemProperty.java index 7423b43d8b..49b51958eb 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemProperty.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/SystemProperty.java @@ -1,44 +1,44 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate;
-
-/**
- * Is used to store and retrieve properties in the database.
- *
- * @author Martin Taal
- */
-public class SystemProperty
-{
- private String name;
-
- private String value;
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public String getValue()
- {
- return value;
- }
-
- public void setValue(String value)
- {
- this.value = value;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate; + +/** + * Is used to store and retrieve properties in the database. + * + * @author Martin Taal + */ +public class SystemProperty +{ + private String name; + + private String value; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getValue() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/bundle/OM.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/bundle/OM.java index e6afe7facf..ff30e8e9ae 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/bundle/OM.java @@ -1,44 +1,44 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate.bundle;
-
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiActivator;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-
-/**
- * The <em>Operations & Maintenance</em> class of this bundle.
- *
- * @author Eike Stepper
- */
-public abstract class OM
-{
- public static final String BUNDLE_ID = "org.eclipse.emf.cdo.server.hibernate"; //$NON-NLS-1$
-
- public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
-
- public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- /**
- * @author Eike Stepper
- */
- public static final class Activator extends OSGiActivator
- {
- public Activator()
- {
- super(BUNDLE);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate.bundle; + +import org.eclipse.net4j.util.om.OMBundle; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.OSGiActivator; +import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.trace.OMTracer; + +/** + * The <em>Operations & Maintenance</em> class of this bundle. + * + * @author Eike Stepper + */ +public abstract class OM +{ + public static final String BUNDLE_ID = "org.eclipse.emf.cdo.server.hibernate"; //$NON-NLS-1$ + + public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class); + + public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$ + + public static final OMLogger LOG = BUNDLE.logger(); + + /** + * @author Eike Stepper + */ + public static final class Activator extends OSGiActivator + { + public Activator() + { + super(BUNDLE); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ClassServerInfo.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ClassServerInfo.java index aa488b41a4..b5e0b19c0e 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ClassServerInfo.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ClassServerInfo.java @@ -1,18 +1,18 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info;
-
-/**
- * @author Eike Stepper
- */
-public final class ClassServerInfo extends ServerInfo
-{
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info; + +/** + * @author Eike Stepper + */ +public final class ClassServerInfo extends ServerInfo +{ +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/FeatureServerInfo.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/FeatureServerInfo.java index 44c95c08a0..39e1eacd1b 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/FeatureServerInfo.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/FeatureServerInfo.java @@ -1,18 +1,18 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info;
-
-/**
- * @author Eike Stepper
- */
-public final class FeatureServerInfo extends ServerInfo
-{
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info; + +/** + * @author Eike Stepper + */ +public final class FeatureServerInfo extends ServerInfo +{ +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/PackageServerInfo.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/PackageServerInfo.java index 756e9cdc7f..7c53403a4d 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/PackageServerInfo.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/PackageServerInfo.java @@ -1,18 +1,18 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info;
-
-/**
- * @author Eike Stepper
- */
-public final class PackageServerInfo extends ServerInfo
-{
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info; + +/** + * @author Eike Stepper + */ +public final class PackageServerInfo extends ServerInfo +{ +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ServerInfo.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ServerInfo.java index d8bba2d058..66bd9467ac 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ServerInfo.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/info/ServerInfo.java @@ -1,18 +1,18 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info;
-
-/**
- * @author Eike Stepper
- */
-public abstract class ServerInfo
-{
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate.info; + +/** + * @author Eike Stepper + */ +public abstract class ServerInfo +{ +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBlobUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBlobUserType.java index fc384f1a53..45f816fedb 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBlobUserType.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBlobUserType.java @@ -1,32 +1,32 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial api
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.lob.CDOBlob;
-import org.eclipse.emf.cdo.common.lob.CDOLobUtil;
-
-/**
- * Persists a {@link CDOBlob} in the DB.
- */
-public class CDOBlobUserType extends CDOLobUserType
-{
- public Class<?> returnedClass()
- {
- return CDOBlob.class;
- }
-
- @Override
- protected Object createLob(byte[] id, long size)
- {
- return CDOLobUtil.createBlob(id, size);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial api + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.lob.CDOBlob; +import org.eclipse.emf.cdo.common.lob.CDOLobUtil; + +/** + * Persists a {@link CDOBlob} in the DB. + */ +public class CDOBlobUserType extends CDOLobUserType +{ + public Class<?> returnedClass() + { + return CDOBlob.class; + } + + @Override + protected Object createLob(byte[] id, long size) + { + return CDOLobUtil.createBlob(id, size); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBranchTimeStampGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBranchTimeStampGetter.java index fc503dbfe7..73d2e54bff 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBranchTimeStampGetter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOBranchTimeStampGetter.java @@ -1,46 +1,46 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateBranchPointImpl;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.hibernate.HibernateException;
-
-/**
- * Gets the time stamp value to store in the database.
- *
- * @see CDOHibernateBranchPointImpl
- * @author Martin Taal
- */
-public class CDOBranchTimeStampGetter extends CDOPropertyGetter
-{
- private static final long serialVersionUID = 1L;
-
- public CDOBranchTimeStampGetter(CDORevisionTuplizer tuplizer, String propertyName)
- {
- super(tuplizer, propertyName);
- }
-
- @Override
- public Object get(Object target) throws HibernateException
- {
- final InternalCDORevision revision = (InternalCDORevision)target;
- final Object value = revision.getTimeStamp();
- return value;
- }
-
- @Override
- protected boolean isVirtualPropertyAllowed()
- {
- return true;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateBranchPointImpl; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.hibernate.HibernateException; + +/** + * Gets the time stamp value to store in the database. + * + * @see CDOHibernateBranchPointImpl + * @author Martin Taal + */ +public class CDOBranchTimeStampGetter extends CDOPropertyGetter +{ + private static final long serialVersionUID = 1L; + + public CDOBranchTimeStampGetter(CDORevisionTuplizer tuplizer, String propertyName) + { + super(tuplizer, propertyName); + } + + @Override + public Object get(Object target) throws HibernateException + { + final InternalCDORevision revision = (InternalCDORevision)target; + final Object value = revision.getTimeStamp(); + return value; + } + + @Override + protected boolean isVirtualPropertyAllowed() + { + return true; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOClobUserType.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOClobUserType.java index aceae92bf2..0d46f3fad1 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOClobUserType.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOClobUserType.java @@ -1,32 +1,32 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial api
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.lob.CDOClob;
-import org.eclipse.emf.cdo.common.lob.CDOLobUtil;
-
-/**
- * Persists a {@link CDOClob} in the DB.
- */
-public class CDOClobUserType extends CDOLobUserType
-{
- public Class<?> returnedClass()
- {
- return CDOClob.class;
- }
-
- @Override
- protected Object createLob(byte[] id, long size)
- {
- return CDOLobUtil.createClob(id, size);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial api + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.lob.CDOClob; +import org.eclipse.emf.cdo.common.lob.CDOLobUtil; + +/** + * Persists a {@link CDOClob} in the DB. + */ +public class CDOClobUserType extends CDOLobUserType +{ + public Class<?> returnedClass() + { + return CDOClob.class; + } + + @Override + protected Object createLob(byte[] id, long size) + { + return CDOLobUtil.createClob(id, size); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOContainerGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOContainerGetter.java index 0c87edc2fd..c71e10c033 100755 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOContainerGetter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOContainerGetter.java @@ -1,45 +1,45 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.ContainerInfoConverter;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.hibernate.HibernateException;
-
-/**
- * gets the container information as a String (to-be-stored in the db) from the CDORevision.
- *
- * @see ContainerInfoConverter
- * @author Martin Taal
- */
-public class CDOContainerGetter extends CDOPropertyGetter
-{
- private static final long serialVersionUID = 1L;
-
- public CDOContainerGetter(CDORevisionTuplizer tuplizer, String propertyName)
- {
- super(tuplizer, propertyName);
- }
-
- @Override
- public Object get(Object target) throws HibernateException
- {
- final InternalCDORevision revision = (InternalCDORevision)target;
- return ContainerInfoConverter.getInstance().convertContainerRelationToString(revision);
- }
-
- @Override
- protected boolean isVirtualPropertyAllowed()
- {
- return true;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.server.internal.hibernate.ContainerInfoConverter; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.hibernate.HibernateException; + +/** + * gets the container information as a String (to-be-stored in the db) from the CDORevision. + * + * @see ContainerInfoConverter + * @author Martin Taal + */ +public class CDOContainerGetter extends CDOPropertyGetter +{ + private static final long serialVersionUID = 1L; + + public CDOContainerGetter(CDORevisionTuplizer tuplizer, String propertyName) + { + super(tuplizer, propertyName); + } + + @Override + public Object get(Object target) throws HibernateException + { + final InternalCDORevision revision = (InternalCDORevision)target; + return ContainerInfoConverter.getInstance().convertContainerRelationToString(revision); + } + + @Override + protected boolean isVirtualPropertyAllowed() + { + return true; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertyGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertyGetter.java index 23fb92fdd9..7ce94d6e2e 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertyGetter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOIDPropertyGetter.java @@ -1,100 +1,100 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - copied from CDORevisionPropertyHandler and adapted
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDObject;
-import org.eclipse.emf.cdo.common.id.CDOIDTemp;
-import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateCommitContext;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.hibernate.HibernateException;
-
-/**
- * @author Martin Taal
- */
-public class CDOIDPropertyGetter extends CDOPropertyGetter
-{
- private static final long serialVersionUID = 1L;
-
- public CDOIDPropertyGetter(CDORevisionTuplizer tuplizer, String propertyName)
- {
- super(tuplizer, propertyName);
- }
-
- @Override
- public Object get(Object target) throws HibernateException
- {
- InternalCDORevision revision = (InternalCDORevision)target;
- if (!(HibernateUtil.getInstance().getCDOID(revision) instanceof CDOIDObject))
- {
- if (!isVirtualProperty())
- {
- final Object value = super.get(target);
- // todo: value can be null for generated values?
- if (value != null)
- {
- setCDOID(revision, value);
- }
-
- return value;
- }
-
- return null;
- }
-
- if (isVirtualProperty())
- {
- return HibernateUtil.getInstance().getIdValue(revision.getID());
- }
-
- Object id = super.get(target);
- setCDOID(revision, id);
-
- // TODO: does this make sense?
- // if (id.getId() == null)
- // {
- // id.setId((Serializable)id);
- // }
- return id;
- }
-
- private void setCDOID(CDORevision target, Object value)
- {
- final InternalCDORevision revision = (InternalCDORevision)target;
- final CDOID id = HibernateUtil.getInstance().getCDOID(revision);
- if (id == null || id instanceof CDOIDTemp)
- {
- final CDOID newCDOID = HibernateUtil.getInstance().createCDOID(new CDOClassifierRef(revision.getEClass()), value);
- revision.setID(newCDOID);
- if (HibernateThreadContext.isCommitContextSet())
- {
- final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext();
- commitContext.setNewID(id, newCDOID);
- if (id instanceof CDOIDTemp)
- {
- commitContext.getCommitContext().addIDMapping(id, newCDOID);
- }
- }
- }
- }
-
- @Override
- protected boolean isVirtualPropertyAllowed()
- {
- return true;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - copied from CDORevisionPropertyHandler and adapted + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDObject; +import org.eclipse.emf.cdo.common.id.CDOIDTemp; +import org.eclipse.emf.cdo.common.model.CDOClassifierRef; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateCommitContext; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.hibernate.HibernateException; + +/** + * @author Martin Taal + */ +public class CDOIDPropertyGetter extends CDOPropertyGetter +{ + private static final long serialVersionUID = 1L; + + public CDOIDPropertyGetter(CDORevisionTuplizer tuplizer, String propertyName) + { + super(tuplizer, propertyName); + } + + @Override + public Object get(Object target) throws HibernateException + { + InternalCDORevision revision = (InternalCDORevision)target; + if (!(HibernateUtil.getInstance().getCDOID(revision) instanceof CDOIDObject)) + { + if (!isVirtualProperty()) + { + final Object value = super.get(target); + // todo: value can be null for generated values? + if (value != null) + { + setCDOID(revision, value); + } + + return value; + } + + return null; + } + + if (isVirtualProperty()) + { + return HibernateUtil.getInstance().getIdValue(revision.getID()); + } + + Object id = super.get(target); + setCDOID(revision, id); + + // TODO: does this make sense? + // if (id.getId() == null) + // { + // id.setId((Serializable)id); + // } + return id; + } + + private void setCDOID(CDORevision target, Object value) + { + final InternalCDORevision revision = (InternalCDORevision)target; + final CDOID id = HibernateUtil.getInstance().getCDOID(revision); + if (id == null || id instanceof CDOIDTemp) + { + final CDOID newCDOID = HibernateUtil.getInstance().createCDOID(new CDOClassifierRef(revision.getEClass()), value); + revision.setID(newCDOID); + if (HibernateThreadContext.isCommitContextSet()) + { + final HibernateCommitContext commitContext = HibernateThreadContext.getCommitContext(); + commitContext.setNewID(id, newCDOID); + if (id instanceof CDOIDTemp) + { + commitContext.getCommitContext().addIDMapping(id, newCDOID); + } + } + } + } + + @Override + protected boolean isVirtualPropertyAllowed() + { + return true; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java index bb443fc147..c71ea6f3b5 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOInterceptor.java @@ -1,71 +1,71 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
-
-import org.hibernate.EmptyInterceptor;
-import org.hibernate.type.Type;
-
-import java.io.Serializable;
-
-/**
- * Resolves entitynames, todo: use entityname strategy!
- *
- * @author Martin Taal
- */
-public class CDOInterceptor extends EmptyInterceptor
-{
- private static final long serialVersionUID = 1L;
-
- public CDOInterceptor()
- {
- }
-
- @Override
- public Boolean isTransient(Object entity)
- {
- if (!(entity instanceof CDORevision))
- {
- return super.isTransient(entity);
- }
-
- final CDORevision revision = (CDORevision)entity;
- final CDOID id = HibernateUtil.getInstance().getCDOID(revision);
- if (id.isNull() || id.isTemporary())
- {
- return true;
- }
-
- return null;
- }
-
- @Override
- public String getEntityName(Object object)
- {
- if (!(object instanceof CDORevision))
- {
- return object.getClass().getName();
- }
-
- return HibernateUtil.getInstance().getEntityName(object);
- }
-
- @Override
- public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
- String[] propertyNames, Type[] types)
- {
- return false;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; + +import org.hibernate.EmptyInterceptor; +import org.hibernate.type.Type; + +import java.io.Serializable; + +/** + * Resolves entitynames, todo: use entityname strategy! + * + * @author Martin Taal + */ +public class CDOInterceptor extends EmptyInterceptor +{ + private static final long serialVersionUID = 1L; + + public CDOInterceptor() + { + } + + @Override + public Boolean isTransient(Object entity) + { + if (!(entity instanceof CDORevision)) + { + return super.isTransient(entity); + } + + final CDORevision revision = (CDORevision)entity; + final CDOID id = HibernateUtil.getInstance().getCDOID(revision); + if (id.isNull() || id.isTemporary()) + { + return true; + } + + return null; + } + + @Override + public String getEntityName(Object object) + { + if (!(object instanceof CDORevision)) + { + return object.getClass().getName(); + } + + return HibernateUtil.getInstance().getEntityName(object); + } + + @Override + public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, + String[] propertyNames, Type[] types) + { + return false; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyHandler.java index 340992a037..c4c2b63fe2 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyHandler.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOPropertyHandler.java @@ -1,88 +1,88 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - copied from CDORevisionPropertyHandler and adapted
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-/**
- * @author Martin Taal
- */
-public abstract class CDOPropertyHandler
-{
- private final ContextTracer tracer = new ContextTracer(OM.DEBUG, this.getClass());
-
- private CDORevisionTuplizer tuplizer;
-
- private EStructuralFeature feature;
-
- private boolean virtualProperty;
-
- public CDOPropertyHandler(CDORevisionTuplizer tuplizer, String propertyName)
- {
- this.tuplizer = tuplizer;
- feature = tuplizer.getEClass().getEStructuralFeature(propertyName);
- if (getTracer().isEnabled())
- {
- getTracer().trace(
- "Created " + this.getClass().getName() + " for eClass/feature: " + tuplizer.getEClass().getName() + "." //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + propertyName);
- }
-
- if (feature == null)
- {
- if (isVirtualPropertyAllowed())
- {
- virtualProperty = true;
- if (getTracer().isEnabled())
- {
- getTracer().trace("This is a virtual property"); //$NON-NLS-1$
- }
- }
- else
- {
- throw new IllegalStateException("Feature not found: " + propertyName); //$NON-NLS-1$
- }
- }
- }
-
- protected ContextTracer getTracer()
- {
- return tracer;
- }
-
- public CDORevisionTuplizer getTuplizer()
- {
- return tuplizer;
- }
-
- public EStructuralFeature getEStructuralFeature()
- {
- return feature;
- }
-
- protected boolean isVirtualPropertyAllowed()
- {
- return false;
- }
-
- /**
- * @return the virtualProperty
- */
- public boolean isVirtualProperty()
- {
- return virtualProperty;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - copied from CDORevisionPropertyHandler and adapted + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM; + +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * @author Martin Taal + */ +public abstract class CDOPropertyHandler +{ + private final ContextTracer tracer = new ContextTracer(OM.DEBUG, this.getClass()); + + private CDORevisionTuplizer tuplizer; + + private EStructuralFeature feature; + + private boolean virtualProperty; + + public CDOPropertyHandler(CDORevisionTuplizer tuplizer, String propertyName) + { + this.tuplizer = tuplizer; + feature = tuplizer.getEClass().getEStructuralFeature(propertyName); + if (getTracer().isEnabled()) + { + getTracer().trace( + "Created " + this.getClass().getName() + " for eClass/feature: " + tuplizer.getEClass().getName() + "." //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + propertyName); + } + + if (feature == null) + { + if (isVirtualPropertyAllowed()) + { + virtualProperty = true; + if (getTracer().isEnabled()) + { + getTracer().trace("This is a virtual property"); //$NON-NLS-1$ + } + } + else + { + throw new IllegalStateException("Feature not found: " + propertyName); //$NON-NLS-1$ + } + } + } + + protected ContextTracer getTracer() + { + return tracer; + } + + public CDORevisionTuplizer getTuplizer() + { + return tuplizer; + } + + public EStructuralFeature getEStructuralFeature() + { + return feature; + } + + protected boolean isVirtualPropertyAllowed() + { + return false; + } + + /** + * @return the virtualProperty + */ + public boolean isVirtualProperty() + { + return virtualProperty; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceGetter.java index db479ab818..3daf5bd26f 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceGetter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOReferenceGetter.java @@ -1,52 +1,52 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - copied from CDORevisionPropertyHandler and adapted
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDExternal;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
-
-import org.hibernate.HibernateException;
-
-/**
- * @author Martin Taal
- */
-public class CDOReferenceGetter extends CDOPropertyGetter
-{
- private static final long serialVersionUID = 1L;
-
- public CDOReferenceGetter(CDORevisionTuplizer tuplizer, String propertyName)
- {
- super(tuplizer, propertyName);
- }
-
- @Override
- public Object get(Object target) throws HibernateException
- {
- final Object o = super.get(target);
- if (o instanceof CDOID && CDOIDUtil.isNull((CDOID)o))
- {
- return null;
- }
- else if (o instanceof CDOIDExternal)
- {
- return o;
- }
- else if (o instanceof CDOID)
- {
- return HibernateUtil.getInstance().getCDORevision((CDOID)o);
- }
-
- return o;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - copied from CDORevisionPropertyHandler and adapted + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDExternal; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; + +import org.hibernate.HibernateException; + +/** + * @author Martin Taal + */ +public class CDOReferenceGetter extends CDOPropertyGetter +{ + private static final long serialVersionUID = 1L; + + public CDOReferenceGetter(CDORevisionTuplizer tuplizer, String propertyName) + { + super(tuplizer, propertyName); + } + + @Override + public Object get(Object target) throws HibernateException + { + final Object o = super.get(target); + if (o instanceof CDOID && CDOIDUtil.isNull((CDOID)o)) + { + return null; + } + else if (o instanceof CDOIDExternal) + { + return o; + } + else if (o instanceof CDOID) + { + return HibernateUtil.getInstance().getCDORevision((CDOID)o); + } + + return o; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOResourceIDGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOResourceIDGetter.java index 3dc010409d..ca88be4978 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOResourceIDGetter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOResourceIDGetter.java @@ -1,41 +1,41 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - copied from CDORevisionPropertyHandler and adapted
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.hibernate.HibernateException;
-
-/**
- * @author Martin Taal
- */
-public class CDOResourceIDGetter extends CDOPropertyGetter
-{
- private static final long serialVersionUID = 1L;
-
- public CDOResourceIDGetter(CDORevisionTuplizer tuplizer, String propertyName)
- {
- super(tuplizer, propertyName);
- }
-
- @Override
- public Object get(Object target) throws HibernateException
- {
- return ((InternalCDORevision)target).getResourceID();
- }
-
- @Override
- protected boolean isVirtualPropertyAllowed()
- {
- return true;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - copied from CDORevisionPropertyHandler and adapted + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.hibernate.HibernateException; + +/** + * @author Martin Taal + */ +public class CDOResourceIDGetter extends CDOPropertyGetter +{ + private static final long serialVersionUID = 1L; + + public CDOResourceIDGetter(CDORevisionTuplizer tuplizer, String propertyName) + { + super(tuplizer, propertyName); + } + + @Override + public Object get(Object target) throws HibernateException + { + return ((InternalCDORevision)target).getResourceID(); + } + + @Override + protected boolean isVirtualPropertyAllowed() + { + return true; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java index 35aa69f41b..0df555ed15 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionInstantiator.java @@ -1,65 +1,65 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.eclipse.emf.ecore.EClass;
-
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.tuple.Instantiator;
-
-import java.io.Serializable;
-
-/**
- * @author Eike Stepper
- */
-public class CDORevisionInstantiator implements Instantiator
-{
- private static final long serialVersionUID = 1L;
-
- private final EClass eClass;
-
- private final CDOClassifierRef classifierRef;
-
- public CDORevisionInstantiator(CDORevisionTuplizer tuplizer, PersistentClass mappingInfo)
- {
- eClass = tuplizer.getEClass();
- classifierRef = new CDOClassifierRef(eClass);
- }
-
- public Object instantiate()
- {
- // TODO CDO can't create a revision w/o CDOID
- return instantiate(null);
- }
-
- public Object instantiate(Serializable key)
- {
- final HibernateStoreAccessor storeAccessor = HibernateThreadContext.getCurrentStoreAccessor();
- HibernateStore store = storeAccessor.getStore();
- final CDOID id = HibernateUtil.getInstance().createCDOID(classifierRef, key);
- final InternalCDORevision revision = store.createRevision(eClass, id);
- revision.setBranchPoint(storeAccessor.getStore().getMainBranchHead());
- return revision;
- }
-
- public boolean isInstance(Object object)
- {
- return object instanceof InternalCDORevision;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.model.CDOClassifierRef; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateThreadContext; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.eclipse.emf.ecore.EClass; + +import org.hibernate.mapping.PersistentClass; +import org.hibernate.tuple.Instantiator; + +import java.io.Serializable; + +/** + * @author Eike Stepper + */ +public class CDORevisionInstantiator implements Instantiator +{ + private static final long serialVersionUID = 1L; + + private final EClass eClass; + + private final CDOClassifierRef classifierRef; + + public CDORevisionInstantiator(CDORevisionTuplizer tuplizer, PersistentClass mappingInfo) + { + eClass = tuplizer.getEClass(); + classifierRef = new CDOClassifierRef(eClass); + } + + public Object instantiate() + { + // TODO CDO can't create a revision w/o CDOID + return instantiate(null); + } + + public Object instantiate(Serializable key) + { + final HibernateStoreAccessor storeAccessor = HibernateThreadContext.getCurrentStoreAccessor(); + HibernateStore store = storeAccessor.getStore(); + final CDOID id = HibernateUtil.getInstance().createCDOID(classifierRef, key); + final InternalCDORevision revision = store.createRevision(eClass, id); + revision.setBranchPoint(storeAccessor.getStore().getMainBranchHead()); + return revision; + } + + public boolean isInstance(Object object) + { + return object instanceof InternalCDORevision; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java index ca28021bfa..342c0999ec 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDORevisionProxyHibernate.java @@ -1,54 +1,54 @@ -/*
- * Copyright (c) 2004 - 2012 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.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.spi.common.revision.DelegatingCDORevision;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.hibernate.proxy.HibernateProxy;
-import org.hibernate.proxy.LazyInitializer;
-
-/**
- * @author Eike Stepper
- */
-public class CDORevisionProxyHibernate extends DelegatingCDORevision implements HibernateProxy
-{
- private static final long serialVersionUID = 1L;
-
- private CDORevisionLazyInitializer li;
-
- CDORevisionProxyHibernate(CDORevisionLazyInitializer li)
- {
- this.li = li;
- }
-
- @Override
- public InternalCDORevision copy()
- {
- return new CDORevisionProxyHibernate(li);
- }
-
- @Override
- public InternalCDORevision getDelegate()
- {
- return li.getRevision();
- }
-
- public LazyInitializer getHibernateLazyInitializer()
- {
- return li;
- }
-
- public Object writeReplace()
- {
- return this;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.spi.common.revision.DelegatingCDORevision; +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.hibernate.proxy.HibernateProxy; +import org.hibernate.proxy.LazyInitializer; + +/** + * @author Eike Stepper + */ +public class CDORevisionProxyHibernate extends DelegatingCDORevision implements HibernateProxy +{ + private static final long serialVersionUID = 1L; + + private CDORevisionLazyInitializer li; + + CDORevisionProxyHibernate(CDORevisionLazyInitializer li) + { + this.li = li; + } + + @Override + public InternalCDORevision copy() + { + return new CDORevisionProxyHibernate(li); + } + + @Override + public InternalCDORevision getDelegate() + { + return li.getRevision(); + } + + public LazyInitializer getHibernateLazyInitializer() + { + return li; + } + + public Object writeReplace() + { + return this; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertyGetter.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertyGetter.java index 37eb8ed5b4..6aed99fb34 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertyGetter.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/CDOVersionPropertyGetter.java @@ -1,50 +1,50 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - copied from CDORevisionPropertyHandler and adapted
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.hibernate.HibernateException;
-
-/**
- * @author Martin Taal
- */
-public class CDOVersionPropertyGetter extends CDOPropertyGetter
-{
- private static final long serialVersionUID = 1L;
-
- public CDOVersionPropertyGetter(CDORevisionTuplizer tuplizer, String propertyName)
- {
- super(tuplizer, propertyName);
- }
-
- @Override
- public Object get(Object target) throws HibernateException
- {
- InternalCDORevision revision = (InternalCDORevision)target;
- if (isVirtualProperty())
- {
- return revision.getVersion();
- }
-
- Object version = super.get(target);
- // TODO: does this make sense?
- // revision.setVersion(((Number)value).intValue());
- return version;
- }
-
- @Override
- protected boolean isVirtualPropertyAllowed()
- {
- return true;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - copied from CDORevisionPropertyHandler and adapted + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision; + +import org.hibernate.HibernateException; + +/** + * @author Martin Taal + */ +public class CDOVersionPropertyGetter extends CDOPropertyGetter +{ + private static final long serialVersionUID = 1L; + + public CDOVersionPropertyGetter(CDORevisionTuplizer tuplizer, String propertyName) + { + super(tuplizer, propertyName); + } + + @Override + public Object get(Object target) throws HibernateException + { + InternalCDORevision revision = (InternalCDORevision)target; + if (isVirtualProperty()) + { + return revision.getVersion(); + } + + Object version = super.get(target); + // TODO: does this make sense? + // revision.setVersion(((Number)value).intValue()); + return version; + } + + @Override + protected boolean isVirtualPropertyAllowed() + { + return true; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryInstantiator.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryInstantiator.java index df9cc59f13..5f00276d3f 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryInstantiator.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryInstantiator.java @@ -1,51 +1,51 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial api
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
-import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureMapEntry;
-
-import org.hibernate.mapping.Component;
-import org.hibernate.tuple.Instantiator;
-
-import java.io.Serializable;
-
-/**
- * Instantiates {@link CDOFeatureMapEntry}.
- *
- * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- */
-
-public class FeatureMapEntryInstantiator implements Instantiator
-{
- private static final long serialVersionUID = -1219767393020090471L;
-
- public FeatureMapEntryInstantiator(Component component)
- {
- }
-
- public Object instantiate()
- {
- final CDOFeatureMapEntry fme = CDORevisionUtil.createCDOFeatureMapEntry();
- return fme;
- }
-
- public Object instantiate(Serializable id)
- {
- return instantiate();
- }
-
- public boolean isInstance(Object object)
- {
- return CDOFeatureMapEntry.class.isInstance(object);
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial api + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; +import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureMapEntry; + +import org.hibernate.mapping.Component; +import org.hibernate.tuple.Instantiator; + +import java.io.Serializable; + +/** + * Instantiates {@link CDOFeatureMapEntry}. + * + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + */ + +public class FeatureMapEntryInstantiator implements Instantiator +{ + private static final long serialVersionUID = -1219767393020090471L; + + public FeatureMapEntryInstantiator(Component component) + { + } + + public Object instantiate() + { + final CDOFeatureMapEntry fme = CDORevisionUtil.createCDOFeatureMapEntry(); + return fme; + } + + public Object instantiate(Serializable id) + { + return instantiate(); + } + + public boolean isInstance(Object object) + { + return CDOFeatureMapEntry.class.isInstance(object); + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryTuplizer.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryTuplizer.java index cf29cc6e0e..6ce109816c 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryTuplizer.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/FeatureMapEntryTuplizer.java @@ -1,121 +1,121 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial api
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateConstants;
-import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureMapEntry;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
-
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Property;
-import org.hibernate.property.Getter;
-import org.hibernate.property.PropertyAccessor;
-import org.hibernate.property.Setter;
-import org.hibernate.tuple.Instantiator;
-import org.hibernate.tuple.component.AbstractComponentTuplizer;
-
-/**
- * Tuplizer for feature map entries. These types are mapped using the dynamic capabilities of Hibernate.
- *
- * @see CDOFeatureMapEntry
- * @see FeatureMapEntryPropertyHandler
- * @see FeatureMapEntryFeatureURIPropertyHandler
- * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
- */
-
-public class FeatureMapEntryTuplizer extends AbstractComponentTuplizer
-{
- private static final long serialVersionUID = 1L;
-
- private static final EStructuralFeature TEXT = XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Text();
-
- private static final EStructuralFeature CDATA = XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_CDATA();
-
- private static final EStructuralFeature COMMENT = XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Comment();
-
- public FeatureMapEntryTuplizer(Component component)
- {
- super(component);
- }
-
- @Override
- protected Instantiator buildInstantiator(Component component)
- {
- return new FeatureMapEntryInstantiator(component);
- }
-
- @Override
- protected Getter buildGetter(Component component, Property prop)
- {
- return getPropertyAccessor(prop, component).getGetter(component.getComponentClass(), prop.getName());
- }
-
- @Override
- protected Setter buildSetter(Component component, Property prop)
- {
- return getPropertyAccessor(prop, component).getSetter(component.getComponentClass(), prop.getName());
- }
-
- protected PropertyAccessor getPropertyAccessor(Property mappedProperty, Component component)
- {
- if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_FEATURE) == 0)
- {
- return new FeatureMapEntryFeatureURIPropertyHandler();
- }
- else if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_COMMENT) == 0)
- {
- final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler();
- propertyHandler.setPropertyName(COMMENT.getName());
- return propertyHandler;
- }
- else if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_CDATA) == 0)
- {
- final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler();
- propertyHandler.setPropertyName(CDATA.getName());
- return propertyHandler;
- }
- else if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_TEXT) == 0)
- {
- final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler();
- propertyHandler.setPropertyName(TEXT.getName());
- return propertyHandler;
- }
- else if (mappedProperty.getName().endsWith(CDOHibernateConstants.FEATUREMAP_PROPERTY_ANY_PRIMITIVE))
- {
- final WildCardAttributePropertyHandler propertyHandler = new WildCardAttributePropertyHandler();
- final int index = mappedProperty.getName().lastIndexOf(CDOHibernateConstants.PROPERTY_SEPARATOR);
- final String propName = mappedProperty.getName().substring(0, index);
- propertyHandler.setPropertyName(propName);
- return propertyHandler;
- }
- else if (mappedProperty.getName().endsWith(CDOHibernateConstants.FEATUREMAP_PROPERTY_ANY_REFERENCE))
- {
- final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler();
- final int index = mappedProperty.getName().lastIndexOf(CDOHibernateConstants.PROPERTY_SEPARATOR);
- final String propName = mappedProperty.getName().substring(0, index);
- propertyHandler.setPropertyName(propName);
- return propertyHandler;
- }
-
- final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler();
- propertyHandler.setPropertyName(mappedProperty.getName());
- return propertyHandler;
- }
-
- @SuppressWarnings("rawtypes")
- public Class getMappedClass()
- {
- return CDOFeatureMapEntry.class;
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial api + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.server.internal.hibernate.CDOHibernateConstants; +import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureMapEntry; + +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.xml.type.XMLTypePackage; + +import org.hibernate.mapping.Component; +import org.hibernate.mapping.Property; +import org.hibernate.property.Getter; +import org.hibernate.property.PropertyAccessor; +import org.hibernate.property.Setter; +import org.hibernate.tuple.Instantiator; +import org.hibernate.tuple.component.AbstractComponentTuplizer; + +/** + * Tuplizer for feature map entries. These types are mapped using the dynamic capabilities of Hibernate. + * + * @see CDOFeatureMapEntry + * @see FeatureMapEntryPropertyHandler + * @see FeatureMapEntryFeatureURIPropertyHandler + * @author <a href="mailto:mtaal@elver.org">Martin Taal</a> + */ + +public class FeatureMapEntryTuplizer extends AbstractComponentTuplizer +{ + private static final long serialVersionUID = 1L; + + private static final EStructuralFeature TEXT = XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Text(); + + private static final EStructuralFeature CDATA = XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_CDATA(); + + private static final EStructuralFeature COMMENT = XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot_Comment(); + + public FeatureMapEntryTuplizer(Component component) + { + super(component); + } + + @Override + protected Instantiator buildInstantiator(Component component) + { + return new FeatureMapEntryInstantiator(component); + } + + @Override + protected Getter buildGetter(Component component, Property prop) + { + return getPropertyAccessor(prop, component).getGetter(component.getComponentClass(), prop.getName()); + } + + @Override + protected Setter buildSetter(Component component, Property prop) + { + return getPropertyAccessor(prop, component).getSetter(component.getComponentClass(), prop.getName()); + } + + protected PropertyAccessor getPropertyAccessor(Property mappedProperty, Component component) + { + if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_FEATURE) == 0) + { + return new FeatureMapEntryFeatureURIPropertyHandler(); + } + else if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_COMMENT) == 0) + { + final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler(); + propertyHandler.setPropertyName(COMMENT.getName()); + return propertyHandler; + } + else if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_CDATA) == 0) + { + final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler(); + propertyHandler.setPropertyName(CDATA.getName()); + return propertyHandler; + } + else if (mappedProperty.getName().compareToIgnoreCase(CDOHibernateConstants.FEATUREMAP_PROPERTY_TEXT) == 0) + { + final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler(); + propertyHandler.setPropertyName(TEXT.getName()); + return propertyHandler; + } + else if (mappedProperty.getName().endsWith(CDOHibernateConstants.FEATUREMAP_PROPERTY_ANY_PRIMITIVE)) + { + final WildCardAttributePropertyHandler propertyHandler = new WildCardAttributePropertyHandler(); + final int index = mappedProperty.getName().lastIndexOf(CDOHibernateConstants.PROPERTY_SEPARATOR); + final String propName = mappedProperty.getName().substring(0, index); + propertyHandler.setPropertyName(propName); + return propertyHandler; + } + else if (mappedProperty.getName().endsWith(CDOHibernateConstants.FEATUREMAP_PROPERTY_ANY_REFERENCE)) + { + final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler(); + final int index = mappedProperty.getName().lastIndexOf(CDOHibernateConstants.PROPERTY_SEPARATOR); + final String propName = mappedProperty.getName().substring(0, index); + propertyHandler.setPropertyName(propName); + return propertyHandler; + } + + final FeatureMapEntryPropertyHandler propertyHandler = new FeatureMapEntryPropertyHandler(); + propertyHandler.setPropertyName(mappedProperty.getName()); + return propertyHandler; + } + + @SuppressWarnings("rawtypes") + public Class getMappedClass() + { + return CDOFeatureMapEntry.class; + } +} diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java index 1eb3ec02c5..660c56cb4b 100644 --- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java +++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/tuplizer/HibernateMoveableListWrapper.java @@ -1,401 +1,401 @@ -/*
- * Copyright (c) 2004 - 2012 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:
- * Martin Taal - initial api
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDExternal;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil;
-
-import org.eclipse.net4j.util.collection.MoveableList;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * Wraps a moveable list so that hibernate always sees an object view while cdo always sees a cdoid view. The same for
- * EEnum: cdo wants to see an int (the ordinal), hibernate the real eenum value. This to support querying with EENum
- * parameters.
- *
- * @author Martin Taal
- */
-public class HibernateMoveableListWrapper implements MoveableList<Object>
-{
- private List<Object> delegate;
-
- public HibernateMoveableListWrapper()
- {
- }
-
- public Object move(int targetIndex, int sourceIndex)
- {
- int size = size();
- if (sourceIndex >= size)
- {
- throw new IndexOutOfBoundsException("sourceIndex=" + sourceIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (targetIndex >= size)
- {
- throw new IndexOutOfBoundsException("targetIndex=" + targetIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- Object object = get(sourceIndex);
- if (targetIndex == sourceIndex)
- {
- return object;
- }
-
- if (targetIndex < sourceIndex)
- {
- moveUp1(targetIndex, sourceIndex - targetIndex);
- }
- else
- {
- moveDown1(targetIndex, targetIndex - sourceIndex);
- }
-
- set(targetIndex, object);
- return object;
- }
-
- private void moveUp1(int index, int count)
- {
- for (int i = count; i > 0; i--)
- {
- set(index + i, get(index + i - 1));
- }
- }
-
- private void moveDown1(int index, int count)
- {
- for (int i = count; i > 0; i--)
- {
- set(index - i, get(index - i + 1));
- }
- }
-
- /**
- * @return the delegate
- */
- public List<Object> getDelegate()
- {
- return delegate;
- }
-
- /**
- * @param delegate
- * the delegate to set
- */
- public void setDelegate(List<Object> delegate)
- {
- this.delegate = delegate;
- }
-
- protected Object getObject(Object o)
- {
- if (o == null)
- {
- return null;
- }
-
- if (o instanceof CDOID && CDOIDUtil.isNull((CDOID)o))
- {
- return null;
- }
- else if (o instanceof CDOIDExternal)
- {
- return o;
- }
-
- // is already resolved
- if (!(o instanceof CDOID))
- {
- return o;
- }
-
- return HibernateUtil.getInstance().getCDORevision((CDOID)o);
- }
-
- protected List<Object> getObjects(List<?> ids)
- {
- List<Object> result = new ArrayList<Object>();
- for (Object o : ids)
- {
- result.add(getObject(o));
- }
-
- return result;
- }
-
- protected Object getValue(Object o)
- {
- if (o instanceof CDOIDExternal)
- {
- return o;
- }
-
- // can happen for primitive typed lists
- if (!(o instanceof CDORevision))
- {
- return o;
- }
-
- return HibernateUtil.getInstance().getCDOID(o);
- }
-
- protected List<Object> getValues(Collection<?> c)
- {
- List<Object> newC = new ArrayList<Object>();
- for (Object o : c)
- {
- newC.add(getValue(o));
- }
-
- return newC;
- }
-
- public void add(int index, Object element)
- {
- getDelegate().add(index, getValue(element));
- }
-
- public boolean add(Object o)
- {
- return getDelegate().add(getValue(o));
- }
-
- public boolean addAll(Collection<? extends Object> c)
- {
- return getDelegate().addAll(getValues(c));
- }
-
- public boolean addAll(int index, Collection<? extends Object> c)
- {
- return getDelegate().addAll(index, getValues(c));
- }
-
- public void clear()
- {
- getDelegate().clear();
- }
-
- public boolean contains(Object o)
- {
- return getDelegate().contains(getValue(o));
- }
-
- public boolean containsAll(Collection<?> c)
- {
- return getDelegate().containsAll(getValues(c));
- }
-
- public Object get(int index)
- {
- return getObject(getDelegate().get(index));
- }
-
- public int indexOf(Object o)
- {
- return getDelegate().indexOf(getValue(o));
- }
-
- public boolean isEmpty()
- {
- return getDelegate().isEmpty();
- }
-
- public Iterator<Object> iterator()
- {
- return new CDOHibernateIterator(getDelegate().iterator());
- }
-
- public int lastIndexOf(Object o)
- {
- return getDelegate().lastIndexOf(getValue(o));
- }
-
- public ListIterator<Object> listIterator()
- {
- return new CDOHibernateListIterator(getDelegate().listIterator());
- }
-
- public ListIterator<Object> listIterator(int index)
- {
- return new CDOHibernateListIterator(getDelegate().listIterator(index));
- }
-
- public Object remove(int index)
- {
- return getDelegate().remove(index);
- }
-
- public boolean remove(Object o)
- {
- return getDelegate().remove(getValue(o));
- }
-
- public boolean removeAll(Collection<?> c)
- {
- return getDelegate().removeAll(getValues(c));
- }
-
- public boolean retainAll(Collection<?> c)
- {
- return getDelegate().retainAll(getValues(c));
- }
-
- public Object set(int index, Object element)
- {
- return getDelegate().set(index, getValue(element));
- }
-
- public int size()
- {
- return getDelegate().size();
- }
-
- public List<Object> subList(int fromIndex, int toIndex)
- {
- return getObjects(getDelegate().subList(fromIndex, toIndex));
- }
-
- public Object[] toArray()
- {
- Object[] result = new Object[size()];
- int i = 0;
- for (Object o : this)
- {
- result[i++] = o;
- }
-
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public <T> T[] toArray(T[] a)
- {
- int i = 0;
- for (Object o : this)
- {
- a[i++] = (T)o;
- }
-
- return a;
- }
-
- private static final class CDOHibernateIterator implements Iterator<Object>
- {
- private final Iterator<?> delegate;
-
- public CDOHibernateIterator(Iterator<?> delegate)
- {
- this.delegate = delegate;
- }
-
- public boolean hasNext()
- {
- return delegate.hasNext();
- }
-
- public Object next()
- {
- Object o = delegate.next();
- if (o instanceof CDOIDExternal)
- {
- return o;
- }
- else if (o instanceof CDOID)
- {
- return HibernateUtil.getInstance().getCDORevision((CDOID)o);
- }
-
- return o;
- }
-
- public void remove()
- {
- delegate.remove();
- }
- }
-
- private static final class CDOHibernateListIterator implements ListIterator<Object>
- {
- private final ListIterator<Object> delegate;
-
- public CDOHibernateListIterator(ListIterator<Object> delegate)
- {
- this.delegate = delegate;
- }
-
- public void add(Object o)
- {
- delegate.add(HibernateUtil.getInstance().getCDOID(o));
- }
-
- public boolean hasNext()
- {
- return delegate.hasNext();
- }
-
- public boolean hasPrevious()
- {
- return delegate.hasPrevious();
- }
-
- public Object next()
- {
- Object o = delegate.next();
- if (o instanceof CDOID)
- {
- return HibernateUtil.getInstance().getCDORevision((CDOID)delegate.next());
- }
-
- return o;
- }
-
- public int nextIndex()
- {
- return delegate.nextIndex();
- }
-
- public Object previous()
- {
- Object o = delegate.previous();
- if (o instanceof CDOID)
- {
- return HibernateUtil.getInstance().getCDORevision((CDOID)delegate.next());
- }
-
- return o;
- }
-
- public int previousIndex()
- {
- return delegate.previousIndex();
- }
-
- public void remove()
- {
- delegate.remove();
- }
-
- public void set(Object o)
- {
- delegate.set(HibernateUtil.getInstance().getCDOID(o));
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 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: + * Martin Taal - initial api + * Eike Stepper - maintenance + */ +package org.eclipse.emf.cdo.server.internal.hibernate.tuplizer; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDExternal; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.server.internal.hibernate.HibernateUtil; + +import org.eclipse.net4j.util.collection.MoveableList; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +/** + * Wraps a moveable list so that hibernate always sees an object view while cdo always sees a cdoid view. The same for + * EEnum: cdo wants to see an int (the ordinal), hibernate the real eenum value. This to support querying with EENum + * parameters. + * + * @author Martin Taal + */ +public class HibernateMoveableListWrapper implements MoveableList<Object> +{ + private List<Object> delegate; + + public HibernateMoveableListWrapper() + { + } + + public Object move(int targetIndex, int sourceIndex) + { + int size = size(); + if (sourceIndex >= size) + { + throw new IndexOutOfBoundsException("sourceIndex=" + sourceIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$ + } + + if (targetIndex >= size) + { + throw new IndexOutOfBoundsException("targetIndex=" + targetIndex + ", size=" + size); //$NON-NLS-1$ //$NON-NLS-2$ + } + + Object object = get(sourceIndex); + if (targetIndex == sourceIndex) + { + return object; + } + + if (targetIndex < sourceIndex) + { + moveUp1(targetIndex, sourceIndex - targetIndex); + } + else + { + moveDown1(targetIndex, targetIndex - sourceIndex); + } + + set(targetIndex, object); + return object; + } + + private void moveUp1(int index, int count) + { + for (int i = count; i > 0; i--) + { + set(index + i, get(index + i - 1)); + } + } + + private void moveDown1(int index, int count) + { + for (int i = count; i > 0; i--) + { + set(index - i, get(index - i + 1)); + } + } + + /** + * @return the delegate + */ + public List<Object> getDelegate() + { + return delegate; + } + + /** + * @param delegate + * the delegate to set + */ + public void setDelegate(List<Object> delegate) + { + this.delegate = delegate; + } + + protected Object getObject(Object o) + { + if (o == null) + { + return null; + } + + if (o instanceof CDOID && CDOIDUtil.isNull((CDOID)o)) + { + return null; + } + else if (o instanceof CDOIDExternal) + { + return o; + } + + // is already resolved + if (!(o instanceof CDOID)) + { + return o; + } + + return HibernateUtil.getInstance().getCDORevision((CDOID)o); + } + + protected List<Object> getObjects(List<?> ids) + { + List<Object> result = new ArrayList<Object>(); + for (Object o : ids) + { + result.add(getObject(o)); + } + + return result; + } + + protected Object getValue(Object o) + { + if (o instanceof CDOIDExternal) + { + return o; + } + + // can happen for primitive typed lists + if (!(o instanceof CDORevision)) + { + return o; + } + + return HibernateUtil.getInstance().getCDOID(o); + } + + protected List<Object> getValues(Collection<?> c) + { + List<Object> newC = new ArrayList<Object>(); + for (Object o : c) + { + newC.add(getValue(o)); + } + + return newC; + } + + public void add(int index, Object element) + { + getDelegate().add(index, getValue(element)); + } + + public boolean add(Object o) + { + return getDelegate().add(getValue(o)); + } + + public boolean addAll(Collection<? extends Object> c) + { + return getDelegate().addAll(getValues(c)); + } + + public boolean addAll(int index, Collection<? extends Object> c) + { + return getDelegate().addAll(index, getValues(c)); + } + + public void clear() + { + getDelegate().clear(); + } + + public boolean contains(Object o) + { + return getDelegate().contains(getValue(o)); + } + + public boolean containsAll(Collection<?> c) + { + return getDelegate().containsAll(getValues(c)); + } + + public Object get(int index) + { + return getObject(getDelegate().get(index)); + } + + public int indexOf(Object o) + { + return getDelegate().indexOf(getValue(o)); + } + + public boolean isEmpty() + { + return getDelegate().isEmpty(); + } + + public Iterator<Object> iterator() + { + return new CDOHibernateIterator(getDelegate().iterator()); + } + + public int lastIndexOf(Object o) + { + return getDelegate().lastIndexOf(getValue(o)); + } + + public ListIterator<Object> listIterator() + { + return new CDOHibernateListIterator(getDelegate().listIterator()); + } + + public ListIterator<Object> listIterator(int index) + { + return new CDOHibernateListIterator(getDelegate().listIterator(index)); + } + + public Object remove(int index) + { + return getDelegate().remove(index); + } + + public boolean remove(Object o) + { + return getDelegate().remove(getValue(o)); + } + + public boolean removeAll(Collection<?> c) + { + return getDelegate().removeAll(getValues(c)); + } + + public boolean retainAll(Collection<?> c) + { + return getDelegate().retainAll(getValues(c)); + } + + public Object set(int index, Object element) + { + return getDelegate().set(index, getValue(element)); + } + + public int size() + { + return getDelegate().size(); + } + + public List<Object> subList(int fromIndex, int toIndex) + { + return getObjects(getDelegate().subList(fromIndex, toIndex)); + } + + public Object[] toArray() + { + Object[] result = new Object[size()]; + int i = 0; + for (Object o : this) + { + result[i++] = o; + } + + return result; + } + + @SuppressWarnings("unchecked") + public <T> T[] toArray(T[] a) + { + int i = 0; + for (Object o : this) + { + a[i++] = (T)o; + } + + return a; + } + + private static final class CDOHibernateIterator implements Iterator<Object> + { + private final Iterator<?> delegate; + + public CDOHibernateIterator(Iterator<?> delegate) + { + this.delegate = delegate; + } + + public boolean hasNext() + { + return delegate.hasNext(); + } + + public Object next() + { + Object o = delegate.next(); + if (o instanceof CDOIDExternal) + { + return o; + } + else if (o instanceof CDOID) + { + return HibernateUtil.getInstance().getCDORevision((CDOID)o); + } + + return o; + } + + public void remove() + { + delegate.remove(); + } + } + + private static final class CDOHibernateListIterator implements ListIterator<Object> + { + private final ListIterator<Object> delegate; + + public CDOHibernateListIterator(ListIterator<Object> delegate) + { + this.delegate = delegate; + } + + public void add(Object o) + { + delegate.add(HibernateUtil.getInstance().getCDOID(o)); + } + + public boolean hasNext() + { + return delegate.hasNext(); + } + + public boolean hasPrevious() + { + return delegate.hasPrevious(); + } + + public Object next() + { + Object o = delegate.next(); + if (o instanceof CDOID) + { + return HibernateUtil.getInstance().getCDORevision((CDOID)delegate.next()); + } + + return o; + } + + public int nextIndex() + { + return delegate.nextIndex(); + } + + public Object previous() + { + Object o = delegate.previous(); + if (o instanceof CDOID) + { + return HibernateUtil.getInstance().getCDORevision((CDOID)delegate.next()); + } + + return o; + } + + public int previousIndex() + { + return delegate.previousIndex(); + } + + public void remove() + { + delegate.remove(); + } + + public void set(Object o) + { + delegate.set(HibernateUtil.getInstance().getCDOID(o)); + } + } +} |