01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.superbiz.injection.h3jpa;
17:
18: import org.superbiz.injection.h3jpa.Movie;
19: import org.superbiz.injection.h3jpa.Movies;
20:
21: import javax.ejb.Stateful;
22: import javax.persistence.EntityManager;
23: import javax.persistence.PersistenceContext;
24: import javax.persistence.Query;
25: import javax.persistence.PersistenceContextType;
26: import java.util.List;
27:
28: @Stateful(name="Movies")
29: public class MoviesImpl implements Movies {
30:
31: @PersistenceContext(unitName="movie-unit",type=PersistenceContextType.EXTENDED)
32: private EntityManager entityManager;
33:
34: public void addMovie(Movie movie) throws Exception {
35: entityManager.persist(movie);
36: }
37:
38: public void deleteMovie(Movie movie) throws Exception {
39: entityManager.remove(movie);
40: }
41:
42: public List<Movie> getMovies() throws Exception {
43: Query query = entityManager
44: .createQuery("SELECT m from Movie as m");
45: return query.getResultList();
46: }
47:
48: }
|