001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.persistence;
017:
018: import java.util.Map;
019:
020: import javax.persistence.EntityManager;
021: import javax.persistence.EntityManagerFactory;
022: import javax.persistence.EntityTransaction;
023: import javax.persistence.FlushModeType;
024: import javax.persistence.LockModeType;
025: import javax.persistence.Query;
026:
027: /**
028: * @version $Rev: 538730 $ $Date: 2007-05-16 14:07:51 -0700 (Wed, 16 May 2007) $
029: */
030: public class CMPEntityManagerExtended implements EntityManager {
031:
032: private final ExtendedEntityManagerRegistry entityManagerRegistry;
033: private final EntityManagerFactory entityManagerFactory;
034: private final Map entityManagerProperties;
035:
036: public CMPEntityManagerExtended(
037: ExtendedEntityManagerRegistry entityManagerRegistry,
038: EntityManagerFactory entityManagerFactory,
039: Map entityManagerProperties) {
040: this .entityManagerRegistry = entityManagerRegistry;
041: this .entityManagerFactory = entityManagerFactory;
042: this .entityManagerProperties = entityManagerProperties;
043: }
044:
045: private EntityManager getEntityManager() {
046: return entityManagerRegistry.getEntityManager(
047: entityManagerFactory, entityManagerProperties);
048: }
049:
050: public void persist(Object o) {
051: getEntityManager().persist(o);
052: }
053:
054: public <T> T merge(T t) {
055: return getEntityManager().merge(t);
056: }
057:
058: public void remove(Object o) {
059: getEntityManager().remove(o);
060: }
061:
062: public <T> T find(Class<T> aClass, Object o) {
063: return getEntityManager().find(aClass, o);
064: }
065:
066: public <T> T getReference(Class<T> aClass, Object o) {
067: return getEntityManager().getReference(aClass, o);
068: }
069:
070: public void flush() {
071: getEntityManager().flush();
072: }
073:
074: public void setFlushMode(FlushModeType flushModeType) {
075: getEntityManager().setFlushMode(flushModeType);
076: }
077:
078: public FlushModeType getFlushMode() {
079: return getEntityManager().getFlushMode();
080: }
081:
082: public void lock(Object o, LockModeType lockModeType) {
083: getEntityManager().lock(o, lockModeType);
084: }
085:
086: public void refresh(Object o) {
087: getEntityManager().refresh(o);
088: }
089:
090: public void clear() {
091: getEntityManager().clear();
092: }
093:
094: public boolean contains(Object o) {
095: return getEntityManager().contains(o);
096: }
097:
098: public Query createQuery(String s) {
099: return getEntityManager().createQuery(s);
100: }
101:
102: public Query createNamedQuery(String s) {
103: return getEntityManager().createNamedQuery(s);
104: }
105:
106: public Query createNativeQuery(String s) {
107: return getEntityManager().createNativeQuery(s);
108: }
109:
110: public Query createNativeQuery(String s, Class aClass) {
111: return getEntityManager().createNativeQuery(s, aClass);
112: }
113:
114: public Query createNativeQuery(String s, String s1) {
115: return getEntityManager().createNativeQuery(s, s1);
116: }
117:
118: public void close() {
119: throw new IllegalStateException(
120: "You cannot call close on a Container Managed Entity Manager");
121: }
122:
123: public boolean isOpen() {
124: return true;
125: }
126:
127: public EntityTransaction getTransaction() {
128: throw new IllegalStateException(
129: "You cannot call getTransaction on a container managed EntityManager");
130: }
131:
132: public void joinTransaction() {
133: throw new IllegalStateException(
134: "You cannot call joinTransaction on a container managed EntityManager");
135: }
136:
137: public Object getDelegate() {
138: return getEntityManager().getDelegate();
139: }
140:
141: }
|