Class PersistenceUtil


  • public class PersistenceUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      PersistenceUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void cleanUp​(java.util.Map<java.lang.String,​java.lang.Object> context)
      This method should be called in the @After method of a test to clean up the persistence unit and datasource.
      static java.util.Properties getDatasourceProperties()
      This reads in the (maven filtered) datasource properties from the test resource directory.
      static PoolingDataSourceWrapper setupPoolingDataSource()
      This method creates default pooling datasource
      static PoolingDataSourceWrapper setupPoolingDataSource​(java.util.Properties dsProps)
      This method uses the "jdbc/testDS1" datasource, which is the default.
      static PoolingDataSourceWrapper setupPoolingDataSource​(java.util.Properties dsProps, java.lang.String datasourceName)
      This sets up a PoolingDataSource.
      static java.util.Map<java.lang.String,​java.lang.Object> setupWithPoolingDataSource​(java.lang.String persistenceUnitName)  
      static java.util.Map<java.lang.String,​java.lang.Object> setupWithPoolingDataSource​(java.lang.String persistenceUnitName, boolean testMarshalling)  
      static java.util.Map<java.lang.String,​java.lang.Object> setupWithPoolingDataSource​(java.lang.String persistenceUnitName, java.lang.String dataSourceName, boolean testMarshalling)
      This method does all of the setup for the test and returns a HashMap containing the persistence objects that the test might need.
      static boolean useTransactions()
      This method returns whether or not transactions should be used when dealing with the SessionInfo object (or any other persisted entity that contains @Lob's )
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ENTITY_MANAGER_FACTORY

        public static final java.lang.String ENTITY_MANAGER_FACTORY
        See Also:
        Constant Field Values
      • TRANSACTION_MANAGER

        public static final java.lang.String TRANSACTION_MANAGER
        See Also:
        Constant Field Values
      • DATASOURCE_PROPERTIES

        protected static final java.lang.String DATASOURCE_PROPERTIES
        See Also:
        Constant Field Values
      • DATASOURCE

        public static java.lang.String DATASOURCE
    • Constructor Detail

      • PersistenceUtil

        public PersistenceUtil()
    • Method Detail

      • setupWithPoolingDataSource

        public static java.util.Map<java.lang.String,​java.lang.Object> setupWithPoolingDataSource​(java.lang.String persistenceUnitName)
        Parameters:
        persistenceUnitName - The name of the persistence unit to be used.
        Returns:
        test context
        See Also:
        setupWithPoolingDataSource(String, String, boolean)
      • setupWithPoolingDataSource

        public static java.util.Map<java.lang.String,​java.lang.Object> setupWithPoolingDataSource​(java.lang.String persistenceUnitName,
                                                                                                        boolean testMarshalling)
        Parameters:
        persistenceUnitName - The name of the persistence unit to be used.
        Returns:
        test context
        See Also:
        setupWithPoolingDataSource(String, String, boolean)
      • setupWithPoolingDataSource

        public static java.util.Map<java.lang.String,​java.lang.Object> setupWithPoolingDataSource​(java.lang.String persistenceUnitName,
                                                                                                        java.lang.String dataSourceName,
                                                                                                        boolean testMarshalling)
        This method does all of the setup for the test and returns a HashMap containing the persistence objects that the test might need.
        Parameters:
        persistenceUnitName - The name of the persistence unit used by the test.
        Returns:
        Map with persistence objects, such as the EntityManagerFactory and DataSource
      • cleanUp

        public static void cleanUp​(java.util.Map<java.lang.String,​java.lang.Object> context)
        This method should be called in the @After method of a test to clean up the persistence unit and datasource.
        Parameters:
        context - A HashMap
      • setupPoolingDataSource

        public static PoolingDataSourceWrapper setupPoolingDataSource()
        This method creates default pooling datasource
        Returns:
        a PoolingDataSource
      • setupPoolingDataSource

        public static PoolingDataSourceWrapper setupPoolingDataSource​(java.util.Properties dsProps)
        This method uses the "jdbc/testDS1" datasource, which is the default.
        Parameters:
        dsProps - The properties used to setup the data source.
        Returns:
        a PoolingDataSource
      • setupPoolingDataSource

        public static PoolingDataSourceWrapper setupPoolingDataSource​(java.util.Properties dsProps,
                                                                      java.lang.String datasourceName)
        This sets up a PoolingDataSource.
        Returns:
        PoolingDataSource that has been set up but _not_ initialized.
      • getDatasourceProperties

        public static java.util.Properties getDatasourceProperties()
        This reads in the (maven filtered) datasource properties from the test resource directory.
        Returns:
        Properties containing the datasource properties.
      • useTransactions

        public static boolean useTransactions()
        This method returns whether or not transactions should be used when dealing with the SessionInfo object (or any other persisted entity that contains @Lob's )
        Returns:
        boolean Whether or not to use transactions