com.mizar.persistence.jpa.facade
Class JPAFacade

java.lang.Object
  extended by com.mizar.persistence.jpa.facade.JPAFacade
Direct Known Subclasses:
AuthenticatorJPAFactory, EdgeFacade, FacesCollection, SessionLogs, TigerNodeFactory, Uf100001Reader, Uf100002Reader, Uf1GeoReader, UserManagementJPAFactory, UserSdoCachedMapsFacade, UserSdoGeomMetadataFacade, UserSdoMapsFacade, UserSdoStylesFacade, UserSdoThemesFacade, VsgastatFacade

public class JPAFacade
extends java.lang.Object


Field Summary
protected  javax.persistence.EntityManager em
           
protected  javax.persistence.EntityManagerFactory emf
           
protected  java.lang.String model
           
protected  java.lang.String persistenceUnitName
           
protected  java.lang.String schemaName
           
protected  java.lang.Boolean sequencesValidated
           
protected  java.lang.Boolean silent
           
protected  java.lang.Boolean verbose
           
 
Constructor Summary
JPAFacade()
           
JPAFacade(java.lang.String persistenceUnitName)
           
 
Method Summary
 void closeEm()
           
 void closeEm(javax.persistence.EntityManager em)
           
 void closeEmf()
           
 boolean executeDDL(java.lang.String sql)
           
 int executeNativeUpdate(javax.persistence.Query query)
          Deprecated. 
 int executeNativeUpdate(java.lang.String sql)
           
 int executeUpdate(javax.persistence.Query query)
           
static org.eclipse.persistence.internal.databaseaccess.Accessor getClosableConnectionAccessor(javax.persistence.EntityManager em)
          The method gets a JDBC Connection Accessor from JPA.
 java.sql.Connection getConnection()
          The method gets a JDBC Connection.
static java.sql.Connection getConnection(javax.persistence.EntityManager em)
          The method gets a JDBC Connection.
 javax.persistence.EntityManager getEm()
           
 javax.persistence.EntityManager getEm(java.util.Map emProperties)
          The method returns the existing Entity Manager if it is not null and is open If the em is null or is not open it will
 javax.persistence.EntityManagerFactory getEmf()
          The method will return the existing EntityManagerFactory if one exists
 javax.persistence.EntityManagerFactory getEmf(java.util.Map emProperties)
          The method will return the existing EntityManagerFactory if one exists.
protected  org.apache.commons.logging.Log getLogger()
           
 java.lang.String getPassword()
          This property will not exist if the persistence unit is connected to a managed connection
 java.lang.String getPassword(boolean includeSid)
           
 java.lang.String getPersistenceUnitName()
           
 java.lang.String getSchemaName()
           
 java.lang.Boolean getSequencesValidated()
           
 java.lang.String getSid()
          The method strips the last : separated token from the URL
 java.lang.Boolean getSilent()
           
 java.lang.String getTableName(java.lang.Class beanClass)
           
 int[] getToleratedErrorCodes()
           
 java.lang.String getUrl()
          This property will not exist if the persistence unit is connected to a managed connection
 java.lang.String getUser()
          This property will not exist if the persistence unit is connected to a managed connection
 java.lang.Boolean getVerbose()
           
 java.lang.Object mergeBean(java.lang.Object object)
          Merge is a JPAism for Update.
 java.lang.Object persist(java.lang.Object object)
          Persist is a JPAism for Insert.
 java.lang.Object persistBean(java.lang.Object entityBeanOrSubClass)
           
protected  void printAnyBean(java.lang.Object result)
          Used by queryTester()
 void queryTester(java.lang.String jpql, int max)
          The code for this method was taken from Pro EJB 3: Java Persistence API by Keith and Schincariol published by apress 2006, pages 195-196.
 void queryTester(java.lang.String sql, int max, java.lang.Class returnClass)
           
 java.lang.Object refreshBean(java.lang.Object object, java.lang.Object primaryKey)
           
 boolean remove(java.lang.Object entityBean)
          Remove is a JPAism for Delete
 boolean removeBean(java.lang.Class beanClass, java.lang.Object pkey)
           
 boolean removeBean(java.lang.Object entityBeanOrSuperClass)
          Remove is a JPAism for Delete
 void setEmf(javax.persistence.EntityManagerFactory emf)
           
 void setPersistenceUnitName(java.lang.String persistenceUnit)
           
 void setSilent(java.lang.Boolean silent)
           
 void setToleratedErrorCodes(int[] toleratedErrorCodes)
           
 void setVerbose(java.lang.Boolean verbose)
           
 void validateSequences()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emf

protected javax.persistence.EntityManagerFactory emf

em

protected javax.persistence.EntityManager em

model

protected java.lang.String model

persistenceUnitName

protected java.lang.String persistenceUnitName

schemaName

protected java.lang.String schemaName

sequencesValidated

protected java.lang.Boolean sequencesValidated

silent

protected java.lang.Boolean silent

verbose

protected java.lang.Boolean verbose
Constructor Detail

JPAFacade

public JPAFacade()

JPAFacade

public JPAFacade(java.lang.String persistenceUnitName)
Method Detail

getLogger

protected org.apache.commons.logging.Log getLogger()

setEmf

public void setEmf(javax.persistence.EntityManagerFactory emf)

getEmf

public javax.persistence.EntityManagerFactory getEmf()
The method will return the existing EntityManagerFactory if one exists

Returns:
an EntityManagerFactory

getEmf

public javax.persistence.EntityManagerFactory getEmf(java.util.Map emProperties)
The method will return the existing EntityManagerFactory if one exists. If you want to force a change in properties you must first close the existing EntityManagerFactory.

Parameters:
emProperties -
Returns:
an EntityManagerFactory
See Also:
closeEmf()

closeEmf

public void closeEmf()

getEm

public javax.persistence.EntityManager getEm(java.util.Map emProperties)
The method returns the existing Entity Manager if it is not null and is open If the em is null or is not open it will

Parameters:
emProperties -
Returns:

getEm

public javax.persistence.EntityManager getEm()

closeEm

public void closeEm()

closeEm

public void closeEm(javax.persistence.EntityManager em)

getConnection

public java.sql.Connection getConnection()
The method gets a JDBC Connection.

Returns:
See Also:
getConnection(EntityManager), getClosableConnectionAccessor(EntityManager)

getConnection

public static java.sql.Connection getConnection(javax.persistence.EntityManager em)
The method gets a JDBC Connection.

Parameters:
em -
Returns:
See Also:
getConnection()

getClosableConnectionAccessor

public static org.eclipse.persistence.internal.databaseaccess.Accessor getClosableConnectionAccessor(javax.persistence.EntityManager em)
The method gets a JDBC Connection Accessor from JPA.

Parameters:
em -
Returns:
See Also:
Accessor.getConnection(), Accessor.closeConnection()

getUrl

public java.lang.String getUrl()
This property will not exist if the persistence unit is connected to a managed connection

Returns:
javax.persistence.jdbc.url

getSid

public java.lang.String getSid()
The method strips the last : separated token from the URL

Returns:
the assumed database SID
See Also:
getUrl()

getPassword

public java.lang.String getPassword()
This property will not exist if the persistence unit is connected to a managed connection

Returns:
javax.persistence.jdbc.password

getPassword

public java.lang.String getPassword(boolean includeSid)
Parameters:
includeSid - if true append @sid to the password
Returns:
javax.persistence.jdbc.password appended with @sid if includeSid is true

getUser

public java.lang.String getUser()
This property will not exist if the persistence unit is connected to a managed connection

Returns:
javax.persistence.jdbc.user

mergeBean

public java.lang.Object mergeBean(java.lang.Object object)
                           throws javax.persistence.PersistenceException
Merge is a JPAism for Update.

Parameters:
object -
Returns:
the updated entity bean if successfull; null if an error occurs.
Throws:
javax.persistence.PersistenceException
See Also:
EntityManager.merge(T)

persist

public java.lang.Object persist(java.lang.Object object)
                         throws javax.persistence.PersistenceException
Persist is a JPAism for Insert.

Parameters:
object -
Returns:
entity if successful, null if a failure occurs
Throws:
javax.persistence.PersistenceException
See Also:
EntityManager.persist(java.lang.Object)

persistBean

public java.lang.Object persistBean(java.lang.Object entityBeanOrSubClass)
                             throws javax.persistence.PersistenceException
Throws:
javax.persistence.PersistenceException

remove

public boolean remove(java.lang.Object entityBean)
               throws javax.persistence.PersistenceException
Remove is a JPAism for Delete

Parameters:
entityBean - an Entity Bean
Returns:
true if successful
Throws:
javax.persistence.PersistenceException

removeBean

public boolean removeBean(java.lang.Object entityBeanOrSuperClass)
                   throws javax.persistence.PersistenceException
Remove is a JPAism for Delete

Parameters:
entityBeanOrSuperClass -
Returns:
true if successful
Throws:
javax.persistence.PersistenceException

removeBean

public boolean removeBean(java.lang.Class beanClass,
                          java.lang.Object pkey)
                   throws javax.persistence.PersistenceException
Parameters:
beanClass - an Entity class
pkey - primary key of beanClass
Returns:
Throws:
javax.persistence.PersistenceException

refreshBean

public java.lang.Object refreshBean(java.lang.Object object,
                                    java.lang.Object primaryKey)

executeDDL

public boolean executeDDL(java.lang.String sql)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

executeNativeUpdate

public int executeNativeUpdate(java.lang.String sql)
                        throws java.sql.SQLException
Throws:
java.sql.SQLException

executeNativeUpdate

@Deprecated
public int executeNativeUpdate(javax.persistence.Query query)
                        throws java.sql.SQLException
Deprecated. 

Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(javax.persistence.Query query)
                  throws java.sql.SQLException
Throws:
java.sql.SQLException

setPersistenceUnitName

public void setPersistenceUnitName(java.lang.String persistenceUnit)

getPersistenceUnitName

public java.lang.String getPersistenceUnitName()

queryTester

public void queryTester(java.lang.String sql,
                        int max,
                        java.lang.Class returnClass)

queryTester

public void queryTester(java.lang.String jpql,
                        int max)
The code for this method was taken from Pro EJB 3: Java Persistence API by Keith and Schincariol published by apress 2006, pages 195-196.

Parameters:
jpql - a JPQL statement
See Also:
printAnyBean(java.lang.Object)

printAnyBean

protected void printAnyBean(java.lang.Object result)
                     throws java.lang.Exception
Used by queryTester()

Parameters:
result -
Throws:
java.lang.Exception
See Also:
queryTester(String, int)

getTableName

public java.lang.String getTableName(java.lang.Class beanClass)

getSchemaName

public java.lang.String getSchemaName()

validateSequences

public void validateSequences()

getSequencesValidated

public java.lang.Boolean getSequencesValidated()

setToleratedErrorCodes

public void setToleratedErrorCodes(int[] toleratedErrorCodes)

getToleratedErrorCodes

public int[] getToleratedErrorCodes()

setSilent

public void setSilent(java.lang.Boolean silent)

getSilent

public java.lang.Boolean getSilent()

setVerbose

public void setVerbose(java.lang.Boolean verbose)

getVerbose

public java.lang.Boolean getVerbose()