|
Play Framework/Scala example source code file (JPAPlugin.java)
The JPAPlugin.java Play Framework example source code/* * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> */ package play.db.jpa; import play.*; import java.io.*; import java.util.*; import javax.persistence.*; /** * A Play plugin that automatically manages JPA configuration. */ public class JPAPlugin extends Plugin { private final Application application; public JPAPlugin(Application application) { this.application = application; } // -- private final Map<String,EntityManagerFactory> emfs = new HashMap<String,EntityManagerFactory>(); /** * Reads the configuration file and initialises required JPA EntityManagerFactories. */ public void onStart() { Configuration jpaConf = Configuration.root().getConfig("jpa"); if(jpaConf != null) { for(String key: jpaConf.keys()) { String persistenceUnit = jpaConf.getString(key); emfs.put(key, Persistence.createEntityManagerFactory(persistenceUnit)); } } } private boolean isPluginDisabled() { String status = application.configuration().getString("jpaplugin"); return status != null && status.equals("disabled"); } @Override public boolean enabled() { return isPluginDisabled() == false; } public void onStop() { for(EntityManagerFactory emf: emfs.values()) { emf.close(); } } public EntityManager em(String key) { EntityManagerFactory emf = emfs.get(key); if(emf == null) { return null; } return emf.createEntityManager(); } } Other Play Framework source code examplesHere is a short list of links related to this Play Framework JPAPlugin.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.