HHH-5942 - Migrate to JUnit 4
This commit is contained in:
parent
df4df47b95
commit
9ad55dc4bd
|
@ -1077,9 +1077,11 @@ public final class SessionFactoryImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evictQueryRegions() {
|
public void evictQueryRegions() {
|
||||||
for ( QueryCache queryCache : queryCaches.values() ) {
|
if ( queryCaches != null ) {
|
||||||
queryCache.clear();
|
for ( QueryCache queryCache : queryCaches.values() ) {
|
||||||
// TODO : cleanup entries in queryCaches + allCacheRegions ?
|
queryCache.clear();
|
||||||
|
// TODO : cleanup entries in queryCaches + allCacheRegions ?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,19 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb;
|
package org.hibernate.ejb;
|
||||||
|
|
||||||
|
import javax.naming.BinaryRefAddr;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.naming.Reference;
|
||||||
|
import javax.naming.Referenceable;
|
||||||
|
import javax.persistence.Embeddable;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import javax.persistence.MappedSuperclass;
|
||||||
|
import javax.persistence.PersistenceException;
|
||||||
|
import javax.persistence.spi.PersistenceUnitInfo;
|
||||||
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
|
import javax.sql.DataSource;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -45,26 +58,17 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import javax.naming.BinaryRefAddr;
|
|
||||||
import javax.naming.NamingException;
|
|
||||||
import javax.naming.Reference;
|
|
||||||
import javax.naming.Referenceable;
|
|
||||||
import javax.persistence.Embeddable;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import javax.persistence.MappedSuperclass;
|
|
||||||
import javax.persistence.PersistenceException;
|
|
||||||
import javax.persistence.spi.PersistenceUnitInfo;
|
|
||||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
import org.xml.sax.EntityResolver;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.MappingNotFoundException;
|
import org.hibernate.MappingNotFoundException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.AnnotationConfiguration;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
|
@ -95,11 +99,8 @@ import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
import org.hibernate.secure.JACCConfiguration;
|
import org.hibernate.secure.JACCConfiguration;
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
|
||||||
import org.hibernate.service.spi.ServiceRegistry;
|
import org.hibernate.service.spi.ServiceRegistry;
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
import org.xml.sax.EntityResolver;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow a fine tuned configuration of an EJB 3.0 EntityManagerFactory
|
* Allow a fine tuned configuration of an EJB 3.0 EntityManagerFactory
|
||||||
|
@ -127,7 +128,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
private static final String PARSED_MAPPING_DOMS = "hibernate.internal.mapping_doms";
|
private static final String PARSED_MAPPING_DOMS = "hibernate.internal.mapping_doms";
|
||||||
|
|
||||||
private static EntityNotFoundDelegate ejb3EntityNotFoundDelegate = new Ejb3EntityNotFoundDelegate();
|
private static EntityNotFoundDelegate ejb3EntityNotFoundDelegate = new Ejb3EntityNotFoundDelegate();
|
||||||
private static Configuration DEFAULT_CONFIGURATION = new AnnotationConfiguration();
|
private static Configuration DEFAULT_CONFIGURATION = new Configuration();
|
||||||
|
|
||||||
private static class Ejb3EntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable {
|
private static class Ejb3EntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable {
|
||||||
public void handleEntityNotFound(String entityName, Serializable id) {
|
public void handleEntityNotFound(String entityName, Serializable id) {
|
||||||
|
@ -142,8 +143,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
private String persistenceUnitName;
|
private String persistenceUnitName;
|
||||||
private String cfgXmlResource;
|
private String cfgXmlResource;
|
||||||
|
|
||||||
private AnnotationConfiguration cfg;
|
private Configuration cfg;
|
||||||
private final Map connectionProviderInjectionData;
|
|
||||||
//made transient and not restored in deserialization on purpose, should no longer be called after restoration
|
//made transient and not restored in deserialization on purpose, should no longer be called after restoration
|
||||||
private transient EventListenerConfigurator listenerConfigurator;
|
private transient EventListenerConfigurator listenerConfigurator;
|
||||||
private PersistenceUnitTransactionType transactionType;
|
private PersistenceUnitTransactionType transactionType;
|
||||||
|
@ -154,8 +154,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
|
|
||||||
|
|
||||||
public Ejb3Configuration() {
|
public Ejb3Configuration() {
|
||||||
connectionProviderInjectionData = new HashMap();
|
cfg = new Configuration();
|
||||||
cfg = new AnnotationConfiguration();
|
|
||||||
cfg.setEntityNotFoundDelegate( ejb3EntityNotFoundDelegate );
|
cfg.setEntityNotFoundDelegate( ejb3EntityNotFoundDelegate );
|
||||||
listenerConfigurator = new EventListenerConfigurator( this );
|
listenerConfigurator = new EventListenerConfigurator( this );
|
||||||
}
|
}
|
||||||
|
@ -168,10 +167,8 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
@SuppressWarnings({ "JavaDoc", "unchecked" })
|
@SuppressWarnings({ "JavaDoc", "unchecked" })
|
||||||
public void setDataSource(DataSource ds) {
|
public void setDataSource(DataSource ds) {
|
||||||
if ( ds != null ) {
|
if ( ds != null ) {
|
||||||
Map cpInjection = new HashMap();
|
cfg.getProperties().put( Environment.DATASOURCE, ds );
|
||||||
cpInjection.put( "dataSource", ds );
|
this.setProperty( Environment.CONNECTION_PROVIDER, DatasourceConnectionProviderImpl.class.getName() );
|
||||||
connectionProviderInjectionData.put( ConnectionProviderInitiator.INJECTION_DATA, cpInjection );
|
|
||||||
this.setProperty( Environment.CONNECTION_PROVIDER, InjectedDataSourceConnectionProvider.class.getName() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +280,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
/**
|
/**
|
||||||
* Build the configuration from an entity manager name and given the
|
* Build the configuration from an entity manager name and given the
|
||||||
* appropriate extra properties. Those properties override the one get through
|
* appropriate extra properties. Those properties override the one get through
|
||||||
* the peristence.xml file.
|
* the persistence.xml file.
|
||||||
* If the persistence unit name is not found or does not match the Persistence Provider, null is returned
|
* If the persistence unit name is not found or does not match the Persistence Provider, null is returned
|
||||||
*
|
*
|
||||||
* This method is used in a non managed environment
|
* This method is used in a non managed environment
|
||||||
|
@ -505,7 +502,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
* @param info The persistence unit info passed in by the container (usually from processing a persistence.xml).
|
* @param info The persistence unit info passed in by the container (usually from processing a persistence.xml).
|
||||||
* @param integration The map of integration properties from the container to configure the provider.
|
* @param integration The map of integration properties from the container to configure the provider.
|
||||||
*
|
*
|
||||||
* @return The configured EJB3Configurartion object
|
* @return this
|
||||||
*
|
*
|
||||||
* @see HibernatePersistence#createContainerEntityManagerFactory
|
* @see HibernatePersistence#createContainerEntityManagerFactory
|
||||||
*/
|
*/
|
||||||
|
@ -859,23 +856,10 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
// This is used directly by JBoss so don't remove until further notice. bill@jboss.org
|
// This is used directly by JBoss so don't remove until further notice. bill@jboss.org
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public EntityManagerFactory createEntityManagerFactory(Map workingVars) {
|
public EntityManagerFactory createEntityManagerFactory(Map workingVars) {
|
||||||
Properties props = new Properties();
|
configure( workingVars );
|
||||||
if ( workingVars != null ) {
|
|
||||||
props.putAll( workingVars );
|
|
||||||
//remove huge non String elements for a clean props
|
|
||||||
props.remove( AvailableSettings.CLASS_NAMES );
|
|
||||||
props.remove( AvailableSettings.PACKAGE_NAMES );
|
|
||||||
props.remove( AvailableSettings.HBXML_FILES );
|
|
||||||
props.remove( AvailableSettings.LOADED_CLASSES );
|
|
||||||
}
|
|
||||||
configure( props, workingVars );
|
|
||||||
return buildEntityManagerFactory();
|
return buildEntityManagerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManagerFactory createEntityManagerFactory(Map config, ServiceRegistryImpl serviceRegistry) {
|
|
||||||
return null; // todo : implement method body
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process configuration and build an EntityManagerFactory <b>when</b> the configuration is ready
|
* Process configuration and build an EntityManagerFactory <b>when</b> the configuration is ready
|
||||||
* @deprecated
|
* @deprecated
|
||||||
|
@ -906,7 +890,6 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
discardOnClose,
|
discardOnClose,
|
||||||
getSessionInterceptorClass( cfg.getProperties() ),
|
getSessionInterceptorClass( cfg.getProperties() ),
|
||||||
cfg,
|
cfg,
|
||||||
connectionProviderInjectionData,
|
|
||||||
serviceRegistry
|
serviceRegistry
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -972,6 +955,20 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
|
public Ejb3Configuration configure(Map configValues) {
|
||||||
|
Properties props = new Properties();
|
||||||
|
if ( configValues != null ) {
|
||||||
|
props.putAll( configValues );
|
||||||
|
//remove huge non String elements for a clean props
|
||||||
|
props.remove( AvailableSettings.CLASS_NAMES );
|
||||||
|
props.remove( AvailableSettings.PACKAGE_NAMES );
|
||||||
|
props.remove( AvailableSettings.HBXML_FILES );
|
||||||
|
props.remove( AvailableSettings.LOADED_CLASSES );
|
||||||
|
}
|
||||||
|
return configure( props, configValues );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures this configuration object from 2 distinctly different sources.
|
* Configures this configuration object from 2 distinctly different sources.
|
||||||
*
|
*
|
||||||
|
@ -1139,13 +1136,13 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( workingVars.containsKey( AvailableSettings.XML_FILE_NAMES ) ) {
|
if ( workingVars.containsKey( AvailableSettings.XML_FILE_NAMES ) ) {
|
||||||
Collection<String> xmlFiles = (Collection<String>) workingVars.get(
|
Collection<String> xmlFiles = (Collection<String>) workingVars.get( AvailableSettings.XML_FILE_NAMES );
|
||||||
AvailableSettings.XML_FILE_NAMES
|
|
||||||
);
|
|
||||||
for ( String xmlFile : xmlFiles ) {
|
for ( String xmlFile : xmlFiles ) {
|
||||||
Boolean useMetaInf = null;
|
Boolean useMetaInf = null;
|
||||||
try {
|
try {
|
||||||
if ( xmlFile.endsWith( META_INF_ORM_XML ) ) useMetaInf = true;
|
if ( xmlFile.endsWith( META_INF_ORM_XML ) ) {
|
||||||
|
useMetaInf = true;
|
||||||
|
}
|
||||||
cfg.addResource( xmlFile );
|
cfg.addResource( xmlFile );
|
||||||
}
|
}
|
||||||
catch( MappingNotFoundException e ) {
|
catch( MappingNotFoundException e ) {
|
||||||
|
@ -1162,8 +1159,12 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
throw new PersistenceException( getExceptionHeader()
|
throw new PersistenceException( getExceptionHeader()
|
||||||
+ "Error while reading JPA XML file: " + xmlFile, me);
|
+ "Error while reading JPA XML file: " + xmlFile, me);
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(useMetaInf)) LOG.exceptionHeaderFound(getExceptionHeader(), META_INF_ORM_XML);
|
if (Boolean.TRUE.equals(useMetaInf)) {
|
||||||
else if (Boolean.FALSE.equals(useMetaInf)) LOG.exceptionHeaderNotFound(getExceptionHeader(), META_INF_ORM_XML);
|
LOG.exceptionHeaderFound(getExceptionHeader(), META_INF_ORM_XML);
|
||||||
|
}
|
||||||
|
else if (Boolean.FALSE.equals(useMetaInf)) {
|
||||||
|
LOG.exceptionHeaderNotFound(getExceptionHeader(), META_INF_ORM_XML);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( workingVars.containsKey( AvailableSettings.HBXML_FILES ) ) {
|
if ( workingVars.containsKey( AvailableSettings.HBXML_FILES ) ) {
|
||||||
|
@ -1562,7 +1563,7 @@ public class Ejb3Configuration implements Serializable, Referenceable {
|
||||||
* tool.
|
* tool.
|
||||||
* DO NOT update configuration through it.
|
* DO NOT update configuration through it.
|
||||||
*/
|
*/
|
||||||
public AnnotationConfiguration getHibernateConfiguration() {
|
public Configuration getHibernateConfiguration() {
|
||||||
//TODO make it really read only (maybe through proxying)
|
//TODO make it really read only (maybe through proxying)
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb;
|
package org.hibernate.ejb;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import javax.persistence.Cache;
|
import javax.persistence.Cache;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContextType;
|
import javax.persistence.PersistenceContextType;
|
||||||
|
@ -35,10 +29,16 @@ import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.metamodel.Metamodel;
|
import javax.persistence.metamodel.Metamodel;
|
||||||
import javax.persistence.spi.LoadState;
|
import javax.persistence.spi.LoadState;
|
||||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.AnnotationConfiguration;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
|
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
|
||||||
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
||||||
|
@ -46,7 +46,6 @@ import org.hibernate.ejb.util.PersistenceUtilHelper;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
|
||||||
import org.hibernate.service.spi.ServiceRegistry;
|
import org.hibernate.service.spi.ServiceRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +56,6 @@ import org.hibernate.service.spi.ServiceRegistry;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
private final transient ServiceRegistry serviceRegistry;
|
|
||||||
private final SessionFactory sessionFactory;
|
private final SessionFactory sessionFactory;
|
||||||
private final PersistenceUnitTransactionType transactionType;
|
private final PersistenceUnitTransactionType transactionType;
|
||||||
private final boolean discardOnClose;
|
private final boolean discardOnClose;
|
||||||
|
@ -66,7 +64,6 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
private final Metamodel metamodel;
|
private final Metamodel metamodel;
|
||||||
private final HibernatePersistenceUnitUtil util;
|
private final HibernatePersistenceUnitUtil util;
|
||||||
private final Map<String,Object> properties;
|
private final Map<String,Object> properties;
|
||||||
private final Map connectionProviderInjectionData;
|
|
||||||
|
|
||||||
private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache();
|
private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache();
|
||||||
|
|
||||||
|
@ -75,10 +72,8 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
PersistenceUnitTransactionType transactionType,
|
PersistenceUnitTransactionType transactionType,
|
||||||
boolean discardOnClose,
|
boolean discardOnClose,
|
||||||
Class sessionInterceptorClass,
|
Class sessionInterceptorClass,
|
||||||
AnnotationConfiguration cfg,
|
Configuration cfg,
|
||||||
Map connectionProviderInjectionData,
|
|
||||||
ServiceRegistry serviceRegistry) {
|
ServiceRegistry serviceRegistry) {
|
||||||
this.serviceRegistry = serviceRegistry;
|
|
||||||
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||||
this.transactionType = transactionType;
|
this.transactionType = transactionType;
|
||||||
this.discardOnClose = discardOnClose;
|
this.discardOnClose = discardOnClose;
|
||||||
|
@ -98,7 +93,6 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
addAll( props, ( (SessionFactoryImplementor) sessionFactory ).getProperties() );
|
addAll( props, ( (SessionFactoryImplementor) sessionFactory ).getProperties() );
|
||||||
addAll( props, cfg.getProperties() );
|
addAll( props, cfg.getProperties() );
|
||||||
this.properties = Collections.unmodifiableMap( props );
|
this.properties = Collections.unmodifiableMap( props );
|
||||||
this.connectionProviderInjectionData = new HashMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addAll(HashMap<String, Object> propertyMap, Properties properties) {
|
private static void addAll(HashMap<String, Object> propertyMap, Properties properties) {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
|
||||||
* indicated by the @author tags or express copyright attribution
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Middleware LLC.
|
* distributed under license by Red Hat Inc.
|
||||||
*
|
*
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
@ -19,11 +21,11 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//$Id$
|
|
||||||
package org.hibernate.ejb;
|
package org.hibernate.ejb;
|
||||||
import java.io.Serializable;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,14 +22,16 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria;
|
package org.hibernate.ejb.criteria;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Root;
|
|
||||||
import org.hibernate.ejb.metamodel.Address;
|
import org.hibernate.ejb.metamodel.Address;
|
||||||
import org.hibernate.ejb.metamodel.Alias;
|
import org.hibernate.ejb.metamodel.Alias;
|
||||||
import org.hibernate.ejb.metamodel.Country;
|
import org.hibernate.ejb.metamodel.Country;
|
||||||
|
@ -49,12 +51,14 @@ import org.hibernate.ejb.test.callbacks.VideoSystem;
|
||||||
import org.hibernate.ejb.test.inheritance.Fruit;
|
import org.hibernate.ejb.test.inheritance.Fruit;
|
||||||
import org.hibernate.ejb.test.inheritance.Strawberry;
|
import org.hibernate.ejb.test.inheritance.Strawberry;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Customer.class,
|
Customer.class,
|
||||||
|
@ -79,6 +83,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJustSimpleRootCriteria() {
|
public void testJustSimpleRootCriteria() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -98,6 +103,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleJoinCriteria() {
|
public void testSimpleJoinCriteria() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -113,6 +119,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleFetchCriteria() {
|
public void testSimpleFetchCriteria() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -128,6 +135,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerialization() {
|
public void testSerialization() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -145,6 +153,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
private <T> T serializeDeserialize(T object) {
|
private <T> T serializeDeserialize(T object) {
|
||||||
T serializedObject = null;
|
T serializedObject = null;
|
||||||
try {
|
try {
|
||||||
|
@ -161,7 +170,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
byteIn.close();
|
byteIn.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
fail("Unable to serialize / deserialize the object: " + e.getMessage() );
|
Assert.fail( "Unable to serialize / deserialize the object: " + e.getMessage() );
|
||||||
}
|
}
|
||||||
return serializedObject;
|
return serializedObject;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,16 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria;
|
package org.hibernate.ejb.criteria;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import javax.persistence.metamodel.EntityType;
|
import javax.persistence.metamodel.EntityType;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.ejb.criteria.predicate.ComparisonPredicate;
|
import org.hibernate.ejb.criteria.predicate.ComparisonPredicate;
|
||||||
import org.hibernate.ejb.metamodel.Address;
|
import org.hibernate.ejb.metamodel.Address;
|
||||||
import org.hibernate.ejb.metamodel.Alias;
|
import org.hibernate.ejb.metamodel.Alias;
|
||||||
|
@ -46,9 +48,11 @@ import org.hibernate.ejb.metamodel.ShelfLife;
|
||||||
import org.hibernate.ejb.metamodel.Spouse;
|
import org.hibernate.ejb.metamodel.Spouse;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@ -70,6 +74,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEqualityComparisonLiteralConversion() {
|
public void testEqualityComparisonLiteralConversion() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -108,6 +113,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEqualityComparisonEntityConversion() {
|
public void testEqualityComparisonEntityConversion() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -149,6 +155,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTypeConversion() {
|
public void testTypeConversion() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -180,6 +187,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConstructor() {
|
public void testConstructor() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -204,6 +212,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDateTimeFunctions() {
|
public void testDateTimeFunctions() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.basic;
|
package org.hibernate.ejb.criteria.basic;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -33,25 +34,27 @@ import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||||
import org.hibernate.ejb.metamodel.Product;
|
import org.hibernate.ejb.metamodel.Product;
|
||||||
import org.hibernate.ejb.metamodel.Product_;
|
import org.hibernate.ejb.metamodel.Product_;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
private CriteriaBuilder builder;
|
private CriteriaBuilder builder;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void createTestData() {
|
||||||
super.setUp();
|
builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
builder = factory.getCriteriaBuilder();
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Product product = new Product();
|
Product product = new Product();
|
||||||
product.setId( "product1" );
|
product.setId( "product1" );
|
||||||
product.setPrice( 1.23d );
|
product.setPrice( 1.23d );
|
||||||
product.setQuantity( 1000 );
|
product.setQuantity( 1000 );
|
||||||
product.setPartNumber( Integer.MAX_VALUE + 1 );
|
product.setPartNumber( ( (long) Integer.MAX_VALUE ) + 1 );
|
||||||
product.setRating( 1.999f );
|
product.setRating( 1.999f );
|
||||||
product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) );
|
product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) );
|
||||||
product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) );
|
product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) );
|
||||||
|
@ -60,19 +63,19 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void cleanUpTestData() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.createQuery( "delete Product" ).executeUpdate();
|
em.createQuery( "delete Product" ).executeUpdate();
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
super.tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sum of Longs should return a Long
|
* Sum of Longs should return a Long
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSumOfLongs() {
|
public void testSumOfLongs() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -88,6 +91,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
/**
|
/**
|
||||||
* Sum of Integers should return an Integer; note that this is distinctly different than JPAQL
|
* Sum of Integers should return an Integer; note that this is distinctly different than JPAQL
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSumOfIntegers() {
|
public void testSumOfIntegers() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -103,6 +107,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
/**
|
/**
|
||||||
* Sum of Doubles should return a Double
|
* Sum of Doubles should return a Double
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSumOfDoubles() {
|
public void testSumOfDoubles() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -118,6 +123,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
/**
|
/**
|
||||||
* Sum of Floats should return a Float; note that this is distinctly different than JPAQL
|
* Sum of Floats should return a Float; note that this is distinctly different than JPAQL
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSumOfFloats() {
|
public void testSumOfFloats() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -133,6 +139,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
/**
|
/**
|
||||||
* Sum of BigInteger should return a BigInteger
|
* Sum of BigInteger should return a BigInteger
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSumOfBigIntegers() {
|
public void testSumOfBigIntegers() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -148,6 +155,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
/**
|
/**
|
||||||
* Sum of BigDecimal should return a BigDecimal
|
* Sum of BigDecimal should return a BigDecimal
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSumOfBigDecimals() {
|
public void testSumOfBigDecimals() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -160,7 +168,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertReturnType(Class expectedType, Object value) {
|
private void assertReturnType(Class expectedType, Object value) {
|
||||||
if ( value != null && ! expectedType.isInstance( value ) ) {
|
if ( value != null && ! expectedType.isInstance( value ) ) {
|
||||||
throw new AssertionFailedError(
|
throw new AssertionFailedError(
|
||||||
"Result value was not of expected type: expected [" + expectedType.getName()
|
"Result value was not of expected type: expected [" + expectedType.getName()
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009-2011, Red Hat Inc. or third-party contributors as
|
||||||
* indicated by the @author tags or express copyright attribution
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Middleware LLC.
|
* distributed under license by Red Hat Inc.
|
||||||
*
|
*
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
@ -20,6 +22,7 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.basic;
|
package org.hibernate.ejb.criteria.basic;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.ParameterExpression;
|
import javax.persistence.criteria.ParameterExpression;
|
||||||
|
@ -29,17 +32,21 @@ import javax.persistence.metamodel.SingularAttribute;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase {
|
public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { Wall.class };
|
return new Class[] { Wall.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParameterCollection() {
|
public void testParameterCollection() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -57,6 +64,7 @@ public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTrivialCompilation() {
|
public void testTrivialCompilation() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
|
@ -22,10 +22,7 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.basic;
|
package org.hibernate.ejb.criteria.basic;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
@ -33,6 +30,11 @@ import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.ParameterExpression;
|
import javax.persistence.criteria.ParameterExpression;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||||
import org.hibernate.ejb.metamodel.Phone;
|
import org.hibernate.ejb.metamodel.Phone;
|
||||||
|
@ -40,6 +42,12 @@ import org.hibernate.ejb.metamodel.Product;
|
||||||
import org.hibernate.ejb.metamodel.Product_;
|
import org.hibernate.ejb.metamodel.Product_;
|
||||||
import org.hibernate.impl.AbstractQueryImpl;
|
import org.hibernate.impl.AbstractQueryImpl;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that various expressions operate as expected
|
* Tests that various expressions operate as expected
|
||||||
*
|
*
|
||||||
|
@ -48,10 +56,10 @@ import org.hibernate.impl.AbstractQueryImpl;
|
||||||
public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
private CriteriaBuilder builder;
|
private CriteriaBuilder builder;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void prepareTestData() {
|
||||||
super.setUp();
|
builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
builder = factory.getCriteriaBuilder();
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Product product = new Product();
|
Product product = new Product();
|
||||||
|
@ -67,6 +75,16 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanupTestData() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.remove( em.find( Product.class, "product1" ) );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyConjunction() {
|
public void testEmptyConjunction() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -79,6 +97,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyConjunctionIsTrue() {
|
public void testEmptyConjunctionIsTrue() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -91,6 +110,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyConjunctionIsFalse() {
|
public void testEmptyConjunctionIsFalse() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -103,6 +123,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyDisjunction() {
|
public void testEmptyDisjunction() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -115,6 +136,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyDisjunctionIsTrue() {
|
public void testEmptyDisjunctionIsTrue() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -127,6 +149,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyDisjunctionIsFalse() {
|
public void testEmptyDisjunctionIsFalse() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -139,6 +162,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDiff() {
|
public void testDiff() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -151,6 +175,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDiffWithQuotient() {
|
public void testDiffWithQuotient() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -171,6 +196,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSumWithQuotient() {
|
public void testSumWithQuotient() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -191,6 +217,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testQuotientAndMultiply() {
|
public void testQuotientAndMultiply() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -224,7 +251,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParameterReuse() {
|
public void testParameterReuse() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -248,6 +275,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size();
|
return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInExplicitTupleList() {
|
public void testInExplicitTupleList() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -260,6 +288,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInExplicitTupleListVarargs() {
|
public void testInExplicitTupleListVarargs() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -272,6 +301,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInExpressionVarargs() {
|
public void testInExpressionVarargs() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -284,6 +314,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinedElementCollectionValuesInTupleList() {
|
public void testJoinedElementCollectionValuesInTupleList() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
|
@ -22,15 +22,23 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.basic;
|
package org.hibernate.ejb.criteria.basic;
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||||
import org.hibernate.ejb.metamodel.Order;
|
import org.hibernate.ejb.metamodel.Order;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the various predicates.
|
* Test the various predicates.
|
||||||
*
|
*
|
||||||
|
@ -38,25 +46,25 @@ import org.hibernate.ejb.metamodel.Order;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class PredicateTest extends AbstractMetamodelSpecificTest {
|
public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
private EntityManager em;
|
|
||||||
private CriteriaBuilder builder;
|
private CriteriaBuilder builder;
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
@Before
|
||||||
super.setUp();
|
public void prepareTestData() {
|
||||||
builder = factory.getCriteriaBuilder();
|
builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
em = getOrCreateEntityManager();
|
|
||||||
createTestOrders();
|
|
||||||
em.getTransaction().begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tearDown() throws Exception {
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.persist( new Order( "order-1", 1.0d ) );
|
||||||
|
em.persist( new Order( "order-2", 10.0d ) );
|
||||||
|
em.persist( new Order( "order-3", new char[]{'r','u'} ) );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
super.tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyConjunction() {
|
public void testEmptyConjunction() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
// yes this is a retarded case, but explicitly allowed in the JPA spec
|
// yes this is a retarded case, but explicitly allowed in the JPA spec
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
@ -66,9 +74,14 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||||
assertTrue( orders.size() == 3 );
|
assertTrue( orders.size() == 3 );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmptyDisjunction() {
|
public void testEmptyDisjunction() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
// yes this is a retarded case, but explicitly allowed in the JPA spec
|
// yes this is a retarded case, but explicitly allowed in the JPA spec
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
@ -78,12 +91,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||||
assertTrue( orders.size() == 3 );
|
assertTrue( orders.size() == 3 );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check simple not.
|
* Check simple not.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSimpleNot() {
|
public void testSimpleNot() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
|
||||||
|
@ -92,12 +110,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||||
assertTrue( orders.size() == 2 );
|
assertTrue( orders.size() == 2 );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check complicated not.
|
* Check complicated not.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testComplicatedNotOr() {
|
public void testComplicatedNotOr() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
|
||||||
|
@ -110,12 +133,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
assertTrue( orders.size() == 1 );
|
assertTrue( orders.size() == 1 );
|
||||||
Order order = orders.get( 0 );
|
Order order = orders.get( 0 );
|
||||||
assertEquals( "order-3", order.getId() );
|
assertEquals( "order-3", order.getId() );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check complicated not.
|
* Check complicated not.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testNotMultipleOr() {
|
public void testNotMultipleOr() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
|
||||||
|
@ -127,12 +155,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||||
assertTrue( orders.size() == 0 );
|
assertTrue( orders.size() == 0 );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check complicated not.
|
* Check complicated not.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testComplicatedNotAnd() {
|
public void testComplicatedNotAnd() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
|
||||||
|
@ -143,20 +176,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||||
assertTrue( orders.size() == 3 );
|
assertTrue( orders.size() == 3 );
|
||||||
}
|
|
||||||
|
|
||||||
private void createTestOrders() {
|
|
||||||
em.getTransaction().begin();
|
|
||||||
em.persist( new Order( "order-1", 1.0d ) );
|
|
||||||
em.persist( new Order( "order-2", 10.0d ) );
|
|
||||||
em.persist( new Order( "order-3", new char[]{'r','u'} ) );
|
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check predicate for field which has simple char array type (char[]).
|
* Check predicate for field which has simple char array type (char[]).
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCharArray() {
|
public void testCharArray() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
|
||||||
|
@ -166,12 +196,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||||
assertTrue( orders.size() == 1 );
|
assertTrue( orders.size() == 1 );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check predicate for field which has simple char array type (byte[]).
|
* Check predicate for field which has simple char array type (byte[]).
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testByteArray() {
|
public void testByteArray() {
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
CriteriaQuery<Order> orderCriteria = builder.createQuery( Order.class );
|
||||||
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
Root<Order> orderRoot = orderCriteria.from( Order.class );
|
||||||
|
|
||||||
|
@ -181,6 +216,8 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
|
||||||
|
|
||||||
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
|
||||||
assertTrue( orders.size() == 0 );
|
assertTrue( orders.size() == 0 );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,23 +22,30 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.components;
|
package org.hibernate.ejb.criteria.components;
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author alan.oleary
|
* @author alan.oleary
|
||||||
*/
|
*/
|
||||||
public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase {
|
public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { Client.class };
|
return new Class[] { Client.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmbeddableInPath() {
|
public void testEmbeddableInPath() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -54,7 +61,7 @@ public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
Root<Client> root = cq.from(Client.class);
|
Root<Client> root = cq.from(Client.class);
|
||||||
cq.where(cb.equal(root.get("name").get("firstName"), client.getName().getFirstName()));
|
cq.where(cb.equal(root.get("name").get("firstName"), client.getName().getFirstName()));
|
||||||
List<Client> list = em.createQuery(cq).getResultList();
|
List<Client> list = em.createQuery(cq).getResultList();
|
||||||
assertEquals(1, list.size());
|
Assert.assertEquals( 1, list.size() );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
|
@ -65,8 +72,9 @@ public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH-4586" )
|
||||||
public void testParameterizedFunctions() {
|
public void testParameterizedFunctions() {
|
||||||
// HHH-4586
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
CriteriaBuilder cb = em.getCriteriaBuilder();
|
CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||||
|
|
|
@ -22,25 +22,27 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.paths;
|
package org.hibernate.ejb.criteria.paths;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Join;
|
import javax.persistence.criteria.Join;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||||
import org.hibernate.ejb.metamodel.LineItem;
|
import org.hibernate.ejb.metamodel.LineItem;
|
||||||
import org.hibernate.ejb.metamodel.LineItem_;
|
import org.hibernate.ejb.metamodel.LineItem_;
|
||||||
import org.hibernate.ejb.metamodel.Order;
|
import org.hibernate.ejb.metamodel.Order;
|
||||||
import org.hibernate.ejb.metamodel.Order_;
|
import org.hibernate.ejb.metamodel.Order_;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ImplicitJoinTest extends AbstractMetamodelSpecificTest {
|
public class ImplicitJoinTest extends AbstractMetamodelSpecificTest {
|
||||||
|
@Test
|
||||||
public void testImplicitJoinFromExplicitCollectionJoin() {
|
public void testImplicitJoinFromExplicitCollectionJoin() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
|
@ -22,12 +22,14 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.subquery;
|
package org.hibernate.ejb.criteria.subquery;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Join;
|
import javax.persistence.criteria.Join;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import javax.persistence.criteria.Subquery;
|
import javax.persistence.criteria.Subquery;
|
||||||
|
|
||||||
import org.hibernate.dialect.SybaseASE15Dialect;
|
import org.hibernate.dialect.SybaseASE15Dialect;
|
||||||
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||||
import org.hibernate.ejb.metamodel.Customer;
|
import org.hibernate.ejb.metamodel.Customer;
|
||||||
|
@ -37,14 +39,17 @@ import org.hibernate.ejb.metamodel.LineItem_;
|
||||||
import org.hibernate.ejb.metamodel.Order;
|
import org.hibernate.ejb.metamodel.Order;
|
||||||
import org.hibernate.ejb.metamodel.Order_;
|
import org.hibernate.ejb.metamodel.Order_;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.SkipForDialect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
|
public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
|
||||||
|
@Test
|
||||||
public void testBasicCorrelation() {
|
public void testBasicCorrelation() {
|
||||||
CriteriaBuilder builder = factory.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
@ -62,8 +67,9 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRestrictedCorrelation() {
|
public void testRestrictedCorrelation() {
|
||||||
CriteriaBuilder builder = factory.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
@ -83,9 +89,10 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@org.hibernate.testing.SkipForDialect(value=SybaseASE15Dialect.class, jiraKey="HHH-3032")
|
@Test
|
||||||
|
@SkipForDialect(value=SybaseASE15Dialect.class, jiraKey="HHH-3032")
|
||||||
public void testCorrelationExplicitSelectionCorrelation() {
|
public void testCorrelationExplicitSelectionCorrelation() {
|
||||||
CriteriaBuilder builder = factory.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
@ -106,8 +113,9 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRestrictedCorrelationNoExplicitSelection() {
|
public void testRestrictedCorrelationNoExplicitSelection() {
|
||||||
CriteriaBuilder builder = factory.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
|
|
@ -22,26 +22,29 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.criteria.subquery;
|
package org.hibernate.ejb.criteria.subquery;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Join;
|
import javax.persistence.criteria.Join;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import javax.persistence.criteria.Subquery;
|
import javax.persistence.criteria.Subquery;
|
||||||
|
|
||||||
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||||
import org.hibernate.ejb.metamodel.Customer;
|
import org.hibernate.ejb.metamodel.Customer;
|
||||||
import org.hibernate.ejb.metamodel.Customer_;
|
import org.hibernate.ejb.metamodel.Customer_;
|
||||||
import org.hibernate.ejb.metamodel.Order;
|
import org.hibernate.ejb.metamodel.Order;
|
||||||
import org.hibernate.ejb.metamodel.Order_;
|
import org.hibernate.ejb.metamodel.Order_;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class UncorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
|
public class UncorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
|
||||||
|
@Test
|
||||||
public void testEqualAll() {
|
public void testEqualAll() {
|
||||||
CriteriaBuilder builder = factory.getCriteriaBuilder();
|
CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.criteria.tuple;
|
package org.hibernate.ejb.criteria.tuple;
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Tuple;
|
import javax.persistence.Tuple;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Path;
|
import javax.persistence.criteria.Path;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
|
||||||
import org.hibernate.ejb.metamodel.Customer;
|
import org.hibernate.ejb.metamodel.Customer;
|
||||||
import org.hibernate.ejb.metamodel.Customer_;
|
import org.hibernate.ejb.metamodel.Customer_;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class TupleCriteriaTest extends AbstractMetamodelSpecificTest {
|
public class TupleCriteriaTest extends AbstractMetamodelSpecificTest {
|
||||||
|
@Test
|
||||||
public void testArray() {
|
public void testArray() {
|
||||||
EntityManager em = factory.createEntityManager();
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Customer c1 = new Customer();
|
Customer c1 = new Customer();
|
||||||
c1.setId( "c1" );
|
c1.setId( "c1" );
|
||||||
|
@ -25,7 +56,7 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = factory.createEntityManager();
|
em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
final CriteriaBuilder cb = em.getCriteriaBuilder();
|
final CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||||
CriteriaQuery<Object[]> q = cb.createQuery(Object[].class);
|
CriteriaQuery<Object[]> q = cb.createQuery(Object[].class);
|
||||||
|
@ -38,16 +69,16 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = factory.createEntityManager();
|
em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.createQuery( "delete Customer" ).executeUpdate();
|
em.createQuery( "delete Customer" ).executeUpdate();
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTuple() {
|
public void testTuple() {
|
||||||
EntityManager em = factory.createEntityManager();
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Customer c1 = new Customer();
|
Customer c1 = new Customer();
|
||||||
|
@ -58,7 +89,7 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = factory.createEntityManager();
|
em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
final CriteriaBuilder builder = em.getCriteriaBuilder();
|
final CriteriaBuilder builder = em.getCriteriaBuilder();
|
||||||
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
|
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
|
||||||
|
@ -82,7 +113,7 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = factory.createEntityManager();
|
em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.createQuery( "delete Customer" ).executeUpdate();
|
em.createQuery( "delete Customer" ).executeUpdate();
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
|
|
@ -25,8 +25,6 @@ package org.hibernate.ejb.metamodel;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractMetamodelSpecificTest extends BaseEntityManagerFunctionalTestCase {
|
public abstract class AbstractMetamodelSpecificTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
|
@ -22,14 +22,22 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.metamodel;
|
package org.hibernate.ejb.metamodel;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.metamodel.EntityType;
|
import javax.persistence.metamodel.EntityType;
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
import javax.persistence.metamodel.SingularAttribute;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase {
|
public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@ -40,8 +48,9 @@ public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH-4702" )
|
||||||
public void testSingularAttributeAccessByName() {
|
public void testSingularAttributeAccessByName() {
|
||||||
// HHH-4702
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
@ -55,8 +64,9 @@ public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH-5821" )
|
||||||
public void testVersionAttributeMetadata() {
|
public void testVersionAttributeMetadata() {
|
||||||
// HHH-5821
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
EntityType<VersionedEntity> metadata = em.getMetamodel().entity( VersionedEntity.class );
|
EntityType<VersionedEntity> metadata = em.getMetamodel().entity( VersionedEntity.class );
|
||||||
assertNotNull( metadata.getDeclaredVersion( int.class ) );
|
assertNotNull( metadata.getDeclaredVersion( int.class ) );
|
||||||
|
|
|
@ -42,8 +42,9 @@ import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
|
|
||||||
import org.hibernate.testing.AfterClassOnce;
|
import org.junit.After;
|
||||||
import org.hibernate.testing.BeforeClassOnce;
|
import org.junit.Before;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
import static org.hibernate.testing.TestLogger.LOG;
|
import static org.hibernate.testing.TestLogger.LOG;
|
||||||
|
@ -55,32 +56,46 @@ import static org.hibernate.testing.TestLogger.LOG;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCase {
|
public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCase {
|
||||||
|
// IMPL NOTE : Here we use @Before and @After (instead of @BeforeClassOnce and @AfterClassOnce like we do in
|
||||||
|
// BaseCoreFunctionalTestCase) because the old HEM test methodology was to create an EMF for each test method.
|
||||||
|
|
||||||
private static final Dialect dialect = Dialect.getDialect();
|
private static final Dialect dialect = Dialect.getDialect();
|
||||||
private static ServiceRegistryImpl serviceRegistry;
|
|
||||||
private static EntityManagerFactory factory;
|
private Ejb3Configuration ejb3Configuration;
|
||||||
|
private ServiceRegistryImpl serviceRegistry;
|
||||||
|
private EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
private ArrayList<EntityManager> isolatedEms = new ArrayList<EntityManager>();
|
private ArrayList<EntityManager> isolatedEms = new ArrayList<EntityManager>();
|
||||||
|
|
||||||
public static Dialect getDialect() {
|
protected Dialect getDialect() {
|
||||||
return dialect;
|
return dialect;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected
|
protected EntityManagerFactory entityManagerFactory() {
|
||||||
@BeforeClassOnce
|
return entityManagerFactory;
|
||||||
private void buildSessionFactory() throws Exception {
|
}
|
||||||
|
|
||||||
|
protected ServiceRegistryImpl serviceRegistry() {
|
||||||
|
return serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
|
public void buildSessionFactory() throws Exception {
|
||||||
LOG.trace( "Building session factory" );
|
LOG.trace( "Building session factory" );
|
||||||
Ejb3Configuration ejb3Configuration = buildConfiguration();
|
ejb3Configuration = buildConfiguration();
|
||||||
|
ejb3Configuration.configure( getConfig() );
|
||||||
|
afterConfigurationBuilt( ejb3Configuration );
|
||||||
serviceRegistry = buildServiceRegistry( ejb3Configuration.getHibernateConfiguration() );
|
serviceRegistry = buildServiceRegistry( ejb3Configuration.getHibernateConfiguration() );
|
||||||
factory = ejb3Configuration.createEntityManagerFactory( getConfig(), serviceRegistry );
|
applyServices( serviceRegistry );
|
||||||
|
entityManagerFactory = ejb3Configuration.buildEntityManagerFactory( serviceRegistry );
|
||||||
afterEntityManagerFactoryBuilt();
|
afterEntityManagerFactoryBuilt();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Ejb3Configuration buildConfiguration() {
|
protected Ejb3Configuration buildConfiguration() {
|
||||||
Ejb3Configuration ejb3Cfg = constructConfiguration();
|
Ejb3Configuration ejb3Cfg = constructConfiguration();
|
||||||
configure( ejb3Cfg.getHibernateConfiguration() );
|
|
||||||
addMappings( ejb3Cfg.getHibernateConfiguration() );
|
addMappings( ejb3Cfg.getHibernateConfiguration() );
|
||||||
ejb3Cfg.getHibernateConfiguration().buildMappings();
|
|
||||||
afterConfigurationBuilt( ejb3Cfg.getHibernateConfiguration() );
|
|
||||||
return ejb3Cfg;
|
return ejb3Cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +113,19 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
return ejb3Configuration;
|
return ejb3Configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void configure(Configuration hibernateConfiguration) {
|
protected void addMappings(Configuration configuration) {
|
||||||
|
String[] mappings = getMappings();
|
||||||
|
if ( mappings != null ) {
|
||||||
|
for ( String mapping : mappings ) {
|
||||||
|
configuration.addResource( mapping, getClass().getClassLoader() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final String[] NO_MAPPINGS = new String[0];
|
||||||
|
|
||||||
|
protected String[] getMappings() {
|
||||||
|
return NO_MAPPINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map getConfig() {
|
protected Map getConfig() {
|
||||||
|
@ -108,16 +135,10 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
|
classes.addAll( Arrays.asList( getAnnotatedClasses() ) );
|
||||||
config.put( AvailableSettings.LOADED_CLASSES, classes );
|
config.put( AvailableSettings.LOADED_CLASSES, classes );
|
||||||
for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
|
for ( Map.Entry<Class, String> entry : getCachedClasses().entrySet() ) {
|
||||||
config.put(
|
config.put( AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(), entry.getValue() );
|
||||||
AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(),
|
|
||||||
entry.getValue()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
|
for ( Map.Entry<String, String> entry : getCachedCollections().entrySet() ) {
|
||||||
config.put(
|
config.put( AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(), entry.getValue() );
|
||||||
AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(),
|
|
||||||
entry.getValue()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if ( getEjb3DD().length > 0 ) {
|
if ( getEjb3DD().length > 0 ) {
|
||||||
ArrayList<String> dds = new ArrayList<String>();
|
ArrayList<String> dds = new ArrayList<String>();
|
||||||
|
@ -132,44 +153,25 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
protected void addConfigOptions(Map options) {
|
protected void addConfigOptions(Map options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addMappings(Configuration configuration) {
|
private Properties loadProperties() {
|
||||||
String[] mappings = getMappings();
|
Properties props = new Properties();
|
||||||
if ( mappings != null ) {
|
InputStream stream = Persistence.class.getResourceAsStream( "/hibernate.properties" );
|
||||||
for ( String mapping : mappings ) {
|
if ( stream != null ) {
|
||||||
configuration.addResource(
|
try {
|
||||||
getBaseForMappings() + mapping,
|
props.load( stream );
|
||||||
getClass().getClassLoader()
|
}
|
||||||
);
|
catch ( Exception e ) {
|
||||||
|
throw new RuntimeException( "could not load hibernate.properties" );
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
catch ( IOException ignored ) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Class<?>[] annotatedClasses = getAnnotatedClasses();
|
return props;
|
||||||
// if ( annotatedClasses != null ) {
|
|
||||||
// for ( Class<?> annotatedClass : annotatedClasses ) {
|
|
||||||
// configuration.addAnnotatedClass( annotatedClass );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// String[] annotatedPackages = getAnnotatedPackages();
|
|
||||||
// if ( annotatedPackages != null ) {
|
|
||||||
// for ( String annotatedPackage : annotatedPackages ) {
|
|
||||||
// configuration.addPackage( annotatedPackage );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// String[] xmlFiles = getOrmXmlFiles();
|
|
||||||
// if ( xmlFiles != null ) {
|
|
||||||
// for ( String xmlFile : xmlFiles ) {
|
|
||||||
// configuration.addResource( xmlFile );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static final String[] NO_MAPPINGS = new String[0];
|
|
||||||
|
|
||||||
protected String[] getMappings() {
|
|
||||||
return NO_MAPPINGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getBaseForMappings() {
|
|
||||||
return "org/hibernate/test/";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final Class<?>[] NO_CLASSES = new Class[0];
|
protected static final Class<?>[] NO_CLASSES = new Class[0];
|
||||||
|
@ -178,15 +180,20 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
return NO_CLASSES;
|
return NO_CLASSES;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] getAnnotatedPackages() {
|
public Map<Class, String> getCachedClasses() {
|
||||||
return NO_MAPPINGS;
|
return new HashMap<Class, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] getOrmXmlFiles() {
|
public Map<String, String> getCachedCollections() {
|
||||||
return NO_MAPPINGS;
|
return new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void afterConfigurationBuilt(Configuration hibernateConfiguration) {
|
public String[] getEjb3DD() {
|
||||||
|
return new String[] { };
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"UnusedParameters"})
|
||||||
|
protected void afterConfigurationBuilt(Ejb3Configuration ejb3Configuration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ServiceRegistryImpl buildServiceRegistry(Configuration configuration) {
|
protected ServiceRegistryImpl buildServiceRegistry(Configuration configuration) {
|
||||||
|
@ -194,11 +201,10 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
properties.putAll( configuration.getProperties() );
|
properties.putAll( configuration.getProperties() );
|
||||||
Environment.verifyProperties( properties );
|
Environment.verifyProperties( properties );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( properties );
|
return new ServiceRegistryImpl( properties );
|
||||||
applyServices( serviceRegistry );
|
|
||||||
return serviceRegistry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"UnusedParameters"})
|
||||||
protected void applyServices(ServiceRegistryImpl serviceRegistry) {
|
protected void applyServices(ServiceRegistryImpl serviceRegistry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,22 +216,29 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@AfterClassOnce
|
@After
|
||||||
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
public void releaseResources() {
|
public void releaseResources() {
|
||||||
cleanUnclosed( this.em );
|
releaseUnclosedEntityManagers();
|
||||||
for ( EntityManager isolatedEm : isolatedEms ) {
|
|
||||||
cleanUnclosed( isolatedEm );
|
if ( entityManagerFactory != null ) {
|
||||||
|
entityManagerFactory.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( factory != null ) {
|
|
||||||
factory.close();
|
|
||||||
}
|
|
||||||
if ( serviceRegistry != null ) {
|
if ( serviceRegistry != null ) {
|
||||||
serviceRegistry.destroy();
|
serviceRegistry.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanUnclosed(EntityManager em) {
|
private void releaseUnclosedEntityManagers() {
|
||||||
|
releaseUnclosedEntityManager( this.em );
|
||||||
|
|
||||||
|
for ( EntityManager isolatedEm : isolatedEms ) {
|
||||||
|
releaseUnclosedEntityManager( isolatedEm );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseUnclosedEntityManager(EntityManager em) {
|
||||||
if ( em == null ) {
|
if ( em == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -243,65 +256,29 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa
|
||||||
|
|
||||||
protected EntityManager getOrCreateEntityManager() {
|
protected EntityManager getOrCreateEntityManager() {
|
||||||
if ( em == null || !em.isOpen() ) {
|
if ( em == null || !em.isOpen() ) {
|
||||||
em = factory.createEntityManager();
|
em = entityManagerFactory.createEntityManager();
|
||||||
}
|
}
|
||||||
return em;
|
return em;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EntityManager createIsolatedEntityManager() {
|
protected EntityManager createIsolatedEntityManager() {
|
||||||
EntityManager isolatedEm = factory.createEntityManager();
|
EntityManager isolatedEm = entityManagerFactory.createEntityManager();
|
||||||
isolatedEms.add( isolatedEm );
|
isolatedEms.add( isolatedEm );
|
||||||
return isolatedEm;
|
return isolatedEm;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EntityManager createIsolatedEntityManager(Map props) {
|
protected EntityManager createIsolatedEntityManager(Map props) {
|
||||||
EntityManager isolatedEm = factory.createEntityManager(props);
|
EntityManager isolatedEm = entityManagerFactory.createEntityManager(props);
|
||||||
isolatedEms.add( isolatedEm );
|
isolatedEms.add( isolatedEm );
|
||||||
return isolatedEm;
|
return isolatedEm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* always reopen a new EM and clse the existing one
|
|
||||||
*/
|
|
||||||
protected EntityManager createEntityManager(Map properties) {
|
protected EntityManager createEntityManager(Map properties) {
|
||||||
|
// always reopen a new EM and close the existing one
|
||||||
if ( em != null && em.isOpen() ) {
|
if ( em != null && em.isOpen() ) {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
em = factory.createEntityManager( properties );
|
em = entityManagerFactory.createEntityManager( properties );
|
||||||
return em;
|
return em;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getEjb3DD() {
|
|
||||||
return new String[] { };
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Class, String> getCachedClasses() {
|
|
||||||
return new HashMap<Class, String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getCachedCollections() {
|
|
||||||
return new HashMap<String, String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Properties loadProperties() {
|
|
||||||
Properties props = new Properties();
|
|
||||||
InputStream stream = Persistence.class.getResourceAsStream( "/hibernate.properties" );
|
|
||||||
if ( stream != null ) {
|
|
||||||
try {
|
|
||||||
props.load( stream );
|
|
||||||
}
|
|
||||||
catch ( Exception e ) {
|
|
||||||
throw new RuntimeException( "could not load hibernate.properties" );
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
try {
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
catch ( IOException ioe ) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,17 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.HibernateEntityManager;
|
import org.hibernate.ejb.HibernateEntityManager;
|
||||||
import org.hibernate.ejb.HibernateEntityManagerFactory;
|
import org.hibernate.ejb.HibernateEntityManagerFactory;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -56,7 +62,7 @@ import static org.junit.Assert.fail;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Item.class,
|
Item.class,
|
||||||
|
@ -65,20 +71,27 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
|
protected void addConfigOptions(Map options) {
|
||||||
|
options.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Map<Class, String> getCachedClasses() {
|
public Map<Class, String> getCachedClasses() {
|
||||||
Map<Class, String> result = new HashMap<Class, String>();
|
Map<Class, String> result = new HashMap<Class, String>();
|
||||||
result.put( Item.class, "read-write" );
|
result.put( Item.class, "read-write" );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Map<String, String> getCachedCollections() {
|
public Map<String, String> getCachedCollections() {
|
||||||
Map<String, String> result = new HashMap<String, String>();
|
Map<String, String> result = new HashMap<String, String>();
|
||||||
result.put( Item.class.getName() + ".distributors", "read-write, RegionName" );
|
result.put( Item.class.getName() + ".distributors", "read-write, RegionName" );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEntityManager() {
|
public void testEntityManager() {
|
||||||
|
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -121,16 +134,16 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConfiguration() throws Exception {
|
public void testConfiguration() throws Exception {
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
Distributor res = new Distributor();
|
Distributor res = new Distributor();
|
||||||
res.setName( "Bruce" );
|
res.setName( "Bruce" );
|
||||||
item.setDistributors( new HashSet<Distributor>() );
|
item.setDistributors( new HashSet<Distributor>() );
|
||||||
item.getDistributors().add( res );
|
item.getDistributors().add( res );
|
||||||
Statistics stats = ( ( HibernateEntityManagerFactory ) factory ).getSessionFactory().getStatistics();
|
Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics();
|
||||||
stats.clear();
|
stats.clear();
|
||||||
stats.setStatisticsEnabled( true );
|
stats.setStatisticsEnabled( true );
|
||||||
|
|
||||||
|
@ -169,6 +182,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
stats.setStatisticsEnabled( false );
|
stats.setStatisticsEnabled( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testContains() throws Exception {
|
public void testContains() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -201,6 +215,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testClear() throws Exception {
|
public void testClear() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -216,6 +231,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFlushMode() throws Exception {
|
public void testFlushMode() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.setFlushMode( FlushModeType.COMMIT );
|
em.setFlushMode( FlushModeType.COMMIT );
|
||||||
|
@ -225,6 +241,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPersistNoneGenerator() throws Exception {
|
public void testPersistNoneGenerator() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -242,6 +259,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerializableException() throws Exception {
|
public void testSerializableException() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -284,6 +302,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertNotNull( e.getCause() );
|
assertNotNull( e.getCause() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIsOpen() throws Exception {
|
public void testIsOpen() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
assertTrue( em.isOpen() );
|
assertTrue( em.isOpen() );
|
||||||
|
@ -294,7 +313,8 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertFalse( em.isOpen() );
|
assertFalse( em.isOpen() );
|
||||||
}
|
}
|
||||||
|
|
||||||
//EJB-9
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "EJB-9" )
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -315,6 +335,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetProperties() throws Exception {
|
public void testGetProperties() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Map<String, Object> properties = em.getProperties();
|
Map<String, Object> properties = em.getProperties();
|
||||||
|
@ -330,6 +351,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertTrue( properties.containsKey( AvailableSettings.FLUSH_MODE ) );
|
assertTrue( properties.containsKey( AvailableSettings.FLUSH_MODE ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetProperty() throws Exception {
|
public void testSetProperty() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
//$Id$
|
|
||||||
package org.hibernate.ejb.test.association;
|
package org.hibernate.ejb.test.association;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class AssociationTest extends BaseEntityManagerFunctionalTestCase {
|
public class AssociationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testBidirOneToOne() throws Exception {
|
public void testBidirOneToOne() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -20,13 +24,16 @@ public class AssociationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.persist( i );
|
em.persist( i );
|
||||||
}
|
}
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.clear();
|
em.close();
|
||||||
|
|
||||||
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.remove( em.find(Incident.class, id) );
|
em.remove( em.find(Incident.class, id) );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeAndBidirOneToOne() throws Exception {
|
public void testMergeAndBidirOneToOne() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -36,16 +43,23 @@ public class AssociationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.persist( kitchen );
|
em.persist( kitchen );
|
||||||
kitchen.setOven( oven );
|
kitchen.setOven( oven );
|
||||||
oven.setKitchen( kitchen );
|
oven.setKitchen( kitchen );
|
||||||
em.flush();
|
em.getTransaction().commit();
|
||||||
em.clear();
|
em.close();
|
||||||
//oven = em.find(Oven.class, oven.getId() );
|
|
||||||
oven = em.merge( oven );
|
|
||||||
em.flush();
|
|
||||||
|
|
||||||
em.getTransaction().rollback();
|
em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
oven = em.merge( oven );
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
|
|
||||||
|
em = getOrCreateEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.remove( em.find( Oven.class, oven.getId() ) );
|
||||||
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Incident.class,
|
Incident.class,
|
||||||
|
|
|
@ -1,16 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.beanvalidation;
|
package org.hibernate.ejb.test.beanvalidation;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.RollbackException;
|
import javax.persistence.RollbackException;
|
||||||
import javax.validation.ConstraintViolationException;
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase {
|
public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testBeanValidationIntegrationOnFlush() {
|
public void testBeanValidationIntegrationOnFlush() {
|
||||||
CupHolder ch = new CupHolder();
|
CupHolder ch = new CupHolder();
|
||||||
ch.setRadius( new BigDecimal( "12" ) );
|
ch.setRadius( new BigDecimal( "12" ) );
|
||||||
|
@ -32,6 +62,7 @@ public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBeanValidationIntegrationOnCommit() {
|
public void testBeanValidationIntegrationOnCommit() {
|
||||||
CupHolder ch = new CupHolder();
|
CupHolder ch = new CupHolder();
|
||||||
ch.setRadius( new BigDecimal( "9" ) );
|
ch.setRadius( new BigDecimal( "9" ) );
|
||||||
|
|
|
@ -22,10 +22,12 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.cacheable.cachemodes;
|
package org.hibernate.ejb.test.cacheable.cachemodes;
|
||||||
|
|
||||||
import javax.persistence.CacheRetrieveMode;
|
import javax.persistence.CacheRetrieveMode;
|
||||||
import javax.persistence.CacheStoreMode;
|
import javax.persistence.CacheStoreMode;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
|
@ -34,9 +36,11 @@ import org.hibernate.ejb.HibernateQuery;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.impl.AbstractQueryImpl;
|
import org.hibernate.impl.AbstractQueryImpl;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
|
public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@ -45,8 +49,7 @@ public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
return new Class[] { SimpleEntity.class };
|
return new Class[] { SimpleEntity.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is all i can do for now testing-wise since I did not implement @Cacheable first ;)
|
@Test
|
||||||
|
|
||||||
public void testEntityManagerCacheModes() {
|
public void testEntityManagerCacheModes() {
|
||||||
|
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
@ -82,6 +85,7 @@ public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertEquals( CacheMode.REFRESH, session.getCacheMode() );
|
assertEquals( CacheMode.REFRESH, session.getCacheMode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testQueryCacheModes() {
|
public void testQueryCacheModes() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Query jpaQuery = em.createQuery( "from SimpleEntity" );
|
Query jpaQuery = em.createQuery( "from SimpleEntity" );
|
||||||
|
|
|
@ -1,15 +1,44 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.callbacks;
|
package org.hibernate.ejb.test.callbacks;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
|
public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testDirtyButNotDirty() throws Exception {
|
public void testDirtyButNotDirty() throws Exception {
|
||||||
EntityManager manager = getOrCreateEntityManager();
|
EntityManager manager = getOrCreateEntityManager();
|
||||||
manager.getTransaction().begin();
|
manager.getTransaction().begin();
|
||||||
|
@ -81,6 +110,7 @@ public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
manager.close();
|
manager.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Customer.class,
|
Customer.class,
|
||||||
|
|
|
@ -1,20 +1,30 @@
|
||||||
//$Id$
|
|
||||||
package org.hibernate.ejb.test.callbacks;
|
package org.hibernate.ejb.test.callbacks;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.ejb.test.Cat;
|
import org.hibernate.ejb.test.Cat;
|
||||||
import org.hibernate.ejb.test.Kitten;
|
import org.hibernate.ejb.test.Kitten;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testCallbackMethod() throws Exception {
|
public void testCallbackMethod() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Cat c = new Cat();
|
Cat c = new Cat();
|
||||||
|
@ -37,6 +47,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEntityListener() throws Exception {
|
public void testEntityListener() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Cat c = new Cat();
|
Cat c = new Cat();
|
||||||
|
@ -63,7 +74,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPostPersist() throws Exception {
|
public void testPostPersist() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Cat c = new Cat();
|
Cat c = new Cat();
|
||||||
|
@ -103,6 +114,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPrePersistOnCascade() throws Exception {
|
public void testPrePersistOnCascade() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -118,6 +130,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCallBackListenersHierarchy() throws Exception {
|
public void testCallBackListenersHierarchy() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -133,6 +146,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertTrue( tv.isLast );
|
assertTrue( tv.isLast );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testException() throws Exception {
|
public void testException() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -154,6 +168,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIdNullSetByPrePersist() throws Exception {
|
public void testIdNullSetByPrePersist() throws Exception {
|
||||||
Plant plant = new Plant();
|
Plant plant = new Plant();
|
||||||
plant.setName( "Origuna plantula gigantic" );
|
plant.setName( "Origuna plantula gigantic" );
|
||||||
|
@ -165,6 +180,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@FailureExpected(message = "collection change does not trigger an event", jiraKey = "EJB-288")
|
@FailureExpected(message = "collection change does not trigger an event", jiraKey = "EJB-288")
|
||||||
public void testPostUpdateCollection() throws Exception {
|
public void testPostUpdateCollection() throws Exception {
|
||||||
// create a cat
|
// create a cat
|
||||||
|
@ -220,6 +236,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Cat.class,
|
Cat.class,
|
||||||
|
|
|
@ -1,23 +1,45 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.cascade;
|
package org.hibernate.ejb.test.cascade;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Max Rydahl Andersen
|
* @author Max Rydahl Andersen
|
||||||
*/
|
*/
|
||||||
public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
|
public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testCascade() throws Exception {
|
public void testCascade() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
Teacher teacher = null;
|
Teacher teacher = new Teacher();
|
||||||
|
|
||||||
teacher = new Teacher();
|
|
||||||
|
|
||||||
Student student = new Student();
|
Student student = new Student();
|
||||||
|
|
||||||
|
@ -46,10 +68,9 @@ public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes.
|
em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes.
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNoCascadeAndMerge() throws Exception {
|
public void testNoCascadeAndMerge() throws Exception {
|
||||||
Song e1 = new Song();
|
Song e1 = new Song();
|
||||||
Author e2 = new Author();
|
Author e2 = new Author();
|
||||||
|
@ -67,7 +88,6 @@ public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
|
|
||||||
e1 = em.find(Song.class, e1.getId());
|
e1 = em.find(Song.class, e1.getId());
|
||||||
e2 = null;
|
|
||||||
|
|
||||||
|
|
||||||
tx = em.getTransaction();
|
tx = em.getTransaction();
|
||||||
|
@ -76,10 +96,9 @@ public class CascadeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
//em.refresh(e1);
|
//em.refresh(e1);
|
||||||
tx.commit();
|
tx.commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Teacher.class,
|
Teacher.class,
|
||||||
|
|
|
@ -1,5 +1,28 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.cascade;
|
package org.hibernate.ejb.test.cascade;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -11,10 +34,14 @@ import javax.persistence.EntityTransaction;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
|
public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testDeleteOrphan() throws Exception {
|
public void testDeleteOrphan() throws Exception {
|
||||||
EntityTransaction tx;
|
EntityTransaction tx;
|
||||||
|
|
||||||
|
@ -41,7 +68,7 @@ public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
Soldier soldier = troop.getSoldiers().iterator().next();
|
Soldier soldier = troop.getSoldiers().iterator().next();
|
||||||
troop.getSoldiers().remove( soldier );
|
troop.getSoldiers().remove( soldier );
|
||||||
troop = (Troop) unserialize( serialize( troop ) );
|
troop = (Troop) deserialize( serialize( troop ) );
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
tx = em.getTransaction();
|
tx = em.getTransaction();
|
||||||
|
@ -54,13 +81,14 @@ public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
tx = em.getTransaction();
|
tx = em.getTransaction();
|
||||||
tx.begin();
|
tx.begin();
|
||||||
soldier = em.find( Soldier.class, mickey.getId() );
|
soldier = em.find( Soldier.class, mickey.getId() );
|
||||||
assertNull( "delete-orphan should work", soldier );
|
Assert.assertNull( "delete-orphan should work", soldier );
|
||||||
troop = em.find( Troop.class, disney.getId() );
|
troop = em.find( Troop.class, disney.getId() );
|
||||||
em.remove( troop );
|
em.remove( troop );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Troop.class,
|
Troop.class,
|
||||||
|
@ -78,7 +106,7 @@ public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object unserialize(byte[] serialized) throws IOException, ClassNotFoundException {
|
private Object deserialize(byte[] serialized) throws IOException, ClassNotFoundException {
|
||||||
ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
|
ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
|
||||||
ObjectInputStream in = new ObjectInputStream( byteIn );
|
ObjectInputStream in = new ObjectInputStream( byteIn );
|
||||||
Object result = in.readObject();
|
Object result = in.readObject();
|
||||||
|
|
|
@ -1,21 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.cascade;
|
package org.hibernate.ejb.test.cascade;
|
||||||
import static javax.persistence.CascadeType.DETACH;
|
|
||||||
import static javax.persistence.CascadeType.REMOVE;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static javax.persistence.CascadeType.DETACH;
|
||||||
|
import static javax.persistence.CascadeType.REMOVE;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase {
|
public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testDetach() {
|
public void testDetach() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -49,6 +80,7 @@ public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Mouth.class,
|
Mouth.class,
|
||||||
|
|
|
@ -1,19 +1,48 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.cascade;
|
package org.hibernate.ejb.test.cascade;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.ejb.HibernateEntityManager;
|
import org.hibernate.ejb.HibernateEntityManager;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testCascadeAndFetchCollection() throws Exception {
|
public void testCascadeAndFetchCollection() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -43,6 +72,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCascadeAndFetchEntity() throws Exception {
|
public void testCascadeAndFetchEntity() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -71,6 +101,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTwoLevelDeepPersist() throws Exception {
|
public void testTwoLevelDeepPersist() throws Exception {
|
||||||
EntityTransaction tx;
|
EntityTransaction tx;
|
||||||
|
|
||||||
|
@ -108,6 +139,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTwoLevelDeepPersistOnManyToOne() throws Exception {
|
public void testTwoLevelDeepPersistOnManyToOne() throws Exception {
|
||||||
EntityTransaction tx;
|
EntityTransaction tx;
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -131,6 +163,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPerfCascadeAndFetchEntity() throws Exception {
|
public void testPerfCascadeAndFetchEntity() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
//init data
|
//init data
|
||||||
|
@ -198,7 +231,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Troop.class,
|
Troop.class,
|
||||||
|
|
|
@ -1,12 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.cascade;
|
package org.hibernate.ejb.test.cascade;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
|
public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testProxyTransientStuff() throws Exception {
|
public void testProxyTransientStuff() throws Exception {
|
||||||
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
EntityManager em = factory.createEntityManager();
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
Troop2 disney = new Troop2();
|
Troop2 disney = new Troop2();
|
||||||
|
@ -22,7 +50,7 @@ public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = factory.createEntityManager();
|
em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
Soldier2 soldier = em.find( Soldier2.class, mickey.getId() );
|
Soldier2 soldier = em.find( Soldier2.class, mickey.getId() );
|
||||||
|
@ -37,7 +65,7 @@ public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = factory.createEntityManager();
|
em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
//load troop wo a proxy
|
//load troop wo a proxy
|
||||||
|
@ -56,6 +84,7 @@ public class FetchTest2 extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Troop2.class,
|
Troop2.class,
|
||||||
|
|
|
@ -1,13 +1,37 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.ejb3configuration;
|
package org.hibernate.ejb.test.ejb3configuration;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import org.hibernate.ejb.HibernateEntityManager;
|
import org.hibernate.ejb.HibernateEntityManager;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.ejb.test.Cat;
|
import org.hibernate.ejb.test.Cat;
|
||||||
|
@ -16,15 +40,17 @@ import org.hibernate.ejb.test.Item;
|
||||||
import org.hibernate.ejb.test.Kitten;
|
import org.hibernate.ejb.test.Kitten;
|
||||||
import org.hibernate.ejb.test.Wallet;
|
import org.hibernate.ejb.test.Wallet;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalTestCase {
|
public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testSerialization() throws Exception {
|
public void testSerialization() throws Exception {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
ObjectOutput out = new ObjectOutputStream( stream );
|
ObjectOutput out = new ObjectOutputStream( stream );
|
||||||
out.writeObject( factory );
|
out.writeObject( entityManagerFactory() );
|
||||||
out.close();
|
out.close();
|
||||||
byte[] serialized = stream.toByteArray();
|
byte[] serialized = stream.toByteArray();
|
||||||
stream.close();
|
stream.close();
|
||||||
|
@ -79,6 +105,7 @@ public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalT
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Item.class,
|
Item.class,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//$Id$
|
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
|
@ -23,16 +22,20 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FlushModeTest extends BaseEntityManagerFunctionalTestCase {
|
public class FlushModeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testCreateEMFlushMode() throws Exception {
|
public void testCreateEMFlushMode() throws Exception {
|
||||||
Map<String, String> properties = new HashMap<String, String>();
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
properties.put( "org.hibernate.flushMode", "manual" );
|
properties.put( "org.hibernate.flushMode", "manual" );
|
||||||
|
@ -45,11 +48,12 @@ public class FlushModeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
em.clear();
|
em.clear();
|
||||||
|
|
||||||
assertNull( em.find( Dress.class, dress.name ) );
|
Assert.assertNull( em.find( Dress.class, dress.name ) );
|
||||||
|
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Race.class,
|
Race.class,
|
||||||
|
|
|
@ -1,5 +1,28 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -10,19 +33,37 @@ import javax.persistence.Query;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
private static Set<String> names= new HashSet<String>();
|
private static Set<String> names = namesSet();
|
||||||
static {
|
private static Set<String> namesSet() {
|
||||||
|
HashSet<String> names = new HashSet<String>();
|
||||||
names.add("Toonses");
|
names.add("Toonses");
|
||||||
names.add("Sox");
|
names.add("Sox");
|
||||||
names.add("Winnie");
|
names.add("Winnie");
|
||||||
names.add("Junior");
|
names.add("Junior");
|
||||||
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Test for EJBTHREE-722
|
@Override
|
||||||
|
public Class[] getAnnotatedClasses() {
|
||||||
|
return new Class[] {
|
||||||
|
Pet.class,
|
||||||
|
Dog.class,
|
||||||
|
Cat.class,
|
||||||
|
Decorate.class
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "EJBTHREE-722" )
|
||||||
public void testFlushOnDetached() throws Exception {
|
public void testFlushOnDetached() throws Exception {
|
||||||
EntityManager manager = getOrCreateEntityManager( );
|
EntityManager manager = getOrCreateEntityManager( );
|
||||||
|
|
||||||
|
@ -55,22 +96,21 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
manager.flush();
|
manager.flush();
|
||||||
manager.clear();
|
manager.clear();
|
||||||
for (Object o : l) {
|
for (Object o : l) {
|
||||||
assertTrue( names.contains( ( (Pet) o).getName() ) );
|
Assert.assertTrue( names.contains( ((Pet) o).getName() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<Decorate> founds = getDecorate(manager);
|
Collection<Decorate> founds = getDecorate(manager);
|
||||||
manager.flush();
|
manager.flush();
|
||||||
manager.clear();
|
manager.clear();
|
||||||
for (Decorate value : founds) {
|
for (Decorate value : founds) {
|
||||||
assertTrue( names.contains( value.getPet().getName() ) );
|
Assert.assertTrue( names.contains( value.getPet().getName() ) );
|
||||||
}
|
}
|
||||||
manager.getTransaction().rollback();
|
manager.getTransaction().rollback();
|
||||||
|
|
||||||
manager.close();
|
manager.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dog createDog(String name, double weight, int bones, EntityManager manager) {
|
private Dog createDog(String name, double weight, int bones, EntityManager manager) {
|
||||||
Dog dog = new Dog();
|
Dog dog = new Dog();
|
||||||
dog.setName(name);
|
dog.setName(name);
|
||||||
dog.setWeight(weight);
|
dog.setWeight(weight);
|
||||||
|
@ -79,7 +119,7 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
return dog;
|
return dog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cat createCat(String name, double weight, int lives, EntityManager manager) {
|
private Cat createCat(String name, double weight, int lives, EntityManager manager) {
|
||||||
Cat cat = new Cat();
|
Cat cat = new Cat();
|
||||||
cat.setName(name);
|
cat.setName(name);
|
||||||
cat.setWeight(weight);
|
cat.setWeight(weight);
|
||||||
|
@ -88,13 +128,13 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
return cat;
|
return cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List findByWeight(double weight, EntityManager manager) {
|
private List findByWeight(double weight, EntityManager manager) {
|
||||||
return manager.createQuery(
|
return manager.createQuery(
|
||||||
"select p from Pet p where p.weight < :weight").setParameter(
|
"select p from Pet p where p.weight < :weight").setParameter(
|
||||||
"weight", weight).getResultList();
|
"weight", weight).getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Decorate createDecorate(String name, Pet pet, EntityManager manager) {
|
private Decorate createDecorate(String name, Pet pet, EntityManager manager) {
|
||||||
Decorate dec = new Decorate();
|
Decorate dec = new Decorate();
|
||||||
dec.setName(name);
|
dec.setName(name);
|
||||||
dec.setPet(pet);
|
dec.setPet(pet);
|
||||||
|
@ -102,7 +142,7 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
return dec;
|
return dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Decorate> getDecorate(EntityManager manager) {
|
private Collection<Decorate> getDecorate(EntityManager manager) {
|
||||||
Collection<Decorate> founds = new ArrayList<Decorate>();
|
Collection<Decorate> founds = new ArrayList<Decorate>();
|
||||||
Query query = manager.createQuery("SELECT o FROM Decorate o");
|
Query query = manager.createQuery("SELECT o FROM Decorate o");
|
||||||
List list = query.getResultList();
|
List list = query.getResultList();
|
||||||
|
@ -116,12 +156,4 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
return founds;
|
return founds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
Pet.class,
|
|
||||||
Dog.class,
|
|
||||||
Cat.class,
|
|
||||||
Decorate.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,44 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase {
|
public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testWrongIdType() throws Exception {
|
public void testWrongIdType() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
try {
|
try {
|
||||||
Competitor c = em.getReference( Competitor.class, new String("30") );
|
em.getReference( Competitor.class, "30" );
|
||||||
fail("Expected IllegalArgumentException");
|
fail("Expected IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
|
@ -23,7 +49,7 @@ public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mail c = em.getReference( Mail.class, 1 );
|
em.getReference( Mail.class, 1 );
|
||||||
fail("Expected IllegalArgumentException");
|
fail("Expected IllegalArgumentException");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
|
@ -35,6 +61,7 @@ public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Competitor.class,
|
Competitor.class,
|
||||||
|
|
|
@ -1,14 +1,44 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testMergeWithIndexColumn() {
|
public void testMergeWithIndexColumn() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
race.competitors.add( new Competitor( "Name" ) );
|
race.competitors.add( new Competitor( "Name" ) );
|
||||||
|
@ -33,6 +63,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeManyToMany() {
|
public void testMergeManyToMany() {
|
||||||
Competition competition = new Competition();
|
Competition competition = new Competition();
|
||||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||||
|
@ -65,6 +96,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeManyToManyWithDeference() {
|
public void testMergeManyToManyWithDeference() {
|
||||||
Competition competition = new Competition();
|
Competition competition = new Competition();
|
||||||
competition.getCompetitors().add( new Competitor( "Name" ) );
|
competition.getCompetitors().add( new Competitor( "Name" ) );
|
||||||
|
@ -98,6 +130,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveAndMerge() {
|
public void testRemoveAndMerge() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -122,6 +155,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConcurrentMerge() {
|
public void testConcurrentMerge() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
race.name = "Derby";
|
race.name = "Derby";
|
||||||
|
@ -154,6 +188,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeUnidirectionalOneToMany() throws Exception {
|
public void testMergeUnidirectionalOneToMany() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -173,6 +208,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Race.class,
|
Race.class,
|
||||||
|
|
|
@ -1,13 +1,41 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class RefreshTest extends BaseEntityManagerFunctionalTestCase {
|
public class RefreshTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testRefreshNonManaged() throws Exception {
|
public void testRefreshNonManaged() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -28,6 +56,7 @@ public class RefreshTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Race.class,
|
Race.class,
|
||||||
|
|
|
@ -1,5 +1,28 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.emops;
|
package org.hibernate.ejb.test.emops;
|
||||||
|
|
||||||
import static org.hibernate.testing.TestLogger.LOG;
|
import static org.hibernate.testing.TestLogger.LOG;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -7,11 +30,14 @@ import javax.persistence.OptimisticLockException;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testRemove() {
|
public void testRemove() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
race.competitors.add( new Competitor() );
|
race.competitors.add( new Competitor() );
|
||||||
|
@ -27,17 +53,19 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveAndFind() {
|
public void testRemoveAndFind() {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( race );
|
em.persist( race );
|
||||||
em.remove( race );
|
em.remove( race );
|
||||||
assertNull( em.find( Race.class, race.id ) );
|
Assert.assertNull( em.find( Race.class, race.id ) );
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testUpdatedAndRemove() throws Exception {
|
public void testUpdatedAndRemove() throws Exception {
|
||||||
Music music = new Music();
|
Music music = new Music();
|
||||||
music.setName( "Classical" );
|
music.setName( "Classical" );
|
||||||
|
@ -48,12 +76,13 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.clear();
|
em.clear();
|
||||||
|
|
||||||
|
|
||||||
EntityManager em2 = factory.createEntityManager();
|
EntityManager em2 = entityManagerFactory().createEntityManager();
|
||||||
try {
|
try {
|
||||||
em2.getTransaction().begin();
|
em2.getTransaction().begin();
|
||||||
//read music from 2nd EM
|
//read music from 2nd EM
|
||||||
music = em2.find( Music.class, music.getId() );
|
music = em2.find( Music.class, music.getId() );
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e) {
|
||||||
em2.getTransaction().rollback();
|
em2.getTransaction().rollback();
|
||||||
em2.close();
|
em2.close();
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -68,9 +97,8 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
try {
|
try {
|
||||||
em2.remove( music ); //remove changed music
|
em2.remove( music ); //remove changed music
|
||||||
em2.flush();
|
em2.flush();
|
||||||
fail("should have an optimistic lock exception");
|
Assert.fail( "should have an optimistic lock exception" );
|
||||||
}
|
}
|
||||||
|
|
||||||
catch( OptimisticLockException e ) {
|
catch( OptimisticLockException e ) {
|
||||||
LOG.debug("success");
|
LOG.debug("success");
|
||||||
}
|
}
|
||||||
|
@ -97,9 +125,8 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map getConfig() {
|
@SuppressWarnings( {"unchecked"})
|
||||||
Map cfg = super.getConfig();
|
protected void addConfigOptions(Map options) {
|
||||||
cfg.put( "hibernate.jdbc.batch_size", "0");
|
options.put( "hibernate.jdbc.batch_size", "0" );
|
||||||
return cfg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,43 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.emops.cascade;
|
package org.hibernate.ejb.test.emops.cascade;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase {
|
public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testLazyCollectionsStayLazyOnPersist() throws Exception {
|
public void testLazyCollectionsStayLazyOnPersist() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -81,6 +109,7 @@ public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
A.class,
|
A.class,
|
||||||
|
|
|
@ -1,24 +1,56 @@
|
||||||
// $Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.exception;
|
package org.hibernate.ejb.test.exception;
|
||||||
import static org.hibernate.testing.TestLogger.LOG;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityNotFoundException;
|
import javax.persistence.EntityNotFoundException;
|
||||||
import javax.persistence.OptimisticLockException;
|
import javax.persistence.OptimisticLockException;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.TestLogger.LOG;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testOptimisticLockingException() throws Exception {
|
public void testOptimisticLockingException() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
EntityManager em2 = factory.createEntityManager();
|
EntityManager em2 = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Music music = new Music();
|
Music music = new Music();
|
||||||
music.setName( "Old Country" );
|
music.setName( "Old Country" );
|
||||||
|
@ -59,6 +91,7 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEntityNotFoundException() throws Exception {
|
public void testEntityNotFoundException() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Music music = em.getReference( Music.class, -1 );
|
Music music = em.getReference( Music.class, -1 );
|
||||||
|
@ -74,6 +107,7 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConstraintViolationException() throws Exception {
|
public void testConstraintViolationException() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -102,7 +136,8 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HHH-4676
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH-4676" )
|
||||||
public void testInterceptor() throws Exception {
|
public void testInterceptor() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -119,10 +154,8 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map getConfig() {
|
protected void addConfigOptions(Map options) {
|
||||||
Map config = super.getConfig();
|
options.put( Environment.BATCH_VERSIONED_DATA, "false" );
|
||||||
config.put( Environment.BATCH_VERSIONED_DATA, "false" );
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,13 +1,41 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.inheritance;
|
package org.hibernate.ejb.test.inheritance;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class InheritanceTest extends BaseEntityManagerFunctionalTestCase {
|
public class InheritanceTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testFind() throws Exception {
|
public void testFind() throws Exception {
|
||||||
EntityManager firstSession = getOrCreateEntityManager( );
|
EntityManager firstSession = getOrCreateEntityManager( );
|
||||||
Strawberry u = new Strawberry();
|
Strawberry u = new Strawberry();
|
||||||
|
@ -30,6 +58,8 @@ public class InheritanceTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
firstSession.getTransaction().commit();
|
firstSession.getTransaction().commit();
|
||||||
firstSession.close();
|
firstSession.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Fruit.class,
|
Fruit.class,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
|
@ -34,6 +33,8 @@ import java.util.Map;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.DialectChecks;
|
import org.hibernate.testing.DialectChecks;
|
||||||
import org.hibernate.testing.RequiresDialectFeature;
|
import org.hibernate.testing.RequiresDialectFeature;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
*/
|
*/
|
||||||
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class )
|
||||||
public class BlobTest extends BaseEntityManagerFunctionalTestCase {
|
public class BlobTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testBlobSerialization() throws Exception {
|
public void testBlobSerialization() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -69,6 +70,7 @@ public class BlobTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { ImageReader.class };
|
return new Class[] { ImageReader.class };
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,34 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.lock;
|
package org.hibernate.ejb.test.lock;
|
||||||
import static org.hibernate.testing.TestLogger.LOG;
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.LockModeType;
|
||||||
|
import javax.persistence.LockTimeoutException;
|
||||||
|
import javax.persistence.OptimisticLockException;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import javax.persistence.QueryTimeoutException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -8,22 +36,25 @@ import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.LockModeType;
|
|
||||||
import javax.persistence.LockTimeoutException;
|
|
||||||
import javax.persistence.OptimisticLockException;
|
|
||||||
import javax.persistence.Query;
|
|
||||||
import javax.persistence.QueryTimeoutException;
|
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.Oracle10gDialect;
|
import org.hibernate.dialect.Oracle10gDialect;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hibernate.testing.TestLogger.LOG;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testFindWithTimeoutHint() {
|
public void testFindWithTimeoutHint() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -49,6 +80,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLockRead() throws Exception {
|
public void testLockRead() throws Exception {
|
||||||
Lock lock = new Lock();
|
Lock lock = new Lock();
|
||||||
lock.setName( "name" );
|
lock.setName( "name" );
|
||||||
|
@ -72,6 +104,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLockOptimistic() throws Exception {
|
public void testLockOptimistic() throws Exception {
|
||||||
Lock lock = new Lock();
|
Lock lock = new Lock();
|
||||||
lock.setName( "name" );
|
lock.setName( "name" );
|
||||||
|
@ -95,6 +128,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLockWrite() throws Exception {
|
public void testLockWrite() throws Exception {
|
||||||
Lock lock = new Lock();
|
Lock lock = new Lock();
|
||||||
lock.setName( "second" );
|
lock.setName( "second" );
|
||||||
|
@ -121,6 +155,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLockWriteOnUnversioned() throws Exception {
|
public void testLockWriteOnUnversioned() throws Exception {
|
||||||
UnversionedLock lock = new UnversionedLock();
|
UnversionedLock lock = new UnversionedLock();
|
||||||
lock.setName( "second" );
|
lock.setName( "second" );
|
||||||
|
@ -153,6 +188,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLockPessimisticForceIncrement() throws Exception {
|
public void testLockPessimisticForceIncrement() throws Exception {
|
||||||
Lock lock = new Lock();
|
Lock lock = new Lock();
|
||||||
lock.setName( "force" );
|
lock.setName( "force" );
|
||||||
|
@ -179,6 +215,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLockOptimisticForceIncrement() throws Exception {
|
public void testLockOptimisticForceIncrement() throws Exception {
|
||||||
Lock lock = new Lock();
|
Lock lock = new Lock();
|
||||||
lock.setName( "force" );
|
lock.setName( "force" );
|
||||||
|
@ -205,30 +242,31 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLockOptimisticForceIncrementDifferentEm() throws Exception {
|
@Test
|
||||||
Lock lock = new Lock();
|
public void testLockOptimisticForceIncrementDifferentEm() throws Exception {
|
||||||
lock.setName( "force" );
|
Lock lock = new Lock();
|
||||||
EntityManager em1 = createIsolatedEntityManager();
|
lock.setName( "force" );
|
||||||
em1.getTransaction().begin();
|
EntityManager em1 = createIsolatedEntityManager();
|
||||||
em1.persist( lock );
|
em1.getTransaction().begin();
|
||||||
em1.getTransaction().commit();
|
em1.persist( lock );
|
||||||
em1.close();
|
em1.getTransaction().commit();
|
||||||
|
em1.close();
|
||||||
|
|
||||||
EntityManager em2 = createIsolatedEntityManager();
|
EntityManager em2 = createIsolatedEntityManager();
|
||||||
em2.getTransaction().begin();
|
em2.getTransaction().begin();
|
||||||
lock = em2.find( Lock.class, lock.getId(), LockModeType.OPTIMISTIC );
|
lock = em2.find( Lock.class, lock.getId(), LockModeType.OPTIMISTIC );
|
||||||
assertEquals( "lock mode should be OPTIMISTIC ", LockModeType.OPTIMISTIC, em2.getLockMode(lock) );
|
assertEquals( "lock mode should be OPTIMISTIC ", LockModeType.OPTIMISTIC, em2.getLockMode(lock) );
|
||||||
em2.lock( lock, LockModeType.OPTIMISTIC_FORCE_INCREMENT );
|
em2.lock( lock, LockModeType.OPTIMISTIC_FORCE_INCREMENT );
|
||||||
assertEquals( "lock mode should be OPTIMISTIC_FORCE_INCREMENT ", LockModeType.OPTIMISTIC_FORCE_INCREMENT, em2.getLockMode(lock) );
|
assertEquals( "lock mode should be OPTIMISTIC_FORCE_INCREMENT ", LockModeType.OPTIMISTIC_FORCE_INCREMENT, em2.getLockMode(lock) );
|
||||||
em2.getTransaction().commit();
|
em2.getTransaction().commit();
|
||||||
em2.getTransaction().begin();
|
em2.getTransaction().begin();
|
||||||
em2.remove( lock );
|
em2.remove( lock );
|
||||||
em2.getTransaction().commit();
|
em2.getTransaction().commit();
|
||||||
em2.close();
|
em2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testContendedPessimisticLock() throws Exception {
|
public void testContendedPessimisticLock() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
final EntityManager em2 = createIsolatedEntityManager();
|
final EntityManager em2 = createIsolatedEntityManager();
|
||||||
// TODO: replace dialect instanceof test with a Dialect.hasCapability (e.g. supportsPessimisticWriteLock)
|
// TODO: replace dialect instanceof test with a Dialect.hasCapability (e.g. supportsPessimisticWriteLock)
|
||||||
|
@ -300,8 +338,8 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testContendedPessimisticReadLockTimeout() throws Exception {
|
public void testContendedPessimisticReadLockTimeout() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
final EntityManager em2 = createIsolatedEntityManager();
|
final EntityManager em2 = createIsolatedEntityManager();
|
||||||
// TODO: replace dialect instanceof test with a Dialect.hasCapability (e.g. supportsPessimisticLockTimeout)
|
// TODO: replace dialect instanceof test with a Dialect.hasCapability (e.g. supportsPessimisticLockTimeout)
|
||||||
|
@ -385,6 +423,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testContendedPessimisticWriteLockTimeout() throws Exception {
|
public void testContendedPessimisticWriteLockTimeout() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -470,6 +509,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testContendedPessimisticWriteLockNoWait() throws Exception {
|
public void testContendedPessimisticWriteLockNoWait() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -555,6 +595,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testQueryTimeout() throws Exception {
|
public void testQueryTimeout() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -644,6 +685,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testQueryTimeoutEMProps() throws Exception {
|
public void testQueryTimeoutEMProps() throws Exception {
|
||||||
// TODO: replace dialect instanceof test with a Dialect.hasCapability
|
// TODO: replace dialect instanceof test with a Dialect.hasCapability
|
||||||
if ( ! (getDialect() instanceof Oracle10gDialect)) {
|
if ( ! (getDialect() instanceof Oracle10gDialect)) {
|
||||||
|
@ -734,6 +776,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLockTimeoutEMProps() throws Exception {
|
public void testLockTimeoutEMProps() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -819,7 +862,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Lock.class,
|
Lock.class,
|
||||||
|
|
|
@ -22,23 +22,30 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.lock;
|
package org.hibernate.ejb.test.lock;
|
||||||
import java.util.Map;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.LockModeType;
|
import javax.persistence.LockModeType;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.cfg.AnnotationConfiguration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.QueryImpl;
|
import org.hibernate.ejb.QueryImpl;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.impl.SessionImpl;
|
import org.hibernate.impl.SessionImpl;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
return new Class[] { Lockable.class };
|
return new Class[] { Lockable.class };
|
||||||
|
@ -47,9 +54,10 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "unchecked" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
protected void addConfigOptions(Map options) {
|
protected void addConfigOptions(Map options) {
|
||||||
options.put( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
options.put( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOverallLockMode() {
|
public void testOverallLockMode() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -75,6 +83,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPessimisticForcedIncrementOverall() {
|
public void testPessimisticForcedIncrementOverall() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -99,6 +108,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPessimisticForcedIncrementSpecific() {
|
public void testPessimisticForcedIncrementSpecific() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -125,6 +135,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOptimisticForcedIncrementOverall() {
|
public void testOptimisticForcedIncrementOverall() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -150,6 +161,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOptimisticForcedIncrementSpecific() {
|
public void testOptimisticForcedIncrementSpecific() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -177,6 +189,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOptimisticOverall() {
|
public void testOptimisticOverall() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -205,6 +218,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOptimisticSpecific() {
|
public void testOptimisticSpecific() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
|
@ -1,11 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.mapping;
|
package org.hibernate.ejb.test.mapping;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class QuotingTest extends BaseEntityManagerFunctionalTestCase {
|
public class QuotingTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testQuote() {
|
public void testQuote() {
|
||||||
// the configuration was failing
|
// the configuration was failing
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.metadata;
|
package org.hibernate.ejb.test.metadata;
|
||||||
import java.util.Set;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.metamodel.Attribute;
|
import javax.persistence.metamodel.Attribute;
|
||||||
import javax.persistence.metamodel.Bindable;
|
import javax.persistence.metamodel.Bindable;
|
||||||
|
@ -36,44 +36,58 @@ import javax.persistence.metamodel.PluralAttribute;
|
||||||
import javax.persistence.metamodel.SetAttribute;
|
import javax.persistence.metamodel.SetAttribute;
|
||||||
import javax.persistence.metamodel.SingularAttribute;
|
import javax.persistence.metamodel.SingularAttribute;
|
||||||
import javax.persistence.metamodel.Type;
|
import javax.persistence.metamodel.Type;
|
||||||
import org.hibernate.cfg.AnnotationConfiguration;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
import org.hibernate.ejb.metamodel.MetamodelImpl;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testBaseOfService() throws Exception {
|
public void testBaseOfService() throws Exception {
|
||||||
EntityManagerFactory emf = factory;
|
EntityManagerFactory emf = entityManagerFactory();
|
||||||
assertNotNull( emf.getMetamodel() );
|
assertNotNull( emf.getMetamodel() );
|
||||||
final EntityType<Fridge> entityType = emf.getMetamodel().entity( Fridge.class );
|
final EntityType<Fridge> entityType = emf.getMetamodel().entity( Fridge.class );
|
||||||
assertNotNull( entityType );
|
assertNotNull( entityType );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@SuppressWarnings({ "unchecked" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
public void testBuildingMetamodelWithParameterizedCollection() {
|
public void testBuildingMetamodelWithParameterizedCollection() {
|
||||||
AnnotationConfiguration cfg = new AnnotationConfiguration( );
|
Configuration cfg = new Configuration( );
|
||||||
configure( cfg );
|
// configure( cfg );
|
||||||
cfg.addAnnotatedClass( WithGenericCollection.class );
|
cfg.addAnnotatedClass( WithGenericCollection.class );
|
||||||
cfg.buildMappings();
|
cfg.buildMappings();
|
||||||
SessionFactoryImplementor sfi = (SessionFactoryImplementor) cfg.buildSessionFactory( getServiceRegistry() );
|
SessionFactoryImplementor sfi = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry() );
|
||||||
MetamodelImpl.buildMetamodel( cfg.getClassMappings(), sfi );
|
MetamodelImpl.buildMetamodel( cfg.getClassMappings(), sfi );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLogicalManyToOne() throws Exception {
|
public void testLogicalManyToOne() throws Exception {
|
||||||
final EntityType<JoinedManyToOneOwner> entityType = factory.getMetamodel().entity( JoinedManyToOneOwner.class );
|
final EntityType<JoinedManyToOneOwner> entityType = entityManagerFactory().getMetamodel().entity( JoinedManyToOneOwner.class );
|
||||||
final SingularAttribute attr = entityType.getDeclaredSingularAttribute( "house" );
|
final SingularAttribute attr = entityType.getDeclaredSingularAttribute( "house" );
|
||||||
assertEquals( Attribute.PersistentAttributeType.MANY_TO_ONE, attr.getPersistentAttributeType() );
|
assertEquals( Attribute.PersistentAttributeType.MANY_TO_ONE, attr.getPersistentAttributeType() );
|
||||||
assertEquals( House.class, attr.getBindableJavaType() );
|
assertEquals( House.class, attr.getBindableJavaType() );
|
||||||
final EntityType<House> houseType = factory.getMetamodel().entity( House.class );
|
final EntityType<House> houseType = entityManagerFactory().getMetamodel().entity( House.class );
|
||||||
assertEquals( houseType.getBindableJavaType(), attr.getBindableJavaType() );
|
assertEquals( houseType.getBindableJavaType(), attr.getBindableJavaType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEntity() throws Exception {
|
public void testEntity() throws Exception {
|
||||||
final EntityType<Fridge> fridgeType = factory.getMetamodel().entity( Fridge.class );
|
final EntityType<Fridge> fridgeType = entityManagerFactory().getMetamodel().entity( Fridge.class );
|
||||||
assertEquals( Fridge.class, fridgeType.getBindableJavaType() );
|
assertEquals( Fridge.class, fridgeType.getBindableJavaType() );
|
||||||
assertEquals( Bindable.BindableType.ENTITY_TYPE, fridgeType.getBindableType() );
|
assertEquals( Bindable.BindableType.ENTITY_TYPE, fridgeType.getBindableType() );
|
||||||
SingularAttribute<Fridge,Integer> wrapped = fridgeType.getDeclaredSingularAttribute( "temperature", Integer.class );
|
SingularAttribute<Fridge,Integer> wrapped = fridgeType.getDeclaredSingularAttribute( "temperature", Integer.class );
|
||||||
|
@ -103,7 +117,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
assertEquals( 3, fridgeType.getDeclaredAttributes().size() );
|
assertEquals( 3, fridgeType.getDeclaredAttributes().size() );
|
||||||
|
|
||||||
final EntityType<House> houseType = factory.getMetamodel().entity( House.class );
|
final EntityType<House> houseType = entityManagerFactory().getMetamodel().entity( House.class );
|
||||||
assertEquals( "org.hibernate.ejb.test.metadata.House", houseType.getName() );
|
assertEquals( "org.hibernate.ejb.test.metadata.House", houseType.getName() );
|
||||||
assertTrue( houseType.hasSingleIdAttribute() );
|
assertTrue( houseType.hasSingleIdAttribute() );
|
||||||
final SingularAttribute<House, House.Key> houseId = houseType.getDeclaredId( House.Key.class );
|
final SingularAttribute<House, House.Key> houseId = houseType.getDeclaredId( House.Key.class );
|
||||||
|
@ -111,7 +125,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertTrue( houseId.isId() );
|
assertTrue( houseId.isId() );
|
||||||
assertEquals( Attribute.PersistentAttributeType.EMBEDDED, houseId.getPersistentAttributeType() );
|
assertEquals( Attribute.PersistentAttributeType.EMBEDDED, houseId.getPersistentAttributeType() );
|
||||||
|
|
||||||
final EntityType<Person> personType = factory.getMetamodel().entity( Person.class );
|
final EntityType<Person> personType = entityManagerFactory().getMetamodel().entity( Person.class );
|
||||||
assertEquals( "Homo", personType.getName() );
|
assertEquals( "Homo", personType.getName() );
|
||||||
assertFalse( personType.hasSingleIdAttribute() );
|
assertFalse( personType.hasSingleIdAttribute() );
|
||||||
final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
|
final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
|
||||||
|
@ -121,7 +135,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertTrue( localId.isId() );
|
assertTrue( localId.isId() );
|
||||||
}
|
}
|
||||||
|
|
||||||
final EntityType<FoodItem> foodType = factory.getMetamodel().entity( FoodItem.class );
|
final EntityType<FoodItem> foodType = entityManagerFactory().getMetamodel().entity( FoodItem.class );
|
||||||
assertTrue( foodType.hasVersionAttribute() );
|
assertTrue( foodType.hasVersionAttribute() );
|
||||||
final SingularAttribute<? super FoodItem, Long> version = foodType.getVersion( Long.class );
|
final SingularAttribute<? super FoodItem, Long> version = foodType.getVersion( Long.class );
|
||||||
assertNotNull( version );
|
assertNotNull( version );
|
||||||
|
@ -130,8 +144,9 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBasic() throws Exception {
|
public void testBasic() throws Exception {
|
||||||
final EntityType<Fridge> entityType = factory.getMetamodel().entity( Fridge.class );
|
final EntityType<Fridge> entityType = entityManagerFactory().getMetamodel().entity( Fridge.class );
|
||||||
final SingularAttribute<? super Fridge,Integer> singularAttribute = entityType.getDeclaredSingularAttribute(
|
final SingularAttribute<? super Fridge,Integer> singularAttribute = entityType.getDeclaredSingularAttribute(
|
||||||
"temperature",
|
"temperature",
|
||||||
Integer.class
|
Integer.class
|
||||||
|
@ -165,8 +180,9 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertTrue( found );
|
assertTrue( found );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmbeddable() throws Exception {
|
public void testEmbeddable() throws Exception {
|
||||||
final EntityType<House> entityType = factory.getMetamodel().entity( House.class );
|
final EntityType<House> entityType = entityManagerFactory().getMetamodel().entity( House.class );
|
||||||
final SingularAttribute<? super House,Address> address = entityType.getDeclaredSingularAttribute(
|
final SingularAttribute<? super House,Address> address = entityType.getDeclaredSingularAttribute(
|
||||||
"address",
|
"address",
|
||||||
Address.class
|
Address.class
|
||||||
|
@ -181,21 +197,23 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertTrue( addressType.getDeclaredSingularAttribute( "address1" ).isOptional() );
|
assertTrue( addressType.getDeclaredSingularAttribute( "address1" ).isOptional() );
|
||||||
assertFalse( addressType.getDeclaredSingularAttribute( "address2" ).isOptional() );
|
assertFalse( addressType.getDeclaredSingularAttribute( "address2" ).isOptional() );
|
||||||
|
|
||||||
final EmbeddableType<Address> directType = factory.getMetamodel().embeddable( Address.class );
|
final EmbeddableType<Address> directType = entityManagerFactory().getMetamodel().embeddable( Address.class );
|
||||||
assertNotNull( directType );
|
assertNotNull( directType );
|
||||||
assertEquals( Type.PersistenceType.EMBEDDABLE, directType.getPersistenceType() );
|
assertEquals( Type.PersistenceType.EMBEDDABLE, directType.getPersistenceType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCollection() throws Exception {
|
public void testCollection() throws Exception {
|
||||||
final EntityType<Garden> entiytype = factory.getMetamodel().entity( Garden.class );
|
final EntityType<Garden> entiytype = entityManagerFactory().getMetamodel().entity( Garden.class );
|
||||||
final Set<PluralAttribute<? super Garden, ?, ?>> attributes = entiytype.getPluralAttributes();
|
final Set<PluralAttribute<? super Garden, ?, ?>> attributes = entiytype.getPluralAttributes();
|
||||||
assertEquals( 1, attributes.size() );
|
assertEquals( 1, attributes.size() );
|
||||||
PluralAttribute<? super Garden, ?, ?> flowers = attributes.iterator().next();
|
PluralAttribute<? super Garden, ?, ?> flowers = attributes.iterator().next();
|
||||||
assertTrue( flowers instanceof ListAttribute );
|
assertTrue( flowers instanceof ListAttribute );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testElementCollection() throws Exception {
|
public void testElementCollection() throws Exception {
|
||||||
final EntityType<House> entityType = factory.getMetamodel().entity( House.class );
|
final EntityType<House> entityType = entityManagerFactory().getMetamodel().entity( House.class );
|
||||||
final SetAttribute<House,Room> rooms = entityType.getDeclaredSet( "rooms", Room.class );
|
final SetAttribute<House,Room> rooms = entityType.getDeclaredSet( "rooms", Room.class );
|
||||||
assertNotNull( rooms );
|
assertNotNull( rooms );
|
||||||
assertTrue( rooms.isAssociation() );
|
assertTrue( rooms.isAssociation() );
|
||||||
|
@ -222,8 +240,9 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertEquals( PluralAttribute.CollectionType.LIST, roomsBySize.getCollectionType() );
|
assertEquals( PluralAttribute.CollectionType.LIST, roomsBySize.getCollectionType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHierarchy() {
|
public void testHierarchy() {
|
||||||
final EntityType<Cat> cat = factory.getMetamodel().entity( Cat.class );
|
final EntityType<Cat> cat = entityManagerFactory().getMetamodel().entity( Cat.class );
|
||||||
assertNotNull( cat );
|
assertNotNull( cat );
|
||||||
assertEquals( 7, cat.getAttributes().size() );
|
assertEquals( 7, cat.getAttributes().size() );
|
||||||
assertEquals( 1, cat.getDeclaredAttributes().size() );
|
assertEquals( 1, cat.getDeclaredAttributes().size() );
|
||||||
|
@ -287,14 +306,15 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertNull( thing.getSupertype() );
|
assertNull( thing.getSupertype() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBackrefAndGenerics() throws Exception {
|
public void testBackrefAndGenerics() throws Exception {
|
||||||
final EntityType<Parent> parent = factory.getMetamodel().entity( Parent.class );
|
final EntityType<Parent> parent = entityManagerFactory().getMetamodel().entity( Parent.class );
|
||||||
assertNotNull( parent );
|
assertNotNull( parent );
|
||||||
final SetAttribute<? super Parent, ?> children = parent.getSet( "children" );
|
final SetAttribute<? super Parent, ?> children = parent.getSet( "children" );
|
||||||
assertNotNull( children );
|
assertNotNull( children );
|
||||||
assertEquals( 1, parent.getPluralAttributes().size() );
|
assertEquals( 1, parent.getPluralAttributes().size() );
|
||||||
assertEquals( 4, parent.getAttributes().size() );
|
assertEquals( 4, parent.getAttributes().size() );
|
||||||
final EntityType<Child> child = factory.getMetamodel().entity( Child.class );
|
final EntityType<Child> child = entityManagerFactory().getMetamodel().entity( Child.class );
|
||||||
assertNotNull( child );
|
assertNotNull( child );
|
||||||
assertEquals( 2, child.getAttributes().size() );
|
assertEquals( 2, child.getAttributes().size() );
|
||||||
final SingularAttribute<? super Parent, Parent.Relatives> attribute = parent.getSingularAttribute(
|
final SingularAttribute<? super Parent, Parent.Relatives> attribute = parent.getSingularAttribute(
|
||||||
|
|
|
@ -1,15 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.metadata;
|
package org.hibernate.ejb.test.metadata;
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class SecondMetadataTest extends BaseEntityManagerFunctionalTestCase {
|
public class SecondMetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testBaseOfService() throws Exception {
|
public void testBaseOfService() throws Exception {
|
||||||
EntityManagerFactory emf = factory;
|
EntityManagerFactory emf = entityManagerFactory();
|
||||||
assertNotNull( emf.getMetamodel() );
|
assertNotNull( emf.getMetamodel() );
|
||||||
assertNotNull( emf.getMetamodel().entity( DeskWithRawType.class ) );
|
assertNotNull( emf.getMetamodel().entity( DeskWithRawType.class ) );
|
||||||
assertNotNull( emf.getMetamodel().entity( EmployeeWithRawType.class ) );
|
assertNotNull( emf.getMetamodel().entity( EmployeeWithRawType.class ) );
|
||||||
|
|
|
@ -22,20 +22,28 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.metadata;
|
package org.hibernate.ejb.test.metadata;
|
||||||
import java.util.Set;
|
|
||||||
import javax.persistence.metamodel.Attribute;
|
import javax.persistence.metamodel.Attribute;
|
||||||
import javax.persistence.metamodel.Bindable;
|
import javax.persistence.metamodel.Bindable;
|
||||||
import javax.persistence.metamodel.EmbeddableType;
|
import javax.persistence.metamodel.EmbeddableType;
|
||||||
import javax.persistence.metamodel.PluralAttribute;
|
import javax.persistence.metamodel.PluralAttribute;
|
||||||
import javax.persistence.metamodel.Type;
|
import javax.persistence.metamodel.Type;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class StaticMetadataTest extends BaseEntityManagerFunctionalTestCase {
|
public class StaticMetadataTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testInjections() throws Exception {
|
public void testInjections() throws Exception {
|
||||||
// Address (embeddable)
|
// Address (embeddable)
|
||||||
assertNotNull( Address_.address1 );
|
assertNotNull( Address_.address1 );
|
||||||
|
|
|
@ -1,13 +1,39 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.ops;
|
package org.hibernate.ejb.test.ops;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FindTest extends BaseEntityManagerFunctionalTestCase {
|
public class FindTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testSubclassWrongId() throws Exception {
|
public void testSubclassWrongId() throws Exception {
|
||||||
Mammal mammal = new Mammal();
|
Mammal mammal = new Mammal();
|
||||||
mammal.setMamalNbr( 2 );
|
mammal.setMamalNbr( 2 );
|
||||||
|
@ -16,11 +42,12 @@ public class FindTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( mammal );
|
em.persist( mammal );
|
||||||
em.flush();
|
em.flush();
|
||||||
assertNull( em.find(Reptile.class, 1l) );
|
Assert.assertNull( em.find( Reptile.class, 1l ) );
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Mammal.class,
|
Mammal.class,
|
||||||
|
|
|
@ -21,23 +21,30 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//$Id$
|
|
||||||
package org.hibernate.ejb.test.ops;
|
package org.hibernate.ejb.test.ops;
|
||||||
import java.util.Map;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class GetLoadTest extends BaseEntityManagerFunctionalTestCase {
|
public class GetLoadTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testGetLoad() {
|
public void testGetLoad() {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
|
@ -106,27 +113,24 @@ public class GetLoadTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCounts() {
|
private void clearCounts() {
|
||||||
( ( EntityManagerFactoryImpl ) factory ).getSessionFactory().getStatistics().clear();
|
( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertFetchCount(int count) {
|
private void assertFetchCount(int count) {
|
||||||
int fetches = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory()
|
int fetches = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory()
|
||||||
.getStatistics()
|
.getStatistics()
|
||||||
.getEntityFetchCount();
|
.getEntityFetchCount();
|
||||||
assertEquals( count, fetches );
|
assertEquals( count, fetches );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
protected void addConfigOptions(Map options) {
|
protected void addConfigOptions(Map options) {
|
||||||
options.put( Environment.GENERATE_STATISTICS, "true" );
|
options.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
options.put( Environment.STATEMENT_BATCH_SIZE, "0" );
|
options.put( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
|
||||||
return new Class<?>[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String[] getMappings() {
|
protected String[] getMappings() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"org/hibernate/ejb/test/ops/Node.hbm.xml",
|
"org/hibernate/ejb/test/ops/Node.hbm.xml",
|
||||||
|
|
|
@ -1,14 +1,41 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.ops;
|
package org.hibernate.ejb.test.ops;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MergeNewTest extends BaseEntityManagerFunctionalTestCase {
|
public class MergeNewTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testMergeNew() throws Exception {
|
public void testMergeNew() throws Exception {
|
||||||
Workload load = new Workload();
|
Workload load = new Workload();
|
||||||
load.name = "Cleaning";
|
load.name = "Cleaning";
|
||||||
|
@ -23,6 +50,7 @@ public class MergeNewTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeAfterRemove() throws Exception {
|
public void testMergeAfterRemove() throws Exception {
|
||||||
Workload load = new Workload();
|
Workload load = new Workload();
|
||||||
load.name = "Cleaning";
|
load.name = "Cleaning";
|
||||||
|
@ -48,8 +76,9 @@ public class MergeNewTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[] {
|
||||||
Workload.class
|
Workload.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,20 +21,23 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
//$Id$
|
|
||||||
package org.hibernate.ejb.test.ops;
|
package org.hibernate.ejb.test.ops;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testMergeTree() {
|
public void testMergeTree() {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
|
@ -100,24 +103,25 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCounts() {
|
private void clearCounts() {
|
||||||
( ( EntityManagerFactoryImpl ) factory ).getSessionFactory().getStatistics().clear();
|
( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertInsertCount(int count) {
|
private void assertInsertCount(int count) {
|
||||||
int inserts = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory()
|
int inserts = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory()
|
||||||
.getStatistics()
|
.getStatistics()
|
||||||
.getEntityInsertCount();
|
.getEntityInsertCount();
|
||||||
assertEquals( count, inserts );
|
Assert.assertEquals( count, inserts );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertUpdateCount(int count) {
|
private void assertUpdateCount(int count) {
|
||||||
int updates = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory()
|
int updates = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory()
|
||||||
.getStatistics()
|
.getStatistics()
|
||||||
.getEntityUpdateCount();
|
.getEntityUpdateCount();
|
||||||
assertEquals( count, updates );
|
Assert.assertEquals( count, updates );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
protected void addConfigOptions(Map options) {
|
protected void addConfigOptions(Map options) {
|
||||||
options.put( Environment.GENERATE_STATISTICS, "true" );
|
options.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
options.put( Environment.STATEMENT_BATCH_SIZE, "0" );
|
options.put( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||||
|
|
|
@ -23,22 +23,31 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.ops;
|
package org.hibernate.ejb.test.ops;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import javax.persistence.RollbackException;
|
import javax.persistence.RollbackException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testCreateTree() {
|
public void testCreateTree() {
|
||||||
|
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
@ -56,7 +65,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
root = ( Node ) em.find( Node.class, "root" );
|
root = em.find( Node.class, "root" );
|
||||||
Node child2 = new Node( "child2" );
|
Node child2 = new Node( "child2" );
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
@ -66,6 +75,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateTreeWithGeneratedId() {
|
public void testCreateTreeWithGeneratedId() {
|
||||||
clearCounts();
|
clearCounts();
|
||||||
|
|
||||||
|
@ -83,7 +93,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
root = ( NumberedNode ) em.find( NumberedNode.class, root.getId() );
|
root = em.find( NumberedNode.class, root.getId() );
|
||||||
NumberedNode child2 = new NumberedNode( "child2" );
|
NumberedNode child2 = new NumberedNode( "child2" );
|
||||||
root.addChild( child2 );
|
root.addChild( child2 );
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
@ -93,6 +103,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
assertUpdateCount( 0 );
|
assertUpdateCount( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateException() {
|
public void testCreateException() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -130,6 +141,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateExceptionWithGeneratedId() {
|
public void testCreateExceptionWithGeneratedId() {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -167,6 +179,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBasic() throws Exception {
|
public void testBasic() throws Exception {
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -185,7 +198,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
em = getOrCreateEntityManager();
|
em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
er = ( Employer ) em.find( Employer.class, er.getId() );
|
er = em.find( Employer.class, er.getId() );
|
||||||
assertNotNull( er );
|
assertNotNull( er );
|
||||||
assertNotNull( er.getEmployees() );
|
assertNotNull( er.getEmployees() );
|
||||||
assertEquals( 1, er.getEmployees().size() );
|
assertEquals( 1, er.getEmployees().size() );
|
||||||
|
@ -196,23 +209,25 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCounts() {
|
private void clearCounts() {
|
||||||
( ( EntityManagerFactoryImpl ) factory ).getSessionFactory().getStatistics().clear();
|
( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertInsertCount(int count) {
|
private void assertInsertCount(int count) {
|
||||||
int inserts = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory()
|
int inserts = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory()
|
||||||
.getStatistics()
|
.getStatistics()
|
||||||
.getEntityInsertCount();
|
.getEntityInsertCount();
|
||||||
assertEquals( count, inserts );
|
assertEquals( count, inserts );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertUpdateCount(int count) {
|
private void assertUpdateCount(int count) {
|
||||||
int updates = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory()
|
int updates = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory()
|
||||||
.getStatistics()
|
.getStatistics()
|
||||||
.getEntityUpdateCount();
|
.getEntityUpdateCount();
|
||||||
assertEquals( count, updates );
|
assertEquals( count, updates );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
protected void addConfigOptions(Map options) {
|
protected void addConfigOptions(Map options) {
|
||||||
options.put( Environment.GENERATE_STATISTICS, "true" );
|
options.put( Environment.GENERATE_STATISTICS, "true" );
|
||||||
options.put( Environment.STATEMENT_BATCH_SIZE, "0" );
|
options.put( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||||
|
@ -223,6 +238,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
return new Class<?>[] { Node.class };
|
return new Class<?>[] { Node.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String[] getMappings() {
|
protected String[] getMappings() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"org/hibernate/ejb/test/ops/Node.hbm.xml",
|
"org/hibernate/ejb/test/ops/Node.hbm.xml",
|
||||||
|
|
|
@ -22,20 +22,26 @@
|
||||||
* Boston, MA 02110-1301 USA\
|
* Boston, MA 02110-1301 USA\
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.query;
|
package org.hibernate.ejb.test.query;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.criteria.components.Client;
|
import org.hibernate.ejb.criteria.components.Client;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests related to specifying joins on components (embedded values).
|
* Tests related to specifying joins on components (embedded values).
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ComponentJoinsTest extends BaseEntityManagerFunctionalTestCase {
|
public class ComponentJoinsTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { Client.class };
|
return new Class[] { Client.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testComponentJoins() {
|
public void testComponentJoins() {
|
||||||
// Just checking proper query construction and syntax checking via database query parser...
|
// Just checking proper query construction and syntax checking via database query parser...
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
|
|
@ -1,23 +1,53 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.query;
|
package org.hibernate.ejb.test.query;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.ejb.test.Distributor;
|
import org.hibernate.ejb.test.Distributor;
|
||||||
import org.hibernate.ejb.test.Item;
|
import org.hibernate.ejb.test.Item;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
|
||||||
import org.hibernate.ejb.test.Wallet;
|
import org.hibernate.ejb.test.Wallet;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testPagedQuery() throws Exception {
|
public void testPagedQuery() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -37,6 +67,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAggregationReturnType() throws Exception {
|
public void testAggregationReturnType() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -51,6 +82,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParameterList() throws Exception {
|
public void testParameterList() throws Exception {
|
||||||
final Item item = new Item( "Mouse", "Micro$oft mouse" );
|
final Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
final Item item2 = new Item( "Computer", "Dell computer" );
|
final Item item2 = new Item( "Computer", "Dell computer" );
|
||||||
|
@ -99,6 +131,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParameterListInExistingParens() throws Exception {
|
public void testParameterListInExistingParens() throws Exception {
|
||||||
final Item item = new Item( "Mouse", "Micro$oft mouse" );
|
final Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
final Item item2 = new Item( "Computer", "Dell computer" );
|
final Item item2 = new Item( "Computer", "Dell computer" );
|
||||||
|
@ -150,39 +183,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testDistinct() throws Exception {
|
@Test
|
||||||
// Item item = new Item("Mouse", "Micro_oft mouse");
|
|
||||||
// Distributor fnac = new Distributor();
|
|
||||||
// fnac.setName("Fnac");
|
|
||||||
// item.addDistributor(fnac);
|
|
||||||
// Distributor auchan = new Distributor();
|
|
||||||
// auchan.setName("Auchan");
|
|
||||||
// item.addDistributor(auchan);
|
|
||||||
//
|
|
||||||
// EntityManager em = getOrCreateEntityManager();
|
|
||||||
// em.getTransaction().begin();
|
|
||||||
// em.persist(fnac);
|
|
||||||
// em.persist(auchan);
|
|
||||||
// em.persist(item);
|
|
||||||
// em.getTransaction().commit();
|
|
||||||
//
|
|
||||||
// em.getTransaction().begin();
|
|
||||||
// Query q = em.createQuery("select distinct item from Item item join fetch item.distributors");
|
|
||||||
// List result = q.getResultList();
|
|
||||||
// assertNotNull(result);
|
|
||||||
// assertEquals( 1, result.size() );
|
|
||||||
// item = (Item) result.get(0);
|
|
||||||
// item.getDistributors().clear();
|
|
||||||
// em.flush();
|
|
||||||
// int deleted = em.createQuery("delete from Item").executeUpdate();
|
|
||||||
// assertEquals( 1, deleted );
|
|
||||||
// deleted = em.createQuery("delete from Distributor").executeUpdate();
|
|
||||||
// assertEquals( 2, deleted );
|
|
||||||
// em.getTransaction().commit();
|
|
||||||
//
|
|
||||||
// em.close();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void testEscapeCharacter() throws Exception {
|
public void testEscapeCharacter() throws Exception {
|
||||||
final Item item = new Item( "Mouse", "Micro_oft mouse" );
|
final Item item = new Item( "Mouse", "Micro_oft mouse" );
|
||||||
final Item item2 = new Item( "Computer", "Dell computer" );
|
final Item item2 = new Item( "Computer", "Dell computer" );
|
||||||
|
@ -206,8 +207,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNativeQueryByEntity() {
|
public void testNativeQueryByEntity() {
|
||||||
|
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -227,8 +228,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNativeQueryByResultSet() {
|
public void testNativeQueryByResultSet() {
|
||||||
|
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -249,6 +250,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExplicitPositionalParameter() throws Exception {
|
public void testExplicitPositionalParameter() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -274,6 +276,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPositionalParameterForms() throws Exception {
|
public void testPositionalParameterForms() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -308,6 +311,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPositionalParameterWithUserError() throws Exception {
|
public void testPositionalParameterWithUserError() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -335,6 +339,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNativeQuestionMarkParameter() throws Exception {
|
public void testNativeQuestionMarkParameter() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -354,8 +359,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNativeQueryWithPositionalParameter() {
|
public void testNativeQueryWithPositionalParameter() {
|
||||||
|
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -382,6 +387,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDistinct() throws Exception {
|
public void testDistinct() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -410,6 +416,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIsNull() throws Exception {
|
public void testIsNull() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -443,8 +450,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testUpdateQuery() {
|
public void testUpdateQuery() {
|
||||||
|
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
|
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
@ -469,6 +476,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testUnavailableNamedQuery() throws Exception {
|
public void testUnavailableNamedQuery() throws Exception {
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
|
|
||||||
|
@ -493,6 +501,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTypedNamedNativeQuery() {
|
public void testTypedNamedNativeQuery() {
|
||||||
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
Item item = new Item( "Mouse", "Micro$oft mouse" );
|
||||||
|
|
||||||
|
@ -513,6 +522,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
Item.class,
|
Item.class,
|
||||||
|
|
|
@ -1,21 +1,53 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.transaction;
|
package org.hibernate.ejb.test.transaction;
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.LockModeType;
|
import javax.persistence.LockModeType;
|
||||||
import javax.persistence.OptimisticLockException;
|
import javax.persistence.OptimisticLockException;
|
||||||
import javax.persistence.PersistenceException;
|
import javax.persistence.PersistenceException;
|
||||||
import javax.persistence.RollbackException;
|
import javax.persistence.RollbackException;
|
||||||
import javax.persistence.TransactionRequiredException;
|
import javax.persistence.TransactionRequiredException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.ejb.HibernateEntityManagerFactory;
|
import org.hibernate.ejb.HibernateEntityManagerFactory;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase {
|
public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testAlwaysTransactionalOperations() throws Exception {
|
public void testAlwaysTransactionalOperations() throws Exception {
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Le petit prince";
|
book.name = "Le petit prince";
|
||||||
|
@ -43,39 +75,12 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testTransactionalOperationsWhenTransactional() throws Exception {
|
@Test
|
||||||
// Book book = new Book();
|
|
||||||
// book.name = "Le petit prince";
|
|
||||||
// EntityManager em = getEntityManager( PersistenceContextType.TRANSACTION );
|
|
||||||
// try {
|
|
||||||
// em.persist( book );
|
|
||||||
// fail("flush has to be inside a Tx");
|
|
||||||
// }
|
|
||||||
// catch (TransactionRequiredException e) {
|
|
||||||
// //success
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// em.refresh( book );
|
|
||||||
// fail("refresh has to be inside a Tx");
|
|
||||||
// }
|
|
||||||
// catch (TransactionRequiredException e) {
|
|
||||||
// //success
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// em.remove( book );
|
|
||||||
// fail("refresh has to be inside a Tx");
|
|
||||||
// }
|
|
||||||
// catch (TransactionRequiredException e) {
|
|
||||||
// //success
|
|
||||||
// }
|
|
||||||
// em.close();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void testTransactionalOperationsWhenExtended() throws Exception {
|
public void testTransactionalOperationsWhenExtended() throws Exception {
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Le petit prince";
|
book.name = "Le petit prince";
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Statistics stats = ( ( HibernateEntityManagerFactory ) factory ).getSessionFactory().getStatistics();
|
Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics();
|
||||||
stats.clear();
|
stats.clear();
|
||||||
stats.setStatisticsEnabled( true );
|
stats.setStatisticsEnabled( true );
|
||||||
|
|
||||||
|
@ -114,11 +119,12 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
stats.setStatisticsEnabled( false );
|
stats.setStatisticsEnabled( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeWhenExtended() throws Exception {
|
public void testMergeWhenExtended() throws Exception {
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Le petit prince";
|
book.name = "Le petit prince";
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
Statistics stats = ( ( HibernateEntityManagerFactory ) factory ).getSessionFactory().getStatistics();
|
Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics();
|
||||||
|
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist( book );
|
em.persist( book );
|
||||||
|
@ -157,6 +163,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
stats.setStatisticsEnabled( false );
|
stats.setStatisticsEnabled( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCloseAndTransaction() throws Exception {
|
public void testCloseAndTransaction() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -175,6 +182,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTransactionCommitDoesNotFlush() throws Exception {
|
public void testTransactionCommitDoesNotFlush() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -192,6 +200,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTransactionAndContains() throws Exception {
|
public void testTransactionAndContains() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -211,6 +220,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRollbackOnlyOnPersistenceException() throws Exception {
|
public void testRollbackOnlyOnPersistenceException() throws Exception {
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Stolen keys";
|
book.name = "Stolen keys";
|
||||||
|
@ -243,9 +253,9 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
finally {
|
finally {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRollbackExceptionOnOptimisticLockException() throws Exception {
|
public void testRollbackExceptionOnOptimisticLockException() throws Exception {
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Stolen keys";
|
book.name = "Stolen keys";
|
||||||
|
@ -277,6 +287,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRollbackClearPC() throws Exception {
|
public void testRollbackClearPC() throws Exception {
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
book.name = "Stolen keys";
|
book.name = "Stolen keys";
|
||||||
|
@ -292,6 +303,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Book.class
|
Book.class
|
||||||
|
|
|
@ -1,14 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.util;
|
package org.hibernate.ejb.test.util;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase {
|
public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testSimpleId() {
|
public void testSimpleId() {
|
||||||
EntityManager em = factory.createEntityManager();
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
em.persist( book );
|
em.persist( book );
|
||||||
|
@ -18,8 +47,9 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEmbeddedId() {
|
public void testEmbeddedId() {
|
||||||
EntityManager em = factory.createEntityManager();
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Umbrella umbrella = new Umbrella();
|
Umbrella umbrella = new Umbrella();
|
||||||
umbrella.setId( new Umbrella.PK() );
|
umbrella.setId( new Umbrella.PK() );
|
||||||
|
@ -32,8 +62,9 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testIdClass() {
|
public void testIdClass() {
|
||||||
EntityManager em = factory.createEntityManager();
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Sickness sick = new Sickness();
|
Sickness sick = new Sickness();
|
||||||
|
|
||||||
|
@ -49,6 +80,7 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
Book.class,
|
Book.class,
|
||||||
|
|
|
@ -1,14 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.util;
|
package org.hibernate.ejb.test.util;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class IsLoadedTest extends BaseEntityManagerFunctionalTestCase {
|
public class IsLoadedTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testIsLoadedOnPrivateSuperclassProperty() {
|
public void testIsLoadedOnPrivateSuperclassProperty() {
|
||||||
EntityManager em = factory.createEntityManager();
|
EntityManager em = entityManagerFactory().createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
Author a = new Author();
|
Author a = new Author();
|
||||||
Book book = new Book(a);
|
Book book = new Book(a);
|
||||||
|
|
|
@ -1,5 +1,28 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.xml;
|
package org.hibernate.ejb.test.xml;
|
||||||
|
|
||||||
import javax.persistence.PrePersist;
|
import javax.persistence.PrePersist;
|
||||||
import javax.persistence.PreRemove;
|
import javax.persistence.PreRemove;
|
||||||
import javax.persistence.PreUpdate;
|
import javax.persistence.PreUpdate;
|
||||||
|
|
|
@ -1,13 +1,41 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.xml;
|
package org.hibernate.ejb.test.xml;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testAttributeOverriding() throws Exception {
|
public void testAttributeOverriding() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -26,6 +54,7 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDefaultEventListener() throws Exception {
|
public void testDefaultEventListener() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -63,10 +92,6 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas
|
||||||
assertEquals( 1, CounterListener.delete );
|
assertEquals( 1, CounterListener.delete );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
|
||||||
return new Class[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getEjb3DD() {
|
public String[] getEjb3DD() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
|
|
|
@ -1,18 +1,45 @@
|
||||||
//$Id$
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.xml;
|
package org.hibernate.ejb.test.xml;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class XmlTest extends BaseEntityManagerFunctionalTestCase {
|
public class XmlTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testXmlMappingCorrectness() throws Exception {
|
public void testXmlMappingCorrectness() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[0];
|
return new Class[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,38 @@
|
||||||
//$Id: $
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
package org.hibernate.ejb.test.xml.sequences;
|
package org.hibernate.ejb.test.xml.sequences;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
@Test
|
||||||
public void testAttributeOverriding() throws Exception {
|
public void testAttributeOverriding() throws Exception {
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
@ -26,10 +51,6 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getAnnotatedClasses() {
|
|
||||||
return new Class[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getEjb3DD() {
|
public String[] getEjb3DD() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
|
|
Loading…
Reference in New Issue