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 */ 017 018 package org.apache.geronimo.persistence; 019 020 import java.util.Map; 021 022 import javax.persistence.EntityManager; 023 import javax.persistence.EntityManagerFactory; 024 import javax.persistence.EntityTransaction; 025 import javax.persistence.FlushModeType; 026 import javax.persistence.LockModeType; 027 import javax.persistence.Query; 028 029 /** 030 * @version $Rev: 538730 $ $Date: 2007-05-16 17:07:51 -0400 (Wed, 16 May 2007) $ 031 */ 032 public class CMPEntityManagerExtended implements EntityManager { 033 034 private final ExtendedEntityManagerRegistry entityManagerRegistry; 035 private final EntityManagerFactory entityManagerFactory; 036 private final Map entityManagerProperties; 037 038 public CMPEntityManagerExtended(ExtendedEntityManagerRegistry entityManagerRegistry, EntityManagerFactory entityManagerFactory, Map entityManagerProperties) { 039 this.entityManagerRegistry = entityManagerRegistry; 040 this.entityManagerFactory = entityManagerFactory; 041 this.entityManagerProperties = entityManagerProperties; 042 } 043 044 private EntityManager getEntityManager() { 045 return entityManagerRegistry.getEntityManager(entityManagerFactory, entityManagerProperties); 046 } 047 048 public void persist(Object o) { 049 getEntityManager().persist(o); 050 } 051 052 public <T>T merge(T t) { 053 return getEntityManager().merge(t); 054 } 055 056 public void remove(Object o) { 057 getEntityManager().remove(o); 058 } 059 060 public <T>T find(Class<T> aClass, Object o) { 061 return getEntityManager().find(aClass, o); 062 } 063 064 public <T>T getReference(Class<T> aClass, Object o) { 065 return getEntityManager().getReference(aClass, o); 066 } 067 068 public void flush() { 069 getEntityManager().flush(); 070 } 071 072 public void setFlushMode(FlushModeType flushModeType) { 073 getEntityManager().setFlushMode(flushModeType); 074 } 075 076 public FlushModeType getFlushMode() { 077 return getEntityManager().getFlushMode(); 078 } 079 080 public void lock(Object o, LockModeType lockModeType) { 081 getEntityManager().lock(o, lockModeType); 082 } 083 084 public void refresh(Object o) { 085 getEntityManager().refresh(o); 086 } 087 088 public void clear() { 089 getEntityManager().clear(); 090 } 091 092 public boolean contains(Object o) { 093 return getEntityManager().contains(o); 094 } 095 096 public Query createQuery(String s) { 097 return getEntityManager().createQuery(s); 098 } 099 100 public Query createNamedQuery(String s) { 101 return getEntityManager().createNamedQuery(s); 102 } 103 104 public Query createNativeQuery(String s) { 105 return getEntityManager().createNativeQuery(s); 106 } 107 108 public Query createNativeQuery(String s, Class aClass) { 109 return getEntityManager().createNativeQuery(s, aClass); 110 } 111 112 public Query createNativeQuery(String s, String s1) { 113 return getEntityManager().createNativeQuery(s, s1); 114 } 115 116 public void close() { 117 throw new IllegalStateException("You cannot call close on a Container Managed Entity Manager"); 118 } 119 120 public boolean isOpen() { 121 return true; 122 } 123 124 public EntityTransaction getTransaction() { 125 throw new IllegalStateException("You cannot call getTransaction on a container managed EntityManager"); 126 } 127 128 public void joinTransaction() { 129 throw new IllegalStateException("You cannot call joinTransaction on a container managed EntityManager"); 130 } 131 132 public Object getDelegate() { 133 return getEntityManager().getDelegate(); 134 } 135 136 }