Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2009-07-06 11:48:45 +0000
committerMartin Taal2009-07-06 11:48:45 +0000
commitaf4c09f0e5893535eaf8cc36895dbfe032d6a247 (patch)
tree3aee97f85ff5aa68569b2cf48aa11584008eb084 /plugins
parent838f955a34001c24808c1fded2f9830e2faeacd0 (diff)
downloadcdo-af4c09f0e5893535eaf8cc36895dbfe032d6a247.tar.gz
cdo-af4c09f0e5893535eaf8cc36895dbfe032d6a247.tar.xz
cdo-af4c09f0e5893535eaf8cc36895dbfe032d6a247.zip
Changed the persisting of CDOPackageUnits and mapping to hibernate
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml14
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnit.java396
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnitDTO.java110
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java96
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java4
5 files changed, 171 insertions, 449 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml
index eea45e5cab..20abd9499e 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/mappings/meta.hbm.xml
@@ -2,15 +2,16 @@
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.eclipse.emf.cdo.internal.common.model">
- <class name="org.eclipse.emf.cdo.server.internal.hibernate.HibernateCDOPackageUnit" table="cdo_package_unit" lazy="false" entity-name="CDOPackageUnit">
+ <class name="org.eclipse.emf.cdo.server.internal.hibernate.HibernateCDOPackageUnitDTO" table="cdo_package_unit" lazy="false" entity-name="CDOPackageUnit">
<id name="nsUri" access="property"/>
- <property name="type" access="field" />
<property name="originalType" access="field" />
<property name="timeStamp" access="field" />
- <array name="packageInfos" cascade="all, delete-orphan" access="field" inverse="true">
+ <property name="EPackageBlob" access="property" length="40000"/>
+
+ <array name="packageInfos" cascade="all, delete-orphan" access="field">
<key column="cdo_package_unit_id"/>
<list-index column="idx"/>
<one-to-many class="CDOPackageInfoImpl"/>
@@ -22,8 +23,6 @@
<id name="packageURI" access="property"/>
- <many-to-one name="packageUnit" entity-name="CDOPackageUnit" not-null="true" column="cdo_package_unit_id" access="field"/>
-
<property name="parentURI" length="255" access="field" />
<property name="metaIDRange" type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDMetaRangeUserType"
not-null="true" access="field">
@@ -32,11 +31,6 @@
</property>
</class>
- <class name="org.eclipse.emf.cdo.server.internal.hibernate.HibernateEPackage" table="cdo_hibernate_epackage" lazy="false">
- <id name="nsUri" access="property"/>
- <property name="EPackageBlob" access="property" length="10000"/>
- </class>
-
<class name="org.eclipse.emf.cdo.server.internal.hibernate.SystemInformation" table="cdo_system_information" lazy="false">
<id column="id" type="int">
<generator class="native" />
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnit.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnit.java
deleted file mode 100644
index 0cf846ef9a..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnit.java
+++ /dev/null
@@ -1,396 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Martin Taal and others. 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.io.CDODataInput;
-import org.eclipse.emf.cdo.common.io.CDODataOutput;
-import org.eclipse.emf.cdo.common.model.CDOModelUtil;
-import org.eclipse.emf.cdo.common.model.CDOPackageTypeRegistry;
-import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
-import org.eclipse.emf.cdo.common.model.EMFUtil;
-import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
-import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-
-import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Represents the CDOPackageUnitImpl as a Hibernate persistable object.
- *
- * @author Martin Taal
- */
-public class HibernateCDOPackageUnit implements InternalCDOPackageUnit
-{
- private String nsUri;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HibernateCDOPackageUnit.class);
-
- private InternalCDOPackageRegistry packageRegistry;
-
- private State state = State.PROXY;
-
- private Type type;
-
- private Type originalType;
-
- private long timeStamp;
-
- private InternalCDOPackageInfo[] packageInfos;
-
- public HibernateCDOPackageUnit()
- {
- }
-
- public HibernateCDOPackageUnit(CDOPackageUnit cdoPackageUnit)
- {
- setType(cdoPackageUnit.getType());
- setPackageInfos((InternalCDOPackageInfo[])cdoPackageUnit.getPackageInfos());
- setOriginalType(cdoPackageUnit.getOriginalType());
- setPackageRegistry((InternalCDOPackageRegistry)cdoPackageUnit.getPackageRegistry());
- setTimeStamp(cdoPackageUnit.getTimeStamp());
- }
-
- public String getNsUri()
- {
- if (nsUri == null)
- {
- nsUri = getPackageInfos()[0].getPackageURI();
- }
-
- return nsUri;
- }
-
- public void setNsUri(String nsUri)
- {
- this.nsUri = nsUri;
- }
-
- public InternalCDOPackageRegistry getPackageRegistry()
- {
- return packageRegistry;
- }
-
- public void setPackageRegistry(InternalCDOPackageRegistry packageRegistry)
- {
- this.packageRegistry = packageRegistry;
- }
-
- public String getID()
- {
- try
- {
- return getTopLevelPackageInfo().getPackageURI();
- }
- catch (RuntimeException ex)
- {
- return "UNINITIALIZED";
- }
- }
-
- public State getState()
- {
- return state;
- }
-
- public void setState(State state)
- {
- this.state = state;
- if (state == State.LOADED)
- {
- type = null;
- }
- }
-
- public Type getType()
- {
- if (getOriginalType() == Type.DYNAMIC)
- {
- type = Type.DYNAMIC;
- }
- else if (type == null || type == Type.UNKNOWN)
- {
- if (state == State.PROXY)
- {
- type = CDOPackageTypeRegistry.INSTANCE.lookup(getID());
- }
- else
- {
- InternalCDOPackageInfo packageInfo = getTopLevelPackageInfo();
- EPackage ePackage = packageInfo.getEPackage();
- type = CDOPackageTypeRegistry.INSTANCE.lookup(ePackage);
- }
-
- if (type == null)
- {
- type = Type.UNKNOWN;
- }
- }
-
- return type;
- }
-
- public Type getOriginalType()
- {
- return originalType;
- }
-
- public void setOriginalType(Type originalType)
- {
- this.originalType = originalType;
- }
-
- public long getTimeStamp()
- {
- return timeStamp;
- }
-
- public void setTimeStamp(long timeStamp)
- {
- this.timeStamp = timeStamp;
- }
-
- public InternalCDOPackageInfo getTopLevelPackageInfo()
- {
- if (packageInfos == null || packageInfos.length == 0)
- {
- throw new IllegalStateException("Package unit not initialized");
- }
-
- return packageInfos[0];
- }
-
- public InternalCDOPackageInfo getPackageInfo(String packageURI)
- {
- for (InternalCDOPackageInfo packageInfo : packageInfos)
- {
- if (packageInfo.getPackageURI().equals(packageURI))
- {
- return packageInfo;
- }
- }
-
- return null;
- }
-
- public InternalCDOPackageInfo[] getPackageInfos()
- {
- return packageInfos;
- }
-
- public void setPackageInfos(InternalCDOPackageInfo[] packageInfos)
- {
- this.packageInfos = packageInfos;
- for (InternalCDOPackageInfo packageInfo : packageInfos)
- {
- packageInfo.setPackageUnit(this);
- }
- }
-
- public EPackage[] getEPackages(boolean loadOnDemand)
- {
- List<EPackage> result = new ArrayList<EPackage>();
- for (InternalCDOPackageInfo packageInfo : packageInfos)
- {
- EPackage ePackage = packageInfo.getEPackage(loadOnDemand);
- if (ePackage != null)
- {
- result.add(ePackage);
- }
- }
-
- return result.toArray(new EPackage[result.size()]);
- }
-
- public boolean isSystem()
- {
- return getTopLevelPackageInfo().isSystemPackage();
- }
-
- public void init(EPackage ePackage)
- {
- EPackage topLevelPackage = EMFUtil.getTopLevelPackage(ePackage);
- List<InternalCDOPackageInfo> result = new ArrayList<InternalCDOPackageInfo>();
- initPackageInfos(topLevelPackage, result);
- packageInfos = result.toArray(new InternalCDOPackageInfo[result.size()]);
-
- setState(State.NEW);
- originalType = getType();
- }
-
- public void dispose()
- {
- for (InternalCDOPackageInfo packageInfo : packageInfos)
- {
- EPackage ePackage = packageInfo.getEPackage(false);
- if (ePackage != null)
- {
- synchronized (ePackage)
- {
- ePackage.eAdapters().remove(packageInfo);
- }
- }
- }
-
- packageInfos = null;
- setState(State.DISPOSED);
- }
-
- public synchronized void load()
- {
- if (state == State.PROXY)
- {
- EPackage[] ePackages = null;
- ePackages = loadPackagesFromGlobalRegistry();
- if (ePackages == null)
- {
- ePackages = packageRegistry.getPackageLoader().loadPackages(this);
- }
-
- for (EPackage ePackage : ePackages)
- {
- String packageURI = ePackage.getNsURI();
- InternalCDOPackageInfo packageInfo = getPackageInfo(packageURI);
- synchronized (ePackage)
- {
- EMFUtil.addAdapter(ePackage, packageInfo);
- EcoreUtil.resolveAll(ePackage);
- }
- }
-
- setState(State.LOADED);
- }
- }
-
- public void write(CDODataOutput out, boolean withPackages) throws IOException
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Writing {0}", this);
- }
-
- out.writeBoolean(withPackages);
- if (withPackages)
- {
- CDOModelUtil.writePackage(out, packageInfos[0].getEPackage(), true, packageRegistry);
- }
-
- out.writeCDOPackageUnitType(originalType);
- out.writeLong(timeStamp);
- out.writeInt(packageInfos.length);
- for (InternalCDOPackageInfo packageInfo : packageInfos)
- {
- out.writeCDOPackageInfo(packageInfo);
- }
- }
-
- public void read(CDODataInput in, InternalCDOPackageRegistry packageRegistry) throws IOException
- {
- EPackage ePackage = null;
- boolean withPackages = in.readBoolean();
- if (withPackages)
- {
- ePackage = CDOModelUtil.readPackage(in, packageRegistry);
- setState(State.LOADED);
- }
-
- originalType = in.readCDOPackageUnitType();
- timeStamp = in.readLong();
- packageInfos = new InternalCDOPackageInfo[in.readInt()];
- for (int i = 0; i < packageInfos.length; i++)
- {
- packageInfos[i] = (InternalCDOPackageInfo)in.readCDOPackageInfo();
- packageInfos[i].setPackageUnit(this);
- }
-
- if (ePackage != null)
- {
- attachPackageInfos(ePackage);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Read {0}", this);
- }
- }
-
- public int compareTo(CDOPackageUnit o)
- {
- return getID().compareTo(o.getID());
- }
-
- @Override
- public String toString()
- {
- String fmt = "CDOPackageUnit[id={0}, state={1}, type={2}, originalType={3}, timeStamp={4,date} {4,time}]";
- return MessageFormat.format(fmt, getID(), getState(), getType(), getOriginalType(), getTimeStamp());
- }
-
- private void initPackageInfos(EPackage ePackage, List<InternalCDOPackageInfo> result)
- {
- InternalCDOPackageInfo packageInfo = (InternalCDOPackageInfo)CDOModelUtil.createPackageInfo();
- packageInfo.setPackageUnit(this);
- packageInfo.setPackageURI(ePackage.getNsURI());
- packageInfo.setParentURI(ePackage.getESuperPackage() == null ? null : ePackage.getESuperPackage().getNsURI());
- packageInfo.setMetaIDRange(packageRegistry.getMetaInstanceMapper().mapMetaInstances(ePackage));
- EMFUtil.addAdapter(ePackage, packageInfo);
-
- packageRegistry.basicPut(ePackage.getNsURI(), ePackage);
- result.add(packageInfo);
- for (EPackage subPackage : ePackage.getESubpackages())
- {
- initPackageInfos(subPackage, result);
- }
- }
-
- private void attachPackageInfos(EPackage ePackage)
- {
- InternalCDOPackageInfo packageInfo = getPackageInfo(ePackage.getNsURI());
- if (packageInfo != null)
- {
- EMFUtil.addAdapter(ePackage, packageInfo);
- }
-
- for (EPackage subPackage : ePackage.getESubpackages())
- {
- attachPackageInfos(subPackage);
- }
- }
-
- private EPackage[] loadPackagesFromGlobalRegistry()
- {
- EPackage[] ePackages = new EPackage[packageInfos.length];
- for (int i = 0; i < ePackages.length; i++)
- {
- ePackages[i] = EPackage.Registry.INSTANCE.getEPackage(packageInfos[i].getPackageURI());
- if (ePackages[i] == null)
- {
- return null;
- }
- }
-
- return ePackages;
- }
-
- public void setType(Type type)
- {
- this.type = type;
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnitDTO.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnitDTO.java
new file mode 100644
index 0000000000..53ac5d28d8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateCDOPackageUnitDTO.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright (c) 2004 - 2009 Martin Taal and others. 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.model.CDOModelUtil;
+import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
+import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
+import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
+import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
+import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
+
+/**
+ * A DTO for convenience of storing a CDOPackageUnit in the db.
+ *
+ * @author Martin Taal
+ */
+public class HibernateCDOPackageUnitDTO
+{
+ private CDOPackageUnit.Type originalType;
+
+ private long timeStamp;
+
+ private InternalCDOPackageInfo[] packageInfos;
+
+ private byte[] ePackageBlob;
+
+ public HibernateCDOPackageUnitDTO()
+ {
+ }
+
+ public HibernateCDOPackageUnitDTO(CDOPackageUnit cdoPackageUnit)
+ {
+ setPackageInfos((InternalCDOPackageInfo[])cdoPackageUnit.getPackageInfos());
+ setOriginalType(cdoPackageUnit.getOriginalType());
+ setTimeStamp(cdoPackageUnit.getTimeStamp());
+ }
+
+ public CDOPackageUnit.Type getOriginalType()
+ {
+ return originalType;
+ }
+
+ public void setOriginalType(CDOPackageUnit.Type originalType)
+ {
+ this.originalType = originalType;
+ }
+
+ public long getTimeStamp()
+ {
+ return timeStamp;
+ }
+
+ public void setTimeStamp(long timeStamp)
+ {
+ this.timeStamp = timeStamp;
+ }
+
+ public InternalCDOPackageInfo[] getPackageInfos()
+ {
+ return packageInfos;
+ }
+
+ public void setPackageInfos(InternalCDOPackageInfo[] packageInfos)
+ {
+ this.packageInfos = packageInfos;
+ }
+
+ public byte[] getEPackageBlob()
+ {
+ return ePackageBlob;
+ }
+
+ public void setEPackageBlob(byte[] ePackageBlob)
+ {
+ this.ePackageBlob = ePackageBlob;
+ }
+
+ public InternalCDOPackageUnit createCDOPackageUnit(InternalCDOPackageRegistry packageRegistry)
+ {
+ InternalCDOPackageUnit packageUnit = (InternalCDOPackageUnit)CDOModelUtil.createPackageUnit();
+ packageUnit.setOriginalType(originalType);
+ packageUnit.setTimeStamp(timeStamp);
+ packageUnit.setPackageRegistry(packageRegistry);
+ packageUnit.setPackageInfos(packageInfos);
+ for (CDOPackageInfo packageInfo : packageInfos)
+ {
+ ((InternalCDOPackageInfo)packageInfo).setPackageUnit(packageUnit);
+ }
+ return packageUnit;
+ }
+
+ public String getNsUri()
+ {
+ return getPackageInfos()[0].getPackageURI();
+ }
+
+ public void setNsUri(String nsUri)
+ {
+ // ignore
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java
index d40c61ba66..5e3a42d901 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernatePackageHandler.java
@@ -11,6 +11,7 @@
*/
package org.eclipse.emf.cdo.server.internal.hibernate;
+import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.EMFUtil;
import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
@@ -28,13 +29,16 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* Delegate which stores and retrieves cdo packages.
@@ -64,8 +68,14 @@ public class HibernatePackageHandler extends Lifecycle
private Collection<InternalCDOPackageUnit> packageUnits = null;
+ private Map<String, byte[]> ePackageBlobsByRootUri = null;
+
+ private Map<String, EPackage[]> ePackagesByRootUri = null;
+
private HibernateStore hibernateStore;
+ private boolean doDropSchema = false;
+
/**
* TODO Necessary to pass/store/dump the properties from the store?
*/
@@ -107,7 +117,7 @@ public class HibernatePackageHandler extends Lifecycle
// first store and update the packageunits and the epackages
for (InternalCDOPackageUnit packageUnit : packageUnits)
{
- session.saveOrUpdate("CDOPackageUnit", new HibernateCDOPackageUnit(packageUnit));
+ final HibernateCDOPackageUnitDTO hbPackageUnitDTO = new HibernateCDOPackageUnitDTO(packageUnit);
if (packageUnit.getPackageInfos().length > 0)
{
@@ -116,10 +126,11 @@ public class HibernatePackageHandler extends Lifecycle
hbEPackage.setNsUri(rootNSUri);
final EPackage.Registry registry = hibernateStore.getRepository().getPackageRegistry();
final EPackage rootEPackage = registry.getEPackage(rootNSUri);
- hbEPackage.setEPackageBlob(EMFUtil.getEPackageBytes(rootEPackage, true, registry));
- session.saveOrUpdate(hbEPackage);
+ hbPackageUnitDTO.setEPackageBlob(EMFUtil.getEPackageBytes(rootEPackage, true, registry));
}
+ session.saveOrUpdate("CDOPackageUnit", hbPackageUnitDTO);
+
updated = true;
}
@@ -164,38 +175,21 @@ public class HibernatePackageHandler extends Lifecycle
TRACER.trace("Reading EPackages with root uri " + nsUri + " from db");
}
- Session session = getSessionFactory().openSession();
- session.beginTransaction();
- try
+ EPackage[] epacks = ePackagesByRootUri.get(nsUri);
+ if (epacks == null)
{
- Criteria criteria = session.createCriteria(HibernateEPackage.class);
- criteria.add(org.hibernate.criterion.Expression.eq("nsUri", nsUri));
- List<?> list = criteria.list();
- if (list.size() != 1)
- {
- throw new IllegalArgumentException("EPackage with uri " + nsUri + " not present in the db");
- }
-
- if (TRACER.isEnabled())
+ final byte[] ePackageBlob = ePackageBlobsByRootUri.get(nsUri);
+ if (ePackageBlob == null)
{
- TRACER.trace("Found " + list.size() + " EPackages in DB");
+ throw new IllegalArgumentException("EPackages with root uri " + nsUri + " not found");
}
- final HibernateEPackage hbEPackage = (HibernateEPackage)list.get(0);
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read EPackage: " + nsUri);
- }
-
- final EPackage rootEPackage = EMFUtil.createEPackage(nsUri, hbEPackage.getEPackageBlob(), ZIP_PACKAGE_BYTES,
- hibernateStore.getRepository().getPackageRegistry());
- return EMFUtil.getAllPackages(rootEPackage);
- }
- finally
- {
- session.getTransaction().commit();
- session.close();
+ final EPackage rootEPackage = EMFUtil
+ .createEPackage(nsUri, ePackageBlob, ZIP_PACKAGE_BYTES, getPackageRegistry());
+ epacks = EMFUtil.getAllPackages(rootEPackage);
+ ePackagesByRootUri.put(nsUri, epacks);
}
+ return epacks;
}
@SuppressWarnings("unchecked")
@@ -205,7 +199,7 @@ public class HibernatePackageHandler extends Lifecycle
{
if (TRACER.isEnabled())
{
- TRACER.trace("Reading EPackages from db");
+ TRACER.trace("Reading Package Units from db");
}
Session session = getSessionFactory().openSession();
@@ -219,7 +213,17 @@ public class HibernatePackageHandler extends Lifecycle
TRACER.trace("Found " + list.size() + " CDOPackageUnits in DB");
}
- packageUnits = (Collection<InternalCDOPackageUnit>)list;
+ CDOModelUtil.createPackageUnit();
+
+ packageUnits = new ArrayList<InternalCDOPackageUnit>();
+ ePackagesByRootUri = new HashMap<String, EPackage[]>();
+ ePackageBlobsByRootUri = new HashMap<String, byte[]>();
+ for (HibernateCDOPackageUnitDTO dto : (Collection<HibernateCDOPackageUnitDTO>)list)
+ {
+ packageUnits.add(dto.createCDOPackageUnit(getPackageRegistry()));
+ // cache the blob because resolving the epackages right away gives errors
+ ePackageBlobsByRootUri.put(dto.getNsUri(), dto.getEPackageBlob());
+ }
}
finally
{
@@ -229,16 +233,10 @@ public class HibernatePackageHandler extends Lifecycle
if (TRACER.isEnabled())
{
- TRACER.trace("Finished reading EPackages");
+ TRACER.trace("Finished reading Package Units");
}
}
- void doDropSchema()
- {
- final SchemaExport se = new SchemaExport(configuration);
- se.drop(false, true);
- }
-
public synchronized SessionFactory getSessionFactory()
{
if (sessionFactory == null)
@@ -286,7 +284,13 @@ public class HibernatePackageHandler extends Lifecycle
sessionFactory = null;
}
+ if (doDropSchema)
+ {
+ final SchemaExport se = new SchemaExport(configuration);
+ se.drop(false, true);
+ }
configuration = null;
+
super.doDeactivate();
}
@@ -305,6 +309,20 @@ public class HibernatePackageHandler extends Lifecycle
configuration = new Configuration();
configuration.addInputStream(in);
configuration.setProperties(HibernateUtil.getInstance().getPropertiesFromStore(hibernateStore));
+ // prevent the drop at session factory close...
+ // the drop is done by the HibernateStore
+ if (configuration.getProperty(Environment.HBM2DDL_AUTO) != null
+ && configuration.getProperty(Environment.HBM2DDL_AUTO).startsWith("create"))
+ {
+ doDropSchema = true;
+ // note that the value create also re-creates the db and drops the old one
+ configuration.setProperty(Environment.HBM2DDL_AUTO, "update");
+ }
+ else
+ {
+ doDropSchema = false;
+ }
+
}
catch (Exception ex)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
index b02017761e..949690a018 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
@@ -201,10 +201,6 @@ public class HibernateStore extends Store implements IHibernateStore
hibernateConfiguration = null;
LifecycleUtil.deactivate(packageHandler, OMLogger.Level.WARN);
- if (doDropSchema)
- {
- packageHandler.doDropSchema();
- }
super.doDeactivate();
}

Back to the top