001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package org.terracotta.modules.hibernate_3_1_2;
006:
007: import org.osgi.framework.Bundle;
008: import org.osgi.framework.BundleContext;
009: import org.osgi.framework.Constants;
010: import org.terracotta.modules.configuration.TerracottaConfiguratorModule;
011: import org.terracotta.modules.hibernate_3_1_2.object.config.HibernateChangeApplicatorSpec;
012: import org.terracotta.modules.hibernate_3_1_2.object.config.HibernateModuleSpec;
013:
014: import com.tc.object.bytecode.ClassAdapterFactory;
015: import com.tc.object.config.ModuleSpec;
016: import com.tc.object.config.TransparencyClassSpec;
017:
018: import java.util.Dictionary;
019: import java.util.Hashtable;
020:
021: public final class HibernateTerracottaConfigurator extends
022: TerracottaConfiguratorModule {
023: protected final void addInstrumentation(final BundleContext context) {
024: /*
025: * AutoSynchronized lock for AbstractPersistentCollection, PersistentSet, PersistentBag, PersistentList, and
026: * PersistentMap are defined in the terracotta.xml
027: */
028: TransparencyClassSpec spec = configHelper
029: .getOrCreateSpec("org.hibernate.collection.AbstractPersistentCollection");
030: spec.addTransient("session");
031:
032: configHelper.addIncludePattern(
033: "org.hibernate.collection.PersistentSet", false, false,
034: false);
035:
036: configHelper.addIncludePattern(
037: "org.hibernate.collection.PersistentBag", false, false,
038: false);
039:
040: configHelper.addIncludePattern(
041: "org.hibernate.collection.PersistentList", false,
042: false, false);
043:
044: configHelper.addIncludePattern(
045: "org.hibernate.collection.PersistentMap", false, false,
046: false);
047:
048: configHelper
049: .addIncludePattern("org.hibernate.type.ComponentType",
050: false, false, false);
051:
052: configHelper.addIncludePattern("org.hibernate.tuple..*", false,
053: false, false);
054:
055: configHelper.addIncludePattern("org.hibernate.engine..*",
056: false, false, false);
057:
058: configHelper.addIncludePattern("org.hibernate.type..*", false,
059: false, false);
060:
061: configHelper.addIncludePattern("org.hibernate.FetchMode",
062: false, false, false);
063:
064: configHelper.addIncludePattern("org.hibernate.property..*",
065: false, false, false);
066:
067: configHelper.addIncludePattern("org.hibernate.cache.QueryKey",
068: false, false, false);
069:
070: /**
071: * Second level cache begin
072: */
073: configHelper.addIncludePattern("org.hibernate.cache.EhCache",
074: false, false, false);
075: configHelper.addIncludePattern("org.hibernate.cache.CacheKey",
076: false, false, false);
077: configHelper.addIncludePattern(
078: "org.hibernate.cache.EhCacheProvider", false, false,
079: false);
080: configHelper.addIncludePattern("org.hibernate.EntityMode",
081: false, false, false);
082: configHelper.addIncludePattern(
083: "org.hibernate.type.IntegerType", false, false, false);
084: configHelper
085: .addIncludePattern("org.hibernate.type.PrimitiveType",
086: false, false, false);
087: configHelper
088: .addIncludePattern("org.hibernate.type.ImmutableType",
089: false, false, false);
090: configHelper.addIncludePattern(
091: "org.hibernate.type.NullableType", false, false, false);
092: configHelper.addIncludePattern(
093: "org.hibernate.type.AbstractType", false, false, false);
094:
095: configHelper.addIncludePattern(
096: "org.hibernate.cache.ReadWriteCache$Item", false,
097: false, false);
098: configHelper.addIncludePattern(
099: "org.hibernate.cache.ReadWriteCache$Lock", false,
100: false, false);
101: configHelper.addIncludePattern(
102: "org.hibernate.cache.entry.CacheEntry", false, false,
103: false);
104: configHelper.addIncludePattern(
105: "org.hibernate.cache.entry.CollectionCacheEntry",
106: false, false, false);
107: /**
108: * Second level cache ends
109: */
110:
111: configHelper.addIncludePattern(
112: "org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer",
113: false, false, false);
114: configHelper.addIncludePattern(
115: "org.hibernate.proxy.pojo.BasicLazyInitializer", false,
116: false, false);
117: configHelper.addIncludePattern(
118: "org.hibernate.proxy.AbstractLazyInitializer", false,
119: false, false);
120:
121: ClassAdapterFactory factory = new EhcacheClassAdapter();
122: spec = configHelper
123: .getOrCreateSpec("org.hibernate.cache.EhCache");
124: spec.setCustomClassAdapter(factory);
125:
126: factory = new EhcacheProviderClassAdapter();
127: spec = configHelper
128: .getOrCreateSpec("org.hibernate.cache.EhCacheProvider");
129: spec.setCustomClassAdapter(factory);
130:
131: Bundle this Bundle = getExportedBundle(context,
132: "org.terracotta.modules.clustered_hibernate_3.1.2");
133: addExportedBundleClass(this Bundle,
134: "org.terracotta.modules.hibernate_3_1_2.util.HibernateUtil");
135:
136: configHelper
137: .addExcludePattern("org.hibernate.type.TypeFactory");
138: configHelper.addExcludePattern("org.hibernate.engine.Cascade");
139: configHelper
140: .addExcludePattern("org.hibernate.tuple.entity.AbstractEntityTuplizer");
141: configHelper
142: .addExcludePattern("org.hibernate.engine.TwoPhaseLoad");
143: configHelper
144: .addExcludePattern("org.hibernate.property.BasicPropertyAccessor");
145: configHelper
146: .addExcludePattern("org.hibernate.property.BasicPropertyAccessor$BasicSetter");
147:
148: }
149:
150: protected final void registerModuleSpec(final BundleContext context) {
151: final Dictionary serviceProps = new Hashtable();
152: serviceProps.put(Constants.SERVICE_VENDOR, "Terracotta, Inc.");
153: serviceProps.put(Constants.SERVICE_DESCRIPTION,
154: "Hibernate Plugin Spec");
155: serviceProps.put(Constants.SERVICE_RANKING,
156: ModuleSpec.HIGH_RANK);
157: context.registerService(ModuleSpec.class.getName(),
158: new HibernateModuleSpec(
159: new HibernateChangeApplicatorSpec(getClass()
160: .getClassLoader())), serviceProps);
161: }
162:
163: }
|