Commit c16e0e6e authored by toaster's avatar toaster
Browse files

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@52 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 872d965d
......@@ -28,7 +28,6 @@
* Maryland Institute for Advanced Computer Study.
*/
// $Id$
package edu.umiacs.ace.util;
import javax.naming.Context;
......@@ -40,39 +39,58 @@ import javax.persistence.Persistence;
import javax.sql.DataSource;
/**
* Utility class for accessing the entity manager stored as 'ace-amPU'.
*
* @author toaster
*/
public class PersistUtil {
public final class PersistUtil {
private static EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"ace-amPU");
/** entity manager specified in app's persistence.xml. */
private static EntityManagerFactory emf
= Persistence.createEntityManagerFactory("ace-amPU");
/** db connection to aceamdb. */
private static DataSource ds = null;
/**
*
*/
private PersistUtil() {
}
/** Close and set stored entitymanager to null. */
public static void closeFactory() {
emf.close();
emf = null;
}
/**
*
* @return db connection located at 'java:comp/env/jdbc/aceamdb'
*/
public static DataSource getDataSource() {
if ( ds == null ) {
if (ds == null) {
try {
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/aceamdb");
} catch ( NamingException e ) {
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
return ds;
}
public static void persist( Object object ) {
/**
* Persist a new jpa entity using the embedded factory.
*
* @param object object to store
*/
public static void persist(final Object object) {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
em.persist(object);
em.getTransaction().commit();
} catch ( Exception e ) {
} catch (Exception e) {
java.util.logging.Logger.getLogger(PersistUtil.class.getName()).log(
java.util.logging.Level.SEVERE, "exception caught", e);
em.getTransaction().rollback();
......@@ -81,8 +99,13 @@ public class PersistUtil {
}
}
/**
* return entiry manager, will reinitailize stored factory if it has been
* closed.
* @return new entitymanager
*/
public static EntityManager getEntityManager() {
if ( emf == null ) {
if (emf == null) {
emf = Persistence.createEntityManagerFactory("ace-amPU");
}
return emf.createEntityManager();
......
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ace-am">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="aceam." suffix=".log" timestamp="true"/>
<!-- Configuration for authentication. This information should not need to be
<Logger className="org.apache.catalina.logger.FileLogger" prefix="aceam." suffix=".log" timestamp="true"/>
<!-- Configuration for authentication. This information should not need to be
changed at all unless you have your own authentication provider-->
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/aceamdb" debug="99" localDataSource="true"
roleNameCol="rolename" userCredCol="password" userNameCol="username"
userRoleTable="userroles" userTable="users"/>
<!-- If you are using a locally installed Mysql server, you only need to change
<Realm className="org.apache.catalina.realm.DataSourceRealm" dataSourceName="jdbc/aceamdb" debug="99" localDataSource="true" roleNameCol="rolename" userCredCol="password" userNameCol="username" userRoleTable="userroles" userTable="users"/>
<!-- If you are using a locally installed Mysql server, you only need to change
the password entry at the end, otherwise you may need to look at the url
or the username.
or the username.
url - machine name and database name
username - username used to connect to database
password - password used for database
'name' is the resource name used by the web app to refer to this
database and NOT the database name, do not change unless you want bad
things to happen.-->
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/aceamdb"
testOnBorrow="true" type="javax.sql.DataSource" validationQuery="SELECT 1"
url="jdbc:mysql://naraapp12/aceam2"
username="aceam"
password="password" />
<!--Mail server to use when mailing reports. You will need to set this if
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/aceamdb" password="password" testOnBorrow="true" type="javax.sql.DataSource" url="jdbc:mysql://naraapp12/aceam2" username="aceam" validationQuery="SELECT 1"/>
<!--Mail server to use when mailing reports. You will need to set this if
you want reports to be mailed properly.-->
<Parameter name="mail.server" value="localhost.localdomain"/>
<!-- Set this e-mail address to an address e-mail should originate from -->
<Parameter name="mail.from" value="acemail@localhost"/>
<!-- max number of running audits, default 3 -->
<Parameter name="throttle.maxaudit" value="3"/>
<!-- minimum time between srb file reads in milliseconds, default 0 -->
<!--<Parameter name="throttle.wait" value="2000"/>-->
<!-- maximum bytes per second per running audit, default = 0 = unlimited -->
<!-- <Parameter name="throttle.bps" value="1048576"/> -->
<!-- start automated auditing -->
<Parameter name="auto.audit.disable" value="true"/>
<!-- IMS hostname to use. Unless you deployed your own IMS, this should
<Parameter name="mail.server" value="localhost.localdomain"/>
<!-- Set this e-mail address to an address e-mail should originate from -->
<Parameter name="mail.from" value="acemail@localhost"/>
<!-- max number of running audits, default 3 -->
<Parameter name="throttle.maxaudit" value="3"/>
<!-- minimum time between srb file reads in milliseconds, default 0 -->
<!--<Parameter name="throttle.wait" value="2000"/>-->
<!-- maximum bytes per second per running audit, default = 0 = unlimited -->
<!-- <Parameter name="throttle.bps" value="1048576"/> -->
<!-- start automated auditing -->
<Parameter name="auto.audit.disable" value="true"/>
<!-- IMS hostname to use. Unless you deployed your own IMS, this should
probably not be changed -->
<Parameter name="ims" value="ims.umiacs.umd.edu"/>
<!-- Set this to true to disable internal user management. This should only be used
<Parameter name="ims" value="ims.umiacs.umd.edu"/>
<!-- Set this to true to disable internal user management. This should only be used
in conjunction with changes to the Authentication realm listed above.
Default: true;
-->
<Parameter name="auth.management" value="true"/>
<!-- log4j logging properties -->
<!-- change the A1.File value to a location of your logfile -->
<Parameter name="log4j.appender.A1.File" value="/tmp/aceam.log"/>
<!-- Uncomment the following line to log everything to one file, will grow to infinity -->
<!-- <Parameter name="log4j.appender.A1" value="org.apache.log4j.FileAppender"/> -->
<!-- The following 3 lines configure a rolling log file -->
<Parameter name="log4j.appender.A1" value="org.apache.log4j.RollingFileAppender"/>
<Parameter name="log4j.appender.A1.maxFileSize" value="100000KB"/>
<Parameter name="log4j.appender.A1.maxBackupIndex" value="5"/>
<!-- generic logging properties, change only if you know what you are doing -->
<Parameter name="log4j.rootLogger" value="FATAL, A1"/>
<Parameter name="log4j.appender.A1.layout" value="org.apache.log4j.PatternLayout"/>
<Parameter name="log4j.appender.A1.layout.ConversionPattern" value="%d{[dd/MMM/yyyy:HH:mm:ss]} %x%m%n"/>
<Parameter name="log4j.logger.edu.umiacs.irods" value="TRACE"/>
<Parameter name="log4j.logger.edu.umiacs" value="TRACE"/>
<!--<Parameter name="log4j.logger.edu.umiacs.irods.api.IRodsConnection" value="TRACE"/>-->
<Parameter name="auth.management" value="true"/>
<!-- log4j logging properties -->
<!-- change the A1.File value to a location of your logfile -->
<Parameter name="log4j.appender.A1.File" value="/tmp/aceam.log"/>
<!-- Uncomment the following line to log everything to one file, will grow to infinity -->
<!-- <Parameter name="log4j.appender.A1" value="org.apache.log4j.FileAppender"/> -->
<!-- The following 3 lines configure a rolling log file -->
<Parameter name="log4j.appender.A1" value="org.apache.log4j.RollingFileAppender"/>
<Parameter name="log4j.appender.A1.maxFileSize" value="100000KB"/>
<Parameter name="log4j.appender.A1.maxBackupIndex" value="5"/>
<!-- generic logging properties, change only if you know what you are doing -->
<Parameter name="log4j.rootLogger" value="FATAL, A1"/>
<Parameter name="log4j.appender.A1.layout" value="org.apache.log4j.PatternLayout"/>
<Parameter name="log4j.appender.A1.layout.ConversionPattern" value="%d{[dd/MMM/yyyy:HH:mm:ss]} %x%m%n"/>
<Parameter name="log4j.logger.edu.umiacs.irods" value="TRACE"/>
<Parameter name="log4j.logger.edu.umiacs" value="TRACE"/>
<!--<Parameter name="log4j.logger.edu.umiacs.irods.api.IRodsConnection" value="TRACE"/>-->
</Context>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment