/int-tests/src/test/java-jpa-cache-eviction/org/jboss/arquillian/integration/persistence/jpa/cache/GameBeanDoublePersistenceContext.java

https://github.com/arquillian/arquillian-extension-persistence · Java · 54 lines · 25 code · 9 blank · 20 comment · 0 complexity · 485bf8024c2607cf3f79d36533eb9720 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
  4. * as indicated by the @authors tag. All rights reserved.
  5. * See the copyright.txt in the distribution for a
  6. * full listing of individual contributors.
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.jboss.arquillian.integration.persistence.jpa.cache;
  19. import javax.ejb.Stateless;
  20. import javax.persistence.EntityManager;
  21. import javax.persistence.PersistenceContext;
  22. /**
  23. * @author <a href="mailto:thradec@gmail.com">Tomas Hradec</a>
  24. */
  25. @Stateless
  26. public class GameBeanDoublePersistenceContext {
  27. @PersistenceContext(name = "jpacacheeviction", unitName = "jpacacheeviction")
  28. private EntityManager em;
  29. @PersistenceContext(name = "embedded", unitName = "embedded")
  30. private EntityManager embedded;
  31. public void init() {
  32. insertGames();
  33. }
  34. public void insertGames() {
  35. em.createNativeQuery("insert into Game(id, title) values (1, 'Pac Man')").executeUpdate();
  36. em.createNativeQuery("insert into Game(id, title) values (2, 'Super Mario')").executeUpdate();
  37. embedded.createNativeQuery("insert into Platform(id, title) values (1, 'PC')").executeUpdate();
  38. }
  39. public Game findById(long gameId) {
  40. return em.find(Game.class, gameId);
  41. }
  42. public Platform findByIdInEmbedded(long platformId) {
  43. return embedded.find(Platform.class, platformId);
  44. }
  45. }