001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.ejb;
012:
013: import com.versant.core.jdo.PersistenceManagerFactoryBase;
014: import com.versant.core.jdo.BootstrapPMF;
015: import com.versant.core.jdo.LifecycleListener;
016: import com.versant.core.jdo.VersantPMFInternal;
017: import com.versant.core.storagemanager.StorageManagerFactory;
018: import com.versant.core.storagemanager.StorageCache;
019: import com.versant.core.metric.Metric;
020: import com.versant.core.metric.MetricSnapshotPacket;
021: import com.versant.core.server.DataStoreInfo;
022: import com.versant.core.logging.LogEventStore;
023: import com.versant.core.logging.LogEvent;
024: import com.versant.core.common.config.ConfigParser;
025: import com.versant.core.metadata.MDStatics;
026:
027: import javax.persistence.EntityManager;
028: import javax.persistence.EntityManagerFactory;
029: import javax.jdo.PersistenceManagerFactory;
030: import java.util.Map;
031: import java.util.Properties;
032:
033: /**
034: * Factory class responsible for supplying EntityManger instances.
035: */
036: public class EntityManagerFactoryImp implements EntityManagerFactory {
037: private VersantPMFInternal pmf;
038:
039: public EntityManagerFactoryImp(PersistenceManagerFactory pmf) {
040: this .pmf = (VersantPMFInternal) pmf;
041: }
042:
043: public static EntityManagerFactoryImp getEntityManagerFactory(
044: Properties props) {
045: props.setProperty(ConfigParser.META_DATA_PRE_PROCESSOR, props
046: .getProperty(ConfigParser.META_DATA_PRE_PROCESSOR,
047: MDStatics.EJB_JDBC_PRE_PROCESSOR));
048: PersistenceManagerFactoryBase pmfBase = (PersistenceManagerFactoryBase) BootstrapPMF
049: .getPersistenceManagerFactory(props);
050: return new EntityManagerFactoryImp(pmfBase);
051: }
052:
053: public EntityManager getEntityManager() {
054: return new EntityManagerImp(pmf.getStorageManagerFactory()
055: .getStorageManager(), pmf.getJDOMetaData());
056: }
057:
058: protected StorageManagerFactory createStorageManagerFactory() {
059: return null;
060: }
061:
062: public Metric[] getMetrics() {
063: return pmf.getMetrics();
064: }
065:
066: public MetricSnapshotPacket getNewMetricSnapshots(int lastId) {
067: return pmf.getNewMetricSnapshots(lastId);
068: }
069:
070: public MetricSnapshotPacket getMostRecentMetricSnapshot(int lastId) {
071: return pmf.getMostRecentMetricSnapshot(lastId);
072: }
073:
074: public void setUserMetric(String name, int value) {
075: pmf.setUserMetric(name, value);
076: }
077:
078: public void incUserMetric(String name, int delta) {
079: pmf.incUserMetric(name, delta);
080: }
081:
082: public int getUserMetric(String name) {
083: return pmf.getUserMetric(name);
084: }
085:
086: public Map getHyperdriveBytecode() {
087: return pmf.getHyperdriveBytecode();
088: }
089:
090: public int getHyperdriveBytecodeMaxSize() {
091: return pmf.getHyperdriveBytecodeMaxSize();
092: }
093:
094: public DataStoreInfo getDataStoreInfo(String datastore) {
095: return pmf.getStorageManagerFactory().getDataStoreInfo();
096: }
097:
098: public void evictAll() {
099: pmf.evictAll();
100: }
101:
102: public void logEvent(int eventNormal, String s, int i) {
103: pmf.logEvent(eventNormal, s, i);
104: }
105:
106: public void addLifecycleListener(LifecycleListener listener,
107: Class[] classes) {
108: pmf.addLifecycleListener(listener, classes);
109: }
110:
111: public boolean isLocal() {
112: return pmf.isLocal();
113: }
114:
115: public LogEventStore getLogEventStore() {
116: return pmf.getLogEventStore();
117: }
118:
119: public LogEvent[] getNewPerfEvents(int lastEQEventId) {
120: return pmf.getNewPerfEvents(lastEQEventId);
121: }
122:
123: public String getConnectionURL() {
124: return pmf.getConnectionURL();
125: }
126:
127: public StorageCache getStorageCache() {
128: return pmf.getStorageCache();
129: }
130:
131: public StorageManagerFactory getStorageManagerFactory() {
132: return pmf.getStorageManagerFactory();
133: }
134: }
|