HHH-6028 - Remove o.h.classic.Session/Validatable

This commit is contained in:
Steve Ebersole 2011-03-19 08:16:33 -05:00
parent efa325f5db
commit 3402ba3a67
72 changed files with 999 additions and 1540 deletions

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-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,14 +20,15 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate; package org.hibernate;
import javax.naming.Referenceable;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Connection; import java.sql.Connection;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.naming.Referenceable;
import org.hibernate.engine.FilterDefinition; import org.hibernate.engine.FilterDefinition;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata; import org.hibernate.metadata.CollectionMetadata;
@ -61,7 +62,7 @@ public interface SessionFactory extends Referenceable, Serializable {
* *
* @throws HibernateException Indicates a peroblem opening the session; pretty rare here. * @throws HibernateException Indicates a peroblem opening the session; pretty rare here.
*/ */
public org.hibernate.classic.Session openSession() throws HibernateException; public Session openSession() throws HibernateException;
/** /**
* Open a {@link Session}, utilizing the specified {@link Interceptor}. * Open a {@link Session}, utilizing the specified {@link Interceptor}.
@ -76,7 +77,7 @@ public interface SessionFactory extends Referenceable, Serializable {
* *
* @throws HibernateException Indicates a peroblem opening the session; pretty rare here. * @throws HibernateException Indicates a peroblem opening the session; pretty rare here.
*/ */
public org.hibernate.classic.Session openSession(Interceptor interceptor) throws HibernateException; public Session openSession(Interceptor interceptor) throws HibernateException;
/** /**
* Open a {@link Session}, utilizing the specfied JDBC {@link Connection}. * Open a {@link Session}, utilizing the specfied JDBC {@link Connection}.
@ -91,7 +92,7 @@ public interface SessionFactory extends Referenceable, Serializable {
* *
* @return The created session. * @return The created session.
*/ */
public org.hibernate.classic.Session openSession(Connection connection); public Session openSession(Connection connection);
/** /**
* Open a {@link Session}, utilizing the specfied JDBC {@link Connection} and * Open a {@link Session}, utilizing the specfied JDBC {@link Connection} and
@ -108,7 +109,7 @@ public interface SessionFactory extends Referenceable, Serializable {
* *
* @return The created session. * @return The created session.
*/ */
public org.hibernate.classic.Session openSession(Connection connection, Interceptor interceptor); public Session openSession(Connection connection, Interceptor interceptor);
/** /**
* Obtains the current session. The definition of what exactly "current" * Obtains the current session. The definition of what exactly "current"
@ -123,7 +124,7 @@ public interface SessionFactory extends Referenceable, Serializable {
* *
* @throws HibernateException Indicates an issue locating a suitable current session. * @throws HibernateException Indicates an issue locating a suitable current session.
*/ */
public org.hibernate.classic.Session getCurrentSession() throws HibernateException; public Session getCurrentSession() throws HibernateException;
/** /**
* Open a new stateless session. * Open a new stateless session.

View File

@ -1,383 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
*
* 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.classic;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.type.Type;
/**
* An extension of the <tt>Session</tt> API, including all
* deprecated methods from Hibernate2. This interface is
* provided to allow easier migration of existing applications.
* New code should use <tt>org.hibernate.Session</tt>.
* @author Gavin King
*/
public interface Session extends org.hibernate.Session {
/**
* Copy the state of the given object onto the persistent object with the same
* identifier. If there is no persistent instance currently associated with
* the session, it will be loaded. Return the persistent instance. If the
* given instance is unsaved or does not exist in the database, save it and
* return it as a newly persistent instance. Otherwise, the given instance
* does not become associated with the session.
*
* @deprecated use {@link org.hibernate.Session#merge(Object)}
*
* @param object a transient instance with state to be copied
* @return an updated persistent instance
*/
public Object saveOrUpdateCopy(Object object) throws HibernateException;
/**
* Copy the state of the given object onto the persistent object with the
* given identifier. If there is no persistent instance currently associated
* with the session, it will be loaded. Return the persistent instance. If
* there is no database row with the given identifier, save the given instance
* and return it as a newly persistent instance. Otherwise, the given instance
* does not become associated with the session.
*
* @deprecated with no replacement
*
* @param object a persistent or transient instance with state to be copied
* @param id the identifier of the instance to copy to
* @return an updated persistent instance
*/
public Object saveOrUpdateCopy(Object object, Serializable id) throws HibernateException;
/**
* Copy the state of the given object onto the persistent object with the same
* identifier. If there is no persistent instance currently associated with
* the session, it will be loaded. Return the persistent instance. If the
* given instance is unsaved or does not exist in the database, save it and
* return it as a newly persistent instance. Otherwise, the given instance
* does not become associated with the session.
*
* @deprecated use {@link org.hibernate.Session#merge(String, Object)}
*
* @param object a transient instance with state to be copied
* @return an updated persistent instance
*/
public Object saveOrUpdateCopy(String entityName, Object object) throws HibernateException;
/**
* Copy the state of the given object onto the persistent object with the
* given identifier. If there is no persistent instance currently associated
* with the session, it will be loaded. Return the persistent instance. If
* there is no database row with the given identifier, save the given instance
* and return it as a newly persistent instance. Otherwise, the given instance
* does not become associated with the session.
*
* @deprecated with no replacement
*
* @param object a persistent or transient instance with state to be copied
* @param id the identifier of the instance to copy to
* @return an updated persistent instance
*/
public Object saveOrUpdateCopy(String entityName, Object object, Serializable id) throws HibernateException;
/**
* Execute a query.
*
* @deprecated use {@link #createQuery}.{@link Query#list()}
*
* @param query a query expressed in Hibernate's query language
* @return a distinct list of instances (or arrays of instances)
* @throws HibernateException
*/
public List find(String query) throws HibernateException;
/**
* Execute a query with bind parameters, binding a value to a "?" parameter
* in the query string.
*
* @deprecated use {@link #createQuery}.setXYZ.{@link Query#list()}
*
* @param query the query string
* @param value a value to be bound to a "?" placeholder (JDBC IN parameter).
* @param type the Hibernate type of the value
* @see org.hibernate.Hibernate for access to <tt>Type</tt> instances
* @return a distinct list of instances (or arrays of instances)
* @throws HibernateException
*/
public List find(String query, Object value, Type type) throws HibernateException;
/**
* Execute a query with bind parameters, binding an array of values to "?"
* parameters in the query string.
*
* @deprecated use {@link #createQuery}.setXYZ.{@link Query#list()}
*
* @param query the query string
* @param values an array of values to be bound to the "?" placeholders (JDBC IN parameters).
* @param types an array of Hibernate types of the values
* @see org.hibernate.Hibernate for access to <tt>Type</tt> instances
* @return a distinct list of instances
* @throws HibernateException
*/
public List find(String query, Object[] values, Type[] types) throws HibernateException;
/**
* Execute a query and return the results in an iterator. If the query has multiple
* return values, values will be returned in an array of type <tt>Object[].</tt><br>
* <br>
* Entities returned as results are initialized on demand. The first SQL query returns
* identifiers only. So <tt>iterate()</tt> is usually a less efficient way to retrieve
* objects than <tt>find()</tt>.
*
* @deprecated use {@link #createQuery}.{@link Query#iterate}
*
* @param query the query string
* @return an iterator
* @throws HibernateException
*/
public Iterator iterate(String query) throws HibernateException;
/**
* Execute a query and return the results in an iterator. Write the given value to "?"
* in the query string. If the query has multiple return values, values will be returned
* in an array of type <tt>Object[]</tt>.<br>
* <br>
* Entities returned as results are initialized on demand. The first SQL query returns
* identifiers only. So <tt>iterate()</tt> is usually a less efficient way to retrieve
* objects than <tt>find()</tt>.
*
* @deprecated use {@link #createQuery}.setXYZ.{@link Query#iterate}
*
* @param query the query string
* @param value a value to be witten to a "?" placeholder in the query string
* @param type the hibernate type of value
* @return an iterator
* @throws HibernateException
*/
public Iterator iterate(String query, Object value, Type type) throws HibernateException;
/**
* Execute a query and return the results in an iterator. Write the given values to "?"
* in the query string. If the query has multiple return values, values will be returned
* in an array of type <tt>Object[]</tt>.<br>
* <br>
* Entities returned as results are initialized on demand. The first SQL query returns
* identifiers only. So <tt>iterate()</tt> is usually a less efficient way to retrieve
* objects than <tt>find()</tt>.
*
* @deprecated use {@link #createQuery}.setXYZ.{@link Query#iterate}
*
* @param query the query string
* @param values a list of values to be written to "?" placeholders in the query
* @param types a list of Hibernate types of the values
* @return an iterator
* @throws HibernateException
*/
public Iterator iterate(String query, Object[] values, Type[] types) throws HibernateException;
/**
* Apply a filter to a persistent collection. A filter is a Hibernate query that may refer to
* <tt>this</tt>, the collection element. Filters allow efficient access to very large lazy
* collections. (Executing the filter does not initialize the collection.)
*
* @deprecated use {@link #createFilter(Object, String)}.{@link Query#list}
*
* @param collection a persistent collection to filter
* @param filter a filter query string
* @return Collection the resulting collection
* @throws HibernateException
*/
public Collection filter(Object collection, String filter) throws HibernateException;
/**
* Apply a filter to a persistent collection. A filter is a Hibernate query that may refer to
* <tt>this</tt>, the collection element.
*
* @deprecated use {@link #createFilter(Object, String)}.setXYZ.{@link Query#list}
*
* @param collection a persistent collection to filter
* @param filter a filter query string
* @param value a value to be witten to a "?" placeholder in the query string
* @param type the hibernate type of value
* @return Collection
* @throws HibernateException
*/
public Collection filter(Object collection, String filter, Object value, Type type) throws HibernateException;
/**
* Apply a filter to a persistent collection.
*
* Bind the given parameters to "?" placeholders. A filter is a Hibernate query that
* may refer to <tt>this</tt>, the collection element.
*
* @deprecated use {@link #createFilter(Object, String)}.setXYZ.{@link Query#list}
*
* @param collection a persistent collection to filter
* @param filter a filter query string
* @param values a list of values to be written to "?" placeholders in the query
* @param types a list of Hibernate types of the values
* @return Collection
* @throws HibernateException
*/
public Collection filter(Object collection, String filter, Object[] values, Type[] types) throws HibernateException;
/**
* Delete all objects returned by the query. Return the number of objects deleted.
* <p/>
* Note that this is very different from the delete-statement support added in HQL
* since 3.1. The functionality here is to actually peform the query and then iterate
* the results calling {@link #delete(Object)} individually.
*
* @deprecated consider using HQL delete statements
*
* @param query the query string
* @return the number of instances deleted
* @throws HibernateException
*/
public int delete(String query) throws HibernateException;
/**
* Delete all objects returned by the query. Return the number of objects deleted.
* <p/>
* Note that this is very different from the delete-statement support added in HQL
* since 3.1. The functionality here is to actually peform the query and then iterate
* the results calling {@link #delete(Object)} individually.
*
* @deprecated consider using HQL delete statements
*
* @param query the query string
* @param value a value to be witten to a "?" placeholder in the query string.
* @param type the hibernate type of value.
* @return the number of instances deleted
* @throws HibernateException
*/
public int delete(String query, Object value, Type type) throws HibernateException;
/**
* Delete all objects returned by the query. Return the number of objects deleted.
* <p/>
* Note that this is very different from the delete-statement support added in HQL
* since 3.1. The functionality here is to actually peform the query and then iterate
* the results calling {@link #delete(Object)} individually.
*
* @deprecated consider using HQL delete statements
*
* @param query the query string
* @param values a list of values to be written to "?" placeholders in the query.
* @param types a list of Hibernate types of the values
* @return the number of instances deleted
* @throws HibernateException
*/
public int delete(String query, Object[] values, Type[] types) throws HibernateException;
/**
* Create a new instance of <tt>Query</tt> for the given SQL string.
* <p/>
* Returned instances should all be {@link org.hibernate.SQLQuery}.
*
* @param sql a query expressed in SQL
* @param returnAlias a table alias that appears inside <tt>{}</tt> in the SQL string
* @param returnClass the returned persistent class
*
* @deprecated use {@link org.hibernate.SQLQuery#addRoot} or {@link org.hibernate.SQLQuery#addEntity} variants
* instead to define the alias/class
*/
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public Query createSQLQuery(String sql, String returnAlias, Class returnClass);
/**
* Create a new instance of <tt>Query</tt> for the given SQL string.
* <p/>
* Returned instances should all be {@link org.hibernate.SQLQuery}.
*
* @param sql a query expressed in SQL
* @param returnAliases an array of table aliases that appear inside <tt>{}</tt> in the SQL string
* @param returnClasses the returned persistent classes
*
* @deprecated use {@link org.hibernate.SQLQuery#addRoot} or {@link org.hibernate.SQLQuery#addEntity} variants
* instead to define the aliases/classes
*/
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public Query createSQLQuery(String sql, String[] returnAliases, Class[] returnClasses);
/**
* Persist the given transient instance, using the given identifier. This operation
* cascades to associated instances if the association is mapped with
* <tt>cascade="save-update"</tt>.
*
* @deprecated declare identifier properties for all classes
*
* @param object a transient instance of a persistent class
* @param id an unused valid identifier
* @throws HibernateException
*/
public void save(Object object, Serializable id) throws HibernateException;
/**
* Persist the given transient instance, using the given identifier. This operation
* cascades to associated instances if the association is mapped with
* <tt>cascade="save-update"</tt>.
*
* @deprecated declare identifier properties for all classes
*
* @param object a transient instance of a persistent class
* @param id an unused valid identifier
* @throws HibernateException
*/
public void save(String entityName, Object object, Serializable id) throws HibernateException;
/**
* Update the persistent state associated with the given identifier. An exception
* is thrown if there is a persistent instance with the same identifier in the
* current session. This operation cascades to associated instances
* if the association is mapped with <tt>cascade="save-update"</tt>.
*
* @deprecated declare identifier properties for all classes
*
* @param object a detached instance containing updated state
* @param id identifier of persistent instance
* @throws HibernateException
*/
public void update(Object object, Serializable id) throws HibernateException;
/**
* Update the persistent state associated with the given identifier. An exception
* is thrown if there is a persistent instance with the same identifier in the
* current session. This operation cascades to associated instances
* if the association is mapped with <tt>cascade="save-update"</tt>.
*
* @deprecated declare identifier properties for all classes
*
* @param object a detached instance containing updated state
* @param id identifier of persistent instance
* @throws HibernateException
*/
public void update(String entityName, Object object, Serializable id) throws HibernateException;
}

View File

@ -1,43 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
*
* 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.classic;
/**
* Implemented by persistent classes with invariants that must
* be checked before inserting into or updating the database.
*
* @author Gavin King
*/
public interface Validatable {
/**
* Validate the state of the object before persisting it.
* If a violation occurs, throw a <tt>ValidationFailure</tt>.
* This method must not change the state of the object by
* side-effect.
* @throws ValidationFailure if an invariant is violated
*/
public void validate() throws ValidationFailure;
}

View File

@ -1,49 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
*
* 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.classic;
import org.hibernate.HibernateException;
/**
* Thrown from <tt>Validatable.validate()</tt> when an invariant
* was violated. Some applications might subclass this exception
* in order to provide more information about the violation.
*
* @author Gavin King
*/
public class ValidationFailure extends HibernateException {
public ValidationFailure(String message) {
super(message);
}
public ValidationFailure(String message, Exception e) {
super(message, e);
}
public ValidationFailure(Exception e) {
super("A validation failure occurred", e);
}
}

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-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,11 +20,13 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.context; package org.hibernate.context;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session;
/** /**
* Defines the contract for implementations which know how to scope the notion * Defines the contract for implementations which know how to scope the notion
@ -55,5 +57,5 @@ public interface CurrentSessionContext extends Serializable {
* @throws HibernateException Typically indicates an issue * @throws HibernateException Typically indicates an issue
* locating or creating the current session. * locating or creating the current session.
*/ */
public org.hibernate.classic.Session currentSession() throws HibernateException; public Session currentSession() throws HibernateException;
} }

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-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,23 +20,24 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.context; package org.hibernate.context;
import java.util.Hashtable;
import java.util.Map;
import javax.transaction.Synchronization; import javax.transaction.Synchronization;
import javax.transaction.Transaction; import javax.transaction.Transaction;
import javax.transaction.TransactionManager; import javax.transaction.TransactionManager;
import java.util.Hashtable;
import java.util.Map;
import org.jboss.logging.Logger;
import org.hibernate.ConnectionReleaseMode; import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.classic.Session; import org.hibernate.Session;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.service.jta.platform.spi.JtaPlatform; import org.hibernate.service.jta.platform.spi.JtaPlatform;
import org.jboss.logging.Logger;
/** /**
* An implementation of {@link CurrentSessionContext} which scopes the notion * An implementation of {@link CurrentSessionContext} which scopes the notion
@ -62,7 +63,6 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class JTASessionContext implements CurrentSessionContext { public class JTASessionContext implements CurrentSessionContext {
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, JTASessionContext.class.getName()); private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, JTASessionContext.class.getName());
protected final SessionFactoryImplementor factory; protected final SessionFactoryImplementor factory;
@ -72,9 +72,7 @@ public JTASessionContext(SessionFactoryImplementor factory) {
this.factory = factory; this.factory = factory;
} }
/** @Override
* {@inheritDoc}
*/
public Session currentSession() throws HibernateException { public Session currentSession() throws HibernateException {
final JtaPlatform jtaPlatform = factory.getServiceRegistry().getService( JtaPlatform.class ); final JtaPlatform jtaPlatform = factory.getServiceRegistry().getService( JtaPlatform.class );
final TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager(); final TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-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,14 +20,15 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.context; package org.hibernate.context;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
/** /**
@ -56,16 +57,14 @@
*/ */
public class ManagedSessionContext implements CurrentSessionContext { public class ManagedSessionContext implements CurrentSessionContext {
private static final ThreadLocal context = new ThreadLocal(); private static final ThreadLocal<Map<SessionFactory,Session>> context = new ThreadLocal<Map<SessionFactory,Session>>();
private final SessionFactoryImplementor factory; private final SessionFactoryImplementor factory;
public ManagedSessionContext(SessionFactoryImplementor factory) { public ManagedSessionContext(SessionFactoryImplementor factory) {
this.factory = factory; this.factory = factory;
} }
/** @Override
* {@inheritDoc}
*/
public Session currentSession() { public Session currentSession() {
Session current = existingSession( factory ); Session current = existingSession( factory );
if ( current == null ) { if ( current == null ) {
@ -93,7 +92,7 @@ public static boolean hasBind(SessionFactory factory) {
* @return Any previously bound session (should be null in most cases). * @return Any previously bound session (should be null in most cases).
*/ */
public static Session bind(Session session) { public static Session bind(Session session) {
return ( Session ) sessionMap( true ).put( session.getSessionFactory(), session ); return sessionMap( true ).put( session.getSessionFactory(), session );
} }
/** /**
@ -105,9 +104,9 @@ public static Session bind(Session session) {
*/ */
public static Session unbind(SessionFactory factory) { public static Session unbind(SessionFactory factory) {
Session existing = null; Session existing = null;
Map sessionMap = sessionMap(); Map<SessionFactory,Session> sessionMap = sessionMap();
if ( sessionMap != null ) { if ( sessionMap != null ) {
existing = ( Session ) sessionMap.remove( factory ); existing = sessionMap.remove( factory );
doCleanup(); doCleanup();
} }
return existing; return existing;
@ -123,21 +122,21 @@ private static Session existingSession(SessionFactory factory) {
} }
} }
protected static Map sessionMap() { protected static Map<SessionFactory,Session> sessionMap() {
return sessionMap( false ); return sessionMap( false );
} }
private static synchronized Map sessionMap(boolean createMap) { private static synchronized Map<SessionFactory,Session> sessionMap(boolean createMap) {
Map sessionMap = ( Map ) context.get(); Map<SessionFactory,Session> sessionMap = context.get();
if ( sessionMap == null && createMap ) { if ( sessionMap == null && createMap ) {
sessionMap = new HashMap(); sessionMap = new HashMap<SessionFactory,Session>();
context.set( sessionMap ); context.set( sessionMap );
} }
return sessionMap; return sessionMap;
} }
private static synchronized void doCleanup() { private static synchronized void doCleanup() {
Map sessionMap = sessionMap( false ); Map<SessionFactory,Session> sessionMap = sessionMap( false );
if ( sessionMap != null ) { if ( sessionMap != null ) {
if ( sessionMap.isEmpty() ) { if ( sessionMap.isEmpty() ) {
context.set( null ); context.set( null );

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-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,10 +20,10 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.context; package org.hibernate.context;
import javax.transaction.Synchronization;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
@ -34,18 +34,19 @@
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.transaction.Synchronization;
import org.jboss.logging.Logger;
import org.hibernate.ConnectionReleaseMode; import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.transaction.spi.TransactionContext; import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.event.EventSource; import org.hibernate.event.EventSource;
import org.jboss.logging.Logger;
/** /**
* A {@link CurrentSessionContext} impl which scopes the notion of current * A {@link CurrentSessionContext} impl which scopes the notion of current

View File

@ -133,7 +133,7 @@ public String toString() {
*/ */
public static final CascadeStyle UPDATE = new CascadeStyle() { public static final CascadeStyle UPDATE = new CascadeStyle() {
public boolean doCascade(CascadingAction action) { public boolean doCascade(CascadingAction action) {
return action==CascadingAction.SAVE_UPDATE || action==CascadingAction.SAVE_UPDATE_COPY; return action==CascadingAction.SAVE_UPDATE;
} }
public String toString() { public String toString() {
return "STYLE_SAVE_UPDATE"; return "STYLE_SAVE_UPDATE";

View File

@ -304,33 +304,6 @@ public String toString() {
} }
}; };
/**
* @see org.hibernate.classic.Session#saveOrUpdateCopy(Object)
*/
public static final CascadingAction SAVE_UPDATE_COPY = new CascadingAction() {
// for deprecated saveOrUpdateCopy()
@Override
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
throws HibernateException {
LOG.trace("Cascading to save or update copy: " + entityName);
session.saveOrUpdateCopy( entityName, child, (Map) anything );
}
@Override
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
// saves / updates don't cascade to uninitialized collections
return getLoadedElementsIterator(session, collectionType, collection);
}
@Override
public boolean deleteOrphans() {
// orphans should not be deleted during copy??
return false;
}
@Override
public String toString() {
return "ACTION_SAVE_UPDATE_COPY";
}
};
/** /**
* @see org.hibernate.Session#persist(Object) * @see org.hibernate.Session#persist(Object)
*/ */

View File

@ -32,6 +32,7 @@
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.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cache.QueryCache; import org.hibernate.cache.QueryCache;
import org.hibernate.cache.Region; import org.hibernate.cache.Region;
@ -211,7 +212,7 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
/** /**
* Get a nontransactional "current" session for Hibernate EntityManager * Get a nontransactional "current" session for Hibernate EntityManager
*/ */
public org.hibernate.classic.Session openTemporarySession() throws HibernateException; public Session openTemporarySession() throws HibernateException;
/** /**
* Open a session conforming to the given parameters. Used mainly by * Open a session conforming to the given parameters. Used mainly by
@ -226,7 +227,7 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
* @return An appropriate session. * @return An appropriate session.
* @throws HibernateException * @throws HibernateException
*/ */
public org.hibernate.classic.Session openSession( public Session openSession(
final Connection connection, final Connection connection,
final boolean flushBeforeCompletionEnabled, final boolean flushBeforeCompletionEnabled,
final boolean autoCloseSessionEnabled, final boolean autoCloseSessionEnabled,

View File

@ -49,7 +49,6 @@
import org.hibernate.event.def.DefaultRefreshEventListener; import org.hibernate.event.def.DefaultRefreshEventListener;
import org.hibernate.event.def.DefaultReplicateEventListener; import org.hibernate.event.def.DefaultReplicateEventListener;
import org.hibernate.event.def.DefaultSaveEventListener; import org.hibernate.event.def.DefaultSaveEventListener;
import org.hibernate.event.def.DefaultSaveOrUpdateCopyEventListener;
import org.hibernate.event.def.DefaultSaveOrUpdateEventListener; import org.hibernate.event.def.DefaultSaveOrUpdateEventListener;
import org.hibernate.event.def.DefaultUpdateEventListener; import org.hibernate.event.def.DefaultUpdateEventListener;
import org.hibernate.internal.util.Cloneable; import org.hibernate.internal.util.Cloneable;
@ -100,7 +99,6 @@ public class EventListeners extends Cloneable implements Serializable {
private SaveOrUpdateEventListener[] saveEventListeners = { new DefaultSaveEventListener() }; private SaveOrUpdateEventListener[] saveEventListeners = { new DefaultSaveEventListener() };
private SaveOrUpdateEventListener[] updateEventListeners = { new DefaultUpdateEventListener() }; private SaveOrUpdateEventListener[] updateEventListeners = { new DefaultUpdateEventListener() };
private MergeEventListener[] saveOrUpdateCopyEventListeners = { new DefaultSaveOrUpdateCopyEventListener() };//saveOrUpdateCopy() is deprecated!
private static Map eventInterfaceFromType; private static Map eventInterfaceFromType;
@ -346,14 +344,6 @@ public void setPersistOnFlushEventListeners(PersistEventListener[] createEventLi
this.persistOnFlushEventListeners = createEventListener; this.persistOnFlushEventListeners = createEventListener;
} }
public MergeEventListener[] getSaveOrUpdateCopyEventListeners() {
return saveOrUpdateCopyEventListeners;
}
public void setSaveOrUpdateCopyEventListeners(MergeEventListener[] saveOrUpdateCopyEventListener) {
this.saveOrUpdateCopyEventListeners = saveOrUpdateCopyEventListener;
}
public SaveOrUpdateEventListener[] getSaveEventListeners() { public SaveOrUpdateEventListener[] getSaveEventListeners() {
return saveEventListeners; return saveEventListeners;
} }

View File

@ -71,11 +71,6 @@ public interface EventSource extends SessionImplementor, Session {
* Cascade refesh an entity instance * Cascade refesh an entity instance
*/ */
public void refresh(Object object, Map refreshedAlready) throws HibernateException; public void refresh(Object object, Map refreshedAlready) throws HibernateException;
/**
* Cascade copy an entity instance
*/
public void saveOrUpdateCopy(String entityName, Object object, Map copiedAlready) throws HibernateException;
/** /**
* Cascade delete an entity instance * Cascade delete an entity instance
*/ */

View File

@ -22,16 +22,20 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.event.def; package org.hibernate.event.def;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import org.jboss.logging.Logger;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException; import org.hibernate.NonUniqueObjectException;
import org.hibernate.action.internal.EntityIdentityInsertAction; import org.hibernate.action.internal.EntityIdentityInsertAction;
import org.hibernate.action.internal.EntityInsertAction; import org.hibernate.action.internal.EntityInsertAction;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.classic.Lifecycle; import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable;
import org.hibernate.engine.Cascade; import org.hibernate.engine.Cascade;
import org.hibernate.engine.CascadingAction; import org.hibernate.engine.CascadingAction;
import org.hibernate.engine.EntityEntry; import org.hibernate.engine.EntityEntry;
@ -44,12 +48,10 @@
import org.hibernate.event.EventSource; import org.hibernate.event.EventSource;
import org.hibernate.id.IdentifierGenerationException; import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.id.IdentifierGeneratorHelper; import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper; import org.hibernate.type.TypeHelper;
import org.jboss.logging.Logger;
/** /**
* A convenience bas class for listeners responding to save events. * A convenience bas class for listeners responding to save events.
@ -211,12 +213,6 @@ protected boolean invokeSaveLifecycle(Object entity, EntityPersister persister,
return false; return false;
} }
protected void validate(Object entity, EntityPersister persister, EventSource source) {
if ( persister.implementsValidatable( source.getEntityMode() ) ) {
( ( Validatable ) entity ).validate();
}
}
/** /**
* Performs all the actual work needed to save an entity (well to get the save moved to * Performs all the actual work needed to save an entity (well to get the save moved to
* the execution queue). * the execution queue).
@ -242,8 +238,6 @@ protected Serializable performSaveOrReplicate(
EventSource source, EventSource source,
boolean requiresImmediateIdAccess) { boolean requiresImmediateIdAccess) {
validate( entity, persister, source );
Serializable id = key == null ? null : key.getIdentifier(); Serializable id = key == null ? null : key.getIdentifier();
boolean inTxn = source.getTransactionCoordinator().isTransactionInProgress(); boolean inTxn = source.getTransactionCoordinator().isTransactionInProgress();

View File

@ -1,10 +1,10 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008-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,11 +20,13 @@
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*
*/ */
package org.hibernate.event.def; package org.hibernate.event.def;
import java.io.Serializable; import java.io.Serializable;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -32,7 +34,7 @@
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
import org.hibernate.action.internal.DelayedPostInsertIdentifier; import org.hibernate.action.internal.DelayedPostInsertIdentifier;
import org.hibernate.action.internal.EntityUpdateAction; import org.hibernate.action.internal.EntityUpdateAction;
import org.hibernate.classic.Validatable; import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.engine.EntityEntry; import org.hibernate.engine.EntityEntry;
import org.hibernate.engine.EntityKey; import org.hibernate.engine.EntityKey;
import org.hibernate.engine.Nullability; import org.hibernate.engine.Nullability;
@ -42,12 +44,10 @@
import org.hibernate.event.EventSource; import org.hibernate.event.EventSource;
import org.hibernate.event.FlushEntityEvent; import org.hibernate.event.FlushEntityEvent;
import org.hibernate.event.FlushEntityEventListener; import org.hibernate.event.FlushEntityEventListener;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.jboss.logging.Logger;
/** /**
* An event that occurs for each entity instance at flush time * An event that occurs for each entity instance at flush time
@ -264,17 +264,7 @@ else if (!entry.isModifiableEntity()) LOG.trace("Updating non-modifiable, delete
} else LOG.trace("Updating entity: " + MessageHelper.infoString(persister, entry.getId(), session.getFactory())); } else LOG.trace("Updating entity: " + MessageHelper.infoString(persister, entry.getId(), session.getFactory()));
} }
final boolean intercepted; final boolean intercepted = !entry.isBeingReplicated() && handleInterception( event );
if ( !entry.isBeingReplicated() ) {
// give the Interceptor a chance to process property values, if the properties
// were modified by the Interceptor, we need to set them back to the object
intercepted = handleInterception( event );
}
else {
intercepted = false;
}
validate( entity, persister, status, entityMode );
// increment the version number (if necessary) // increment the version number (if necessary)
final Object nextVersion = getNextVersion(event); final Object nextVersion = getNextVersion(event);
@ -315,13 +305,6 @@ else if (!entry.isModifiableEntity()) LOG.trace("Updating non-modifiable, delete
return intercepted; return intercepted;
} }
protected void validate(Object entity, EntityPersister persister, Status status, EntityMode entityMode) {
// validate() instances of Validatable
if ( status == Status.MANAGED && persister.implementsValidatable( entityMode ) ) {
( (Validatable) entity ).validate();
}
}
protected boolean handleInterception(FlushEntityEvent event) { protected boolean handleInterception(FlushEntityEvent event) {
SessionImplementor session = event.getSession(); SessionImplementor session = event.getSession();
EntityEntry entry = event.getEntityEntry(); EntityEntry entry = event.getEntityEntry();

View File

@ -1,34 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
*
* 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.event.def;
import org.hibernate.engine.CascadingAction;
public class DefaultSaveOrUpdateCopyEventListener extends DefaultMergeEventListener {
protected CascadingAction getCascadeAction() {
return CascadingAction.SAVE_UPDATE_COPY;
}
}

View File

@ -55,6 +55,7 @@
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.ObjectNotFoundException; import org.hibernate.ObjectNotFoundException;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver; import org.hibernate.SessionFactoryObserver;
import org.hibernate.StatelessSession; import org.hibernate.StatelessSession;
@ -145,7 +146,7 @@
* safe, but also highly concurrent. Synchronization must be used extremely sparingly. * safe, but also highly concurrent. Synchronization must be used extremely sparingly.
* *
* @see org.hibernate.service.jdbc.connections.spi.ConnectionProvider * @see org.hibernate.service.jdbc.connections.spi.ConnectionProvider
* @see org.hibernate.classic.Session * @see org.hibernate.Session
* @see org.hibernate.hql.QueryTranslator * @see org.hibernate.hql.QueryTranslator
* @see org.hibernate.persister.entity.EntityPersister * @see org.hibernate.persister.entity.EntityPersister
* @see org.hibernate.persister.collection.CollectionPersister * @see org.hibernate.persister.collection.CollectionPersister
@ -625,12 +626,11 @@ private SessionImpl openSession(
); );
} }
public org.hibernate.classic.Session openSession(Connection connection, Interceptor sessionLocalInterceptor) { public Session openSession(Connection connection, Interceptor sessionLocalInterceptor) {
return openSession(connection, false, Long.MIN_VALUE, sessionLocalInterceptor); return openSession(connection, false, Long.MIN_VALUE, sessionLocalInterceptor);
} }
public org.hibernate.classic.Session openSession(Interceptor sessionLocalInterceptor) public Session openSession(Interceptor sessionLocalInterceptor) throws HibernateException {
throws HibernateException {
// note that this timestamp is not correct if the connection provider // note that this timestamp is not correct if the connection provider
// returns an older JDBC connection that was associated with a // returns an older JDBC connection that was associated with a
// transaction that was already begun before openSession() was called // transaction that was already begun before openSession() was called
@ -639,15 +639,15 @@ public org.hibernate.classic.Session openSession(Interceptor sessionLocalInterce
return openSession( null, true, timestamp, sessionLocalInterceptor ); return openSession( null, true, timestamp, sessionLocalInterceptor );
} }
public org.hibernate.classic.Session openSession(Connection connection) { public Session openSession(Connection connection) {
return openSession(connection, interceptor); //prevents this session from adding things to cache return openSession(connection, interceptor); //prevents this session from adding things to cache
} }
public org.hibernate.classic.Session openSession() throws HibernateException { public Session openSession() throws HibernateException {
return openSession(interceptor); return openSession(interceptor);
} }
public org.hibernate.classic.Session openTemporarySession() throws HibernateException { public Session openTemporarySession() throws HibernateException {
return new SessionImpl( return new SessionImpl(
null, null,
this, this,
@ -661,7 +661,7 @@ public org.hibernate.classic.Session openTemporarySession() throws HibernateExce
); );
} }
public org.hibernate.classic.Session openSession( public Session openSession(
final Connection connection, final Connection connection,
final boolean flushBeforeCompletionEnabled, final boolean flushBeforeCompletionEnabled,
final boolean autoCloseSessionEnabled, final boolean autoCloseSessionEnabled,
@ -679,7 +679,7 @@ public org.hibernate.classic.Session openSession(
); );
} }
public org.hibernate.classic.Session getCurrentSession() throws HibernateException { public Session getCurrentSession() throws HibernateException {
if ( currentSessionContext == null ) { if ( currentSessionContext == null ) {
throw new HibernateException( "No CurrentSessionContext configured!" ); throw new HibernateException( "No CurrentSessionContext configured!" );
} }

View File

@ -159,7 +159,7 @@
public final class SessionImpl public final class SessionImpl
extends AbstractSessionImpl extends AbstractSessionImpl
implements EventSource, implements EventSource,
org.hibernate.classic.Session, org.hibernate.Session,
TransactionContext, TransactionContext,
LobCreationContext { LobCreationContext {
@ -697,10 +697,6 @@ private void fireSaveOrUpdate(SaveOrUpdateEvent event) {
// save() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // save() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void save(Object obj, Serializable id) throws HibernateException {
save(null, obj, id);
}
public Serializable save(Object obj) throws HibernateException { public Serializable save(Object obj) throws HibernateException {
return save( null, obj ); return save( null, obj );
} }
@ -709,10 +705,6 @@ public Serializable save(String entityName, Object object) throws HibernateExcep
return fireSave( new SaveOrUpdateEvent( entityName, object, this ) ); return fireSave( new SaveOrUpdateEvent( entityName, object, this ) );
} }
public void save(String entityName, Object object, Serializable id) throws HibernateException {
fireSave( new SaveOrUpdateEvent( entityName, object, id, this ) );
}
private Serializable fireSave(SaveOrUpdateEvent event) { private Serializable fireSave(SaveOrUpdateEvent event) {
errorIfClosed(); errorIfClosed();
checkTransactionSynchStatus(); checkTransactionSynchStatus();
@ -730,18 +722,10 @@ public void update(Object obj) throws HibernateException {
update(null, obj); update(null, obj);
} }
public void update(Object obj, Serializable id) throws HibernateException {
update( null, obj, id );
}
public void update(String entityName, Object object) throws HibernateException { public void update(String entityName, Object object) throws HibernateException {
fireUpdate( new SaveOrUpdateEvent( entityName, object, this ) ); fireUpdate( new SaveOrUpdateEvent( entityName, object, this ) );
} }
public void update(String entityName, Object object, Serializable id) throws HibernateException {
fireUpdate( new SaveOrUpdateEvent( entityName, object, id, this ) );
}
private void fireUpdate(SaveOrUpdateEvent event) { private void fireUpdate(SaveOrUpdateEvent event) {
errorIfClosed(); errorIfClosed();
checkTransactionSynchStatus(); checkTransactionSynchStatus();
@ -887,52 +871,6 @@ private void fireMerge(Map copiedAlready, MergeEvent event) {
} }
// saveOrUpdateCopy() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Object saveOrUpdateCopy(String entityName, Object object)
throws HibernateException {
return fireSaveOrUpdateCopy( new MergeEvent( entityName, object, this ) );
}
public Object saveOrUpdateCopy(Object object) throws HibernateException {
return saveOrUpdateCopy( null, object );
}
public Object saveOrUpdateCopy(String entityName, Object object, Serializable id)
throws HibernateException {
return fireSaveOrUpdateCopy( new MergeEvent( entityName, object, id, this ) );
}
public Object saveOrUpdateCopy(Object object, Serializable id)
throws HibernateException {
return saveOrUpdateCopy( null, object, id );
}
public void saveOrUpdateCopy(String entityName, Object object, Map copiedAlready)
throws HibernateException {
fireSaveOrUpdateCopy( copiedAlready, new MergeEvent( entityName, object, this ) );
}
private void fireSaveOrUpdateCopy(Map copiedAlready, MergeEvent event) {
errorIfClosed();
checkTransactionSynchStatus();
MergeEventListener[] saveOrUpdateCopyEventListener = listeners.getSaveOrUpdateCopyEventListeners();
for ( int i = 0; i < saveOrUpdateCopyEventListener.length; i++ ) {
saveOrUpdateCopyEventListener[i].onMerge(event, copiedAlready);
}
}
private Object fireSaveOrUpdateCopy(MergeEvent event) {
errorIfClosed();
checkTransactionSynchStatus();
MergeEventListener[] saveOrUpdateCopyEventListener = listeners.getSaveOrUpdateCopyEventListeners();
for ( int i = 0; i < saveOrUpdateCopyEventListener.length; i++ ) {
saveOrUpdateCopyEventListener[i].onMerge(event);
}
return event.getResult();
}
// delete() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // delete() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/** /**
@ -1239,22 +1177,6 @@ public void forceFlush(EntityEntry entityEntry) throws HibernateException {
flush(); flush();
} }
/**
* Retrieve a list of persistent objects using a hibernate query
*/
public List find(String query) throws HibernateException {
return list( query, new QueryParameters() );
}
public List find(String query, Object value, Type type) throws HibernateException {
return list( query, new QueryParameters(type, value) );
}
public List find(String query, Object[] values, Type[] types) throws HibernateException {
return list( query, new QueryParameters(types, values) );
}
public List list(String query, QueryParameters queryParameters) throws HibernateException { public List list(String query, QueryParameters queryParameters) throws HibernateException {
errorIfClosed(); errorIfClosed();
checkTransactionSynchStatus(); checkTransactionSynchStatus();
@ -1317,18 +1239,6 @@ public int executeNativeUpdate(NativeSQLQuerySpecification nativeQuerySpecificat
return result; return result;
} }
public Iterator iterate(String query) throws HibernateException {
return iterate( query, new QueryParameters() );
}
public Iterator iterate(String query, Object value, Type type) throws HibernateException {
return iterate( query, new QueryParameters(type, value) );
}
public Iterator iterate(String query, Object[] values, Type[] types) throws HibernateException {
return iterate( query, new QueryParameters(types, values) );
}
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException { public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
errorIfClosed(); errorIfClosed();
checkTransactionSynchStatus(); checkTransactionSynchStatus();
@ -1359,35 +1269,6 @@ public ScrollableResults scroll(String query, QueryParameters queryParameters) t
} }
} }
public int delete(String query) throws HibernateException {
return delete( query, ArrayHelper.EMPTY_OBJECT_ARRAY, ArrayHelper.EMPTY_TYPE_ARRAY );
}
public int delete(String query, Object value, Type type) throws HibernateException {
return delete( query, new Object[]{value}, new Type[]{type} );
}
public int delete(String query, Object[] values, Type[] types) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( query == null ) {
throw new IllegalArgumentException("attempt to doAfterTransactionCompletion delete-by-query with null query");
}
if (LOG.isTraceEnabled()) {
LOG.trace("delete: " + query);
if (values.length != 0) LOG.trace("Parameters: " + StringHelper.toString(values));
}
List list = find( query, values, types );
int deletionCount = list.size();
for ( int i = 0; i < deletionCount; i++ ) {
delete( list.get( i ) );
}
return deletionCount;
}
public Query createFilter(Object collection, String queryString) { public Query createFilter(Object collection, String queryString) {
errorIfClosed(); errorIfClosed();
checkTransactionSynchStatus(); checkTransactionSynchStatus();
@ -1534,23 +1415,6 @@ private Serializable getProxyIdentifier(Object proxy) {
return ( (HibernateProxy) proxy ).getHibernateLazyInitializer().getIdentifier(); return ( (HibernateProxy) proxy ).getHibernateLazyInitializer().getIdentifier();
} }
public Collection filter(Object collection, String filter) throws HibernateException {
return listFilter( collection, filter, new QueryParameters( new Type[1], new Object[1] ) );
}
public Collection filter(Object collection, String filter, Object value, Type type) throws HibernateException {
return listFilter( collection, filter, new QueryParameters( new Type[]{null, type}, new Object[]{null, value} ) );
}
public Collection filter(Object collection, String filter, Object[] values, Type[] types)
throws HibernateException {
Object[] vals = new Object[values.length + 1];
Type[] typs = new Type[types.length + 1];
System.arraycopy( values, 0, vals, 1, values.length );
System.arraycopy( types, 0, typs, 1, types.length );
return listFilter( collection, filter, new QueryParameters( typs, vals ) );
}
private FilterQueryPlan getFilterQueryPlan( private FilterQueryPlan getFilterQueryPlan(
Object collection, Object collection,
String filter, String filter,
@ -1766,30 +1630,6 @@ public SQLQuery createSQLQuery(String sql) {
return super.createSQLQuery( sql ); return super.createSQLQuery( sql );
} }
public Query createSQLQuery(String sql, String returnAlias, Class returnClass) {
errorIfClosed();
checkTransactionSynchStatus();
return new SQLQueryImpl(
sql,
new String[] { returnAlias },
new Class[] { returnClass },
this,
factory.getQueryPlanCache().getSQLParameterMetadata( sql )
);
}
public Query createSQLQuery(String sql, String returnAliases[], Class returnClasses[]) {
errorIfClosed();
checkTransactionSynchStatus();
return new SQLQueryImpl(
sql,
returnAliases,
returnClasses,
this,
factory.getQueryPlanCache().getSQLParameterMetadata( sql )
);
}
public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters) public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
throws HibernateException { throws HibernateException {
errorIfClosed(); errorIfClosed();

View File

@ -36,6 +36,7 @@
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession; import org.hibernate.StatelessSession;
import org.hibernate.TypeHelper; import org.hibernate.TypeHelper;
@ -78,23 +79,23 @@ public class SessionFactoryStub implements SessionFactory {
SessionFactoryObjectFactory.addInstance( uuid, name, this, service.getProperties() ); SessionFactoryObjectFactory.addInstance( uuid, name, this, service.getProperties() );
} }
public org.hibernate.classic.Session openSession(Connection connection, Interceptor interceptor) { public Session openSession(Connection connection, Interceptor interceptor) {
return getImpl().openSession(connection, interceptor); return getImpl().openSession(connection, interceptor);
} }
public org.hibernate.classic.Session openSession(Interceptor interceptor) throws HibernateException { public Session openSession(Interceptor interceptor) throws HibernateException {
return getImpl().openSession(interceptor); return getImpl().openSession(interceptor);
} }
public org.hibernate.classic.Session openSession() throws HibernateException { public Session openSession() throws HibernateException {
return getImpl().openSession(); return getImpl().openSession();
} }
public org.hibernate.classic.Session openSession(Connection conn) { public Session openSession(Connection conn) {
return getImpl().openSession(conn); return getImpl().openSession(conn);
} }
public org.hibernate.classic.Session getCurrentSession() { public Session getCurrentSession() {
return getImpl().getCurrentSession(); return getImpl().getCurrentSession();
} }

View File

@ -237,11 +237,6 @@ public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionIm
*/ */
public boolean implementsLifecycle(EntityMode entityMode); public boolean implementsLifecycle(EntityMode entityMode);
/**
* Does the class implement the <tt>Validatable</tt> interface?
*/
public boolean implementsValidatable(EntityMode entityMode);
/** /**
* Get the version number (or timestamp) from the object's version property * Get the version number (or timestamp) from the object's version property
* (or return null if not versioned) * (or return null if not versioned)

View File

@ -3794,10 +3794,6 @@ public boolean implementsLifecycle(EntityMode entityMode) {
return getTuplizer( entityMode ).isLifecycleImplementor(); return getTuplizer( entityMode ).isLifecycleImplementor();
} }
public boolean implementsValidatable(EntityMode entityMode) {
return getTuplizer( entityMode ).isValidatableImplementor();
}
public Class getConcreteProxyClass(EntityMode entityMode) { public Class getConcreteProxyClass(EntityMode entityMode) {
return getTuplizer( entityMode ).getConcreteProxyClass(); return getTuplizer( entityMode ).getConcreteProxyClass();
} }

View File

@ -613,10 +613,6 @@ public Object createProxy(Serializable id, SessionImplementor session)
*/ */
public boolean implementsLifecycle(EntityMode entityMode); public boolean implementsLifecycle(EntityMode entityMode);
/**
* Does the class implement the <tt>Validatable</tt> interface.
*/
public boolean implementsValidatable(EntityMode entityMode);
/** /**
* Get the proxy interface that instances of <em>this</em> concrete class will be * Get the proxy interface that instances of <em>this</em> concrete class will be
* cast to (optional operation). * cast to (optional operation).

View File

@ -633,10 +633,6 @@ public boolean isLifecycleImplementor() {
return false; return false;
} }
public boolean isValidatableImplementor() {
return false;
}
protected final EntityMetamodel getEntityMetamodel() { protected final EntityMetamodel getEntityMetamodel() {
return entityMetamodel; return entityMetamodel;
} }

View File

@ -230,14 +230,6 @@ public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionIm
*/ */
public boolean isLifecycleImplementor(); public boolean isLifecycleImplementor();
/**
* Does the {@link #getMappedClass() class} managed by this tuplizer implement
* the {@link org.hibernate.classic.Validatable} interface.
*
* @return True if the Validatable interface is implemented; false otherwise.
*/
public boolean isValidatableImplementor();
/** /**
* Returns the java class to which generated proxies will be typed. * Returns the java class to which generated proxies will be typed.
* <p/> * <p/>

View File

@ -29,19 +29,21 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jboss.logging.Logger;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver; import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.classic.Lifecycle; import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
@ -53,7 +55,6 @@
import org.hibernate.tuple.Instantiator; import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.PojoInstantiator; import org.hibernate.tuple.PojoInstantiator;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.jboss.logging.Logger;
/** /**
* An {@link EntityTuplizer} specific to the pojo entity mode. * An {@link EntityTuplizer} specific to the pojo entity mode.
@ -68,7 +69,6 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
private final Class mappedClass; private final Class mappedClass;
private final Class proxyInterface; private final Class proxyInterface;
private final boolean lifecycleImplementor; private final boolean lifecycleImplementor;
private final boolean validatableImplementor;
private final Set lazyPropertyNames = new HashSet(); private final Set lazyPropertyNames = new HashSet();
private final ReflectionOptimizer optimizer; private final ReflectionOptimizer optimizer;
@ -77,7 +77,6 @@ public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappe
this.mappedClass = mappedEntity.getMappedClass(); this.mappedClass = mappedEntity.getMappedClass();
this.proxyInterface = mappedEntity.getProxyInterface(); this.proxyInterface = mappedEntity.getProxyInterface();
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass ); this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass );
Iterator iter = mappedEntity.getPropertyClosureIterator(); Iterator iter = mappedEntity.getPropertyClosureIterator();
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
@ -282,14 +281,6 @@ public boolean isLifecycleImplementor() {
return lifecycleImplementor; return lifecycleImplementor;
} }
/**
* {@inheritDoc}
*/
@Override
public boolean isValidatableImplementor() {
return validatableImplementor;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -26,18 +26,19 @@
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import java.util.Properties; import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger; import org.hibernate.HibernateLogger;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.classic.Lifecycle; import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.tuple.component.ComponentMetamodel; import org.hibernate.tuple.component.ComponentMetamodel;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.ParameterizedType; import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType; import org.hibernate.usertype.UserType;
import org.jboss.logging.Logger;
/** /**
* Used internally to build instances of {@link Type}, specifically it builds instances of * Used internally to build instances of {@link Type}, specifically it builds instances of
@ -98,7 +99,7 @@ public Type byClass(Class clazz, Properties parameters) {
return custom( clazz, parameters ); return custom( clazz, parameters );
} }
if ( Lifecycle.class.isAssignableFrom( clazz ) || Validatable.class.isAssignableFrom( clazz ) ) { if ( Lifecycle.class.isAssignableFrom( clazz ) ) {
// not really a many-to-one association *necessarily* // not really a many-to-one association *necessarily*
return manyToOne( clazz.getName() ); return manyToOne( clazz.getName() );
} }

View File

@ -38,8 +38,8 @@
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.ScrollableResults; import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.Cache71Dialect; import org.hibernate.dialect.Cache71Dialect;
import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
@ -81,12 +81,12 @@ public void testDialectSQLFunctions() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf( 10 ) );
simple.setName("Simple Dialect Function Test"); simple.setName("Simple Dialect Function Test");
simple.setAddress("Simple Address"); simple.setAddress("Simple Address");
simple.setPay(new Float(45.8)); simple.setPay(new Float(45.8));
simple.setCount(2); simple.setCount(2);
s.save(simple, Long.valueOf( 10 ) ); s.save( simple );
// Test to make sure allocating an specified object operates correctly. // Test to make sure allocating an specified object operates correctly.
assertTrue( assertTrue(
@ -140,9 +140,9 @@ public void testDialectSQLFunctions() throws Exception {
public void testSetProperties() throws Exception { public void testSetProperties() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf( 10 ) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save(simple, Long.valueOf( 10 ) ); s.save( simple );
Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count");
q.setProperties(simple); q.setProperties(simple);
assertTrue( q.list().get(0)==simple ); assertTrue( q.list().get(0)==simple );
@ -207,21 +207,21 @@ public void testBroken() throws Exception {
public void testNothinToUpdate() throws Exception { public void testNothinToUpdate() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, Long.valueOf(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, Long.valueOf(10) ); s.update( simple );
t.commit(); t.commit();
s.close(); s.close();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, Long.valueOf(10) ); s.update( simple );
s.delete(simple); s.delete(simple);
t.commit(); t.commit();
s.close(); s.close();
@ -231,9 +231,9 @@ public void testNothinToUpdate() throws Exception {
public void testCachedQuery() throws Exception { public void testCachedQuery() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, Long.valueOf(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
@ -272,7 +272,7 @@ public void testCachedQuery() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, Long.valueOf(10) ); s.update( simple );
s.delete(simple); s.delete(simple);
t.commit(); t.commit();
s.close(); s.close();
@ -292,9 +292,9 @@ public void testCachedQuery() throws Exception {
public void testCachedQueryRegion() throws Exception { public void testCachedQueryRegion() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, Long.valueOf(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
@ -325,7 +325,7 @@ public void testCachedQueryRegion() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, Long.valueOf(10) ); s.update( simple );
s.delete(simple); s.delete(simple);
t.commit(); t.commit();
s.close(); s.close();
@ -346,9 +346,9 @@ public void testCachedQueryRegion() throws Exception {
public void testSQLFunctions() throws Exception { public void testSQLFunctions() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save(simple, Long.valueOf(10) ); s.save(simple );
s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list(); s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list(); s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
@ -371,11 +371,11 @@ public void testSQLFunctions() throws Exception {
s.createQuery( "from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'" ).list().size()==1 s.createQuery( "from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'" ).list().size()==1
); );
Simple other = new Simple(); Simple other = new Simple( Long.valueOf(20) );
other.setName( "Simple 2" ); other.setName( "Simple 2" );
other.setCount( 12 ); other.setCount( 12 );
simple.setOther( other ); simple.setOther( other );
s.save( other, Long.valueOf(20) ); s.save( other );
//s.find("from Simple s where s.name ## 'cat|rat|bag'"); //s.find("from Simple s where s.name ## 'cat|rat|bag'");
assertTrue( assertTrue(
s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1 s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1
@ -395,9 +395,9 @@ public void testSQLFunctions() throws Exception {
).list() ).list()
.size()==1 .size()==1
); );
Simple min = new Simple(); Simple min = new Simple( Long.valueOf(30) );
min.setCount( -1 ); min.setCount( -1 );
s.save(min, Long.valueOf(30) ); s.save(min );
assertTrue( assertTrue(
s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" ) s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" )
@ -481,16 +481,15 @@ public void testSQLFunctions() throws Exception {
sr.get(0); sr.get(0);
sr.close(); sr.close();
s.delete(other); s.delete( other );
s.delete(simple); s.delete( simple );
s.delete(min); s.delete( min );
t.commit(); t.commit();
s.close(); s.close();
} }
public void testBlobClob() throws Exception { public void testBlobClob() throws Exception {
Session s = openSession(); Session s = openSession();
s.beginTransaction(); s.beginTransaction();
Blobber b = new Blobber(); Blobber b = new Blobber();
@ -554,9 +553,9 @@ public void testSqlFunctionAsAlias() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, Long.valueOf(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
@ -586,9 +585,9 @@ private String locateAppropriateDialectFunctionNameForAliasTest() {
public void testCachedQueryOnInsert() throws Exception { public void testCachedQueryOnInsert() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, Long.valueOf(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
@ -610,9 +609,9 @@ public void testCachedQueryOnInsert() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
Simple simple2 = new Simple(); Simple simple2 = new Simple( Long.valueOf(12) );
simple2.setCount(133); simple2.setCount(133);
s.save( simple2, Long.valueOf(12) ); s.save( simple2 );
t.commit(); t.commit();
s.close(); s.close();
@ -692,11 +691,11 @@ public void execute(Connection connection) throws SQLException {
s.beginTransaction(); s.beginTransaction();
TestInterSystemsFunctionsClass object = new TestInterSystemsFunctionsClass(); TestInterSystemsFunctionsClass object = new TestInterSystemsFunctionsClass( Long.valueOf( 10 ) );
object.setDateText("1977-07-03"); object.setDateText("1977-07-03");
object.setDate1( testvalue ); object.setDate1( testvalue );
object.setDate3( testvalue3 ); object.setDate3( testvalue3 );
s.save( object, Long.valueOf( 10 ) ); s.save( object );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -764,8 +763,6 @@ public void execute(Connection connection) throws SQLException {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
} }
} }

View File

@ -6,7 +6,7 @@
<hibernate-mapping package="org.hibernate.test.dialect.functional.cache" > <hibernate-mapping package="org.hibernate.test.dialect.functional.cache" >
<class name="TestInterSystemsFunctionsClass" table="SQLUser.TestInterSystemsFunctionsClass"> <class name="TestInterSystemsFunctionsClass" table="SQLUser.TestInterSystemsFunctionsClass">
<id type="long" column="id_"> <id name="id" type="long" column="id_">
<generator class="assigned"/> <generator class="assigned"/>
</id> </id>
<property name="date" column="date_"/> <property name="date" column="date_"/>

View File

@ -7,11 +7,27 @@
* @author Jonathan Levinson * @author Jonathan Levinson
*/ */
public class TestInterSystemsFunctionsClass { public class TestInterSystemsFunctionsClass {
private Long id;
private java.util.Date date3; private java.util.Date date3;
private java.util.Date date1; private java.util.Date date1;
private java.util.Date date; private java.util.Date date;
private String dateText; private String dateText;
public TestInterSystemsFunctionsClass() {
}
public TestInterSystemsFunctionsClass(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getDate() { public Date getDate() {
return date; return date;
} }

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.entitymode.multi; package org.hibernate.test.entitymode.multi;
import java.sql.Date; import java.sql.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -30,9 +31,10 @@
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.OutputFormat; import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter; import org.dom4j.io.XMLWriter;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.junit.Test; import org.junit.Test;

View File

@ -22,13 +22,14 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.hql; package org.hibernate.test.hql;
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 org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.MySQLDialect;
import org.hibernate.hql.ast.HqlSqlWalker; import org.hibernate.hql.ast.HqlSqlWalker;

View File

@ -22,12 +22,13 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.hql; package org.hibernate.test.hql;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Collections; import java.util.Collections;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Projections; import org.hibernate.criterion.Projections;
import org.hibernate.exception.SQLGrammarException; import org.hibernate.exception.SQLGrammarException;
import org.hibernate.hql.QueryTranslator; import org.hibernate.hql.QueryTranslator;

View File

@ -1,14 +1,17 @@
package org.hibernate.test.instrument.cases; package org.hibernate.test.instrument.cases;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.test.instrument.domain.Document; import org.hibernate.test.instrument.domain.Document;
import org.hibernate.test.instrument.domain.Folder; import org.hibernate.test.instrument.domain.Folder;
import org.hibernate.test.instrument.domain.Owner; import org.hibernate.test.instrument.domain.Owner;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
/** /**
* @author Rob.Hasselbaum * @author Rob.Hasselbaum
*/ */

View File

@ -7,6 +7,13 @@ public class A {
private String name; private String name;
private E forward; private E forward;
public A() {
}
public A(Long id) {
this.id = id;
}
/** /**
* Returns the id. * Returns the id.
* @return Long * @return Long

View File

@ -36,10 +36,14 @@
<generator class="assigned"/> <generator class="assigned"/>
</id> </id>
<property name="amount"/> <property name="amount"/>
<!-- these definitions both relied on the ability to save A with alternate assigned id
<many-to-one name="reverse" insert="false" update="false" outer-join="true"> <many-to-one name="reverse" insert="false" update="false" outer-join="true">
<formula>(id)</formula> <formula>(id)</formula>
</many-to-one> </many-to-one>
<many-to-one name="inverse" access="field" insert="false" update="false" formula = "(id)" outer-join="true"/> <many-to-one name="inverse" access="field" insert="false" update="false" formula = "(id)" outer-join="true"/>
-->
<many-to-one name="reverse" column="rev_a_id" outer-join="true"/>
<many-to-one name="inverse" access="field" column="inv_a_id" outer-join="true"/>
<!--many-to-one name="reverse" formula = "(select a.id from TA a where a.id = id)"/--> <!--many-to-one name="reverse" formula = "(select a.id from TA a where a.id = id)"/-->
</class> </class>

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -29,8 +30,8 @@
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
import org.junit.Test; import org.junit.Test;
@ -218,7 +219,9 @@ public void testSubclassing() throws Exception {
(c1b.getCount()==23432) && (c1b.getCount()==23432) &&
c1b.getName().equals("c1") c1b.getName().equals("c1")
); );
System.out.println( s.delete("from A") ); for ( Object a : s.createQuery( "from A" ).list() ) {
s.delete( a );
}
t.commit(); t.commit();
s.close(); s.close();
@ -228,7 +231,9 @@ public void testSubclassing() throws Exception {
s.save( new A() ); s.save( new A() );
assertTrue( s.createQuery( "from B" ).list().size()==1 ); assertTrue( s.createQuery( "from B" ).list().size()==1 );
assertTrue( s.createQuery( "from A" ).list().size()==2 ); assertTrue( s.createQuery( "from A" ).list().size()==2 );
s.delete("from A"); for ( Object a : s.createQuery( "from A" ).list() ) {
s.delete( a );
}
t.commit(); t.commit();
s.close(); s.close();
} }
@ -279,7 +284,9 @@ public void testOneToOne() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
List l = s.find( "from E e, A a where e.reverse = a.forward and a = ?", a, Hibernate.entity(A.class) ); List l = s.createQuery( "from E e, A a where e.reverse = a.forward and a = ?" )
.setEntity( 0, a )
.list();
assertTrue( l.size()==1 ); assertTrue( l.size()==1 );
l = s.createQuery( "from E e join fetch e.reverse" ).list(); l = s.createQuery( "from E e join fetch e.reverse" ).list();
assertTrue( l.size()==2 ); assertTrue( l.size()==2 );

View File

@ -22,10 +22,11 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.util.List; import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.junit.Test; import org.junit.Test;
@ -34,6 +35,7 @@
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@SuppressWarnings( {"UnnecessaryBoxing"})
public class ABCTest extends LegacyTestCase { public class ABCTest extends LegacyTestCase {
public String[] getMappings() { public String[] getMappings() {
return new String[] { "legacy/ABC.hbm.xml", "legacy/ABCExtends.hbm.xml" }; return new String[] { "legacy/ABC.hbm.xml", "legacy/ABCExtends.hbm.xml" };
@ -43,28 +45,30 @@ public String[] getMappings() {
public void testFormulaAssociation() throws Throwable { public void testFormulaAssociation() throws Throwable {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
D d = new D(); Long did = Long.valueOf(12);
Long did = new Long(12); D d = new D( did );
s.save(d, did); s.save(d);
A a = new A(); A a = new A();
a.setName("a"); a.setName("a");
s.save(a, did); s.save( a );
d.setReverse( a );
d.inverse = a;
t.commit(); t.commit();
s.close(); s.close();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
d = (D) s.get(D.class, did); d = (D) s.get(D.class, did);
assertTrue(d.getReverse().getId().equals(did)); assertNotNull( d.getReverse() );
s.clear(); s.clear();
sessionFactory().evict(D.class); sessionFactory().getCache().evictEntityRegion( D.class );
sessionFactory().evict(A.class); sessionFactory().getCache().evictEntityRegion(A.class);
d = (D) s.get(D.class, did); d = (D) s.get(D.class, did);
assertTrue(d.inverse.getId().equals(did)); assertNotNull( d.inverse );
assertTrue(d.inverse.getName().equals("a")); assertTrue(d.inverse.getName().equals("a"));
s.clear(); s.clear();
sessionFactory().evict(D.class); sessionFactory().getCache().evictEntityRegion( D.class );
sessionFactory().evict(A.class); sessionFactory().getCache().evictEntityRegion( A.class );
assertTrue( s.createQuery( "from D d join d.reverse r join d.inverse i where i = r" ).list().size()==1 ); assertTrue( s.createQuery( "from D d join d.reverse r join d.inverse i where i = r" ).list().size()==1 );
t.commit(); t.commit();
s.close(); s.close();
@ -105,7 +109,7 @@ public void testSubclassing() throws Exception {
t.commit(); t.commit();
s.close(); s.close();
sessionFactory().evict(A.class); sessionFactory().getCache().evictEntityRegion( A.class );
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
@ -120,7 +124,7 @@ public void testSubclassing() throws Exception {
t.commit(); t.commit();
s.close(); s.close();
sessionFactory().evict(A.class); sessionFactory().getCache().evictEntityRegion( A.class );
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
@ -163,12 +167,12 @@ public void testSubclassing() throws Exception {
public void testGetSave() throws Exception { public void testGetSave() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
assertNull( s.get( D.class, new Long(1) ) ); assertNull( s.get( D.class, Long.valueOf(1) ) );
D d = new D(); D d = new D();
d.setId( new Long(1) ); d.setId( Long.valueOf(1) );
s.save(d); s.save(d);
s.flush(); s.flush();
assertNotNull( s.get( D.class, new Long(1) ) ); assertNotNull( s.get( D.class, Long.valueOf(1) ) );
s.delete(d); s.delete(d);
s.flush(); s.flush();
t.commit(); t.commit();

View File

@ -5,7 +5,7 @@
<hibernate-mapping default-lazy="false"> <hibernate-mapping default-lazy="false">
<class name="org.hibernate.test.legacy.Simple" table="SIMP"> <class name="org.hibernate.test.legacy.Simple" table="SIMP">
<id type="long" column="id_"> <id name="id" type="long" column="id_">
<generator class="assigned"/> <generator class="assigned"/>
</id> </id>
<property name="name"/> <property name="name"/>

View File

@ -1,11 +1,12 @@
//$Id: CustomSQLTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ //$Id: CustomSQLTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.classic.Session; import org.hibernate.Session;
import org.hibernate.id.PostInsertIdentifierGenerator; import org.hibernate.id.PostInsertIdentifierGenerator;
import org.junit.Test; import org.junit.Test;

View File

@ -13,6 +13,12 @@ public D() {
setAmount(100.0f); setAmount(100.0f);
getAmount(); getAmount();
} }
public D(Long id) {
this();
this.id = id;
}
/** /**
* Returns the amount. * Returns the amount.
* @return float * @return float

View File

@ -5,7 +5,7 @@
<hibernate-mapping default-lazy="false"> <hibernate-mapping default-lazy="false">
<class name="org.hibernate.test.legacy.Fo" table="foes"> <class name="org.hibernate.test.legacy.Fo" table="foes">
<composite-id class="org.hibernate.test.legacy.FumCompositeID"> <composite-id name="id" class="org.hibernate.test.legacy.FumCompositeID">
<key-property name="string"> <key-property name="string">
<column name="string_" length="20"/> <column name="string_" length="20"/>
</key-property> </key-property>

View File

@ -4,17 +4,32 @@
public final class Fo { public final class Fo {
public static Fo newFo(FumCompositeID id) {
Fo fo = newFo();
fo.id = id;
return fo;
}
public static Fo newFo() { public static Fo newFo() {
return new Fo(); return new Fo();
} }
private Fo() {} private Fo() {}
private FumCompositeID id;
private byte[] buf; private byte[] buf;
private Serializable serial; private Serializable serial;
private long version; private long version;
private int x; private int x;
public FumCompositeID getId() {
return id;
}
public void setId(FumCompositeID id) {
this.id = id;
}
public int getX() { public int getX() {
return x; return x;
} }

View File

@ -78,6 +78,10 @@ public void setX(int x) {
public Foo() { public Foo() {
} }
public Foo(String key) {
this.key = key;
}
public Foo(int x) { public Foo(int x) {
this.x=x; this.x=x;
} }

View File

@ -23,7 +23,6 @@
*/ */
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import static org.hibernate.testing.TestLogger.LOG;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Time; import java.sql.Time;
@ -53,8 +52,8 @@
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.ScrollableResults; import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example; import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
@ -85,6 +84,7 @@
import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.env.ConnectionProviderBuilder; import org.hibernate.testing.env.ConnectionProviderBuilder;
import static org.hibernate.testing.TestLogger.LOG;
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.assertNull; import static org.junit.Assert.assertNull;
@ -136,7 +136,7 @@ public void testSaveOrUpdateCopyAny() throws Exception {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
Bar bar2 = (Bar) s.saveOrUpdateCopy(bar); Bar bar2 = (Bar) s.merge( bar );
s.flush(); s.flush();
s.delete(bar2); s.delete(bar2);
s.flush(); s.flush();
@ -783,7 +783,9 @@ public void testQuery() throws Exception {
int len = s.createQuery( "from Foo as foo join foo.foo as foo2 where foo2.id >'a' or foo2.id <'a'" ).list().size(); int len = s.createQuery( "from Foo as foo join foo.foo as foo2 where foo2.id >'a' or foo2.id <'a'" ).list().size();
assertTrue(len==2); assertTrue(len==2);
s.delete("from Holder"); for ( Object entity : s.createQuery( "from Holder" ).list() ) {
s.delete( entity );
}
txn.commit(); txn.commit();
s.close(); s.close();
@ -2678,8 +2680,8 @@ public void testSaveFlush() throws Exception {
Session s = openSession(); Session s = openSession();
s.beginTransaction(); s.beginTransaction();
Fee fee = new Fee(); Fee fee = new Fee();
s.save( fee, "key" ); s.save( fee );
fee.setFi("blah"); fee.setFi( "blah" );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -2687,7 +2689,6 @@ public void testSaveFlush() throws Exception {
s.beginTransaction(); s.beginTransaction();
fee = (Fee) s.load( Fee.class, fee.getKey() ); fee = (Fee) s.load( Fee.class, fee.getKey() );
assertTrue( "blah".equals( fee.getFi() ) ); assertTrue( "blah".equals( fee.getFi() ) );
assertTrue( "key".equals( fee.getKey() ) );
s.delete(fee); s.delete(fee);
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -2717,14 +2718,14 @@ public void testCreateUpdate() throws Exception {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
foo = new Foo(); foo = new Foo();
s.save(foo, "assignedid"); s.save(foo);
foo.setString("dirty"); foo.setString("dirty");
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
s.load(foo2, "assignedid"); s.load(foo2, foo.getKey());
// There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15 // There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15
assertTrue( "create-update", foo.equalsFoo(foo2) ); assertTrue( "create-update", foo.equalsFoo(foo2) );
//System.out.println( s.print(foo2) ); //System.out.println( s.print(foo2) );
@ -3474,7 +3475,12 @@ public void testScrollableIterator() throws Exception {
assertTrue( iter.last() ); assertTrue( iter.last() );
assertTrue( iter.get(0)==f4 ); assertTrue( iter.get(0)==f4 );
assertTrue( iter.previous() ); assertTrue( iter.previous() );
assertTrue( s.delete("from Foo")==4 ); int i = 0;
for ( Object entity : s.createQuery( "from Foo" ).list() ) {
i++;
s.delete( entity );
}
assertEquals( 4, i );
s.flush(); s.flush();
assertTrue( s.createQuery( "from java.lang.Object" ).list().size()==0 ); assertTrue( s.createQuery( "from java.lang.Object" ).list().size()==0 );
txn.commit(); txn.commit();
@ -3695,7 +3701,7 @@ public void testUpdateFromTransient() throws Exception {
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
s.saveOrUpdate(fee2); s.saveOrUpdate(fee2);
s.update( fee1, fee1.getKey() ); s.update( fee1 );
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
@ -3799,7 +3805,7 @@ public void testComponents() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction txn = s.beginTransaction(); Transaction txn = s.beginTransaction();
Foo foo = new Foo(); Foo foo = new Foo();
foo.setComponent( new FooComponent("foo", 69, null, new FooComponent("bar", 96, null, null) ) ); // foo.setComponent( new FooComponent("foo", 69, null, new FooComponent("bar", 96, null, null) ) );
s.save(foo); s.save(foo);
foo.getComponent().setName( "IFA" ); foo.getComponent().setName( "IFA" );
txn.commit(); txn.commit();
@ -4233,13 +4239,14 @@ public void testVeto() throws Exception {
Session s = openSession(); Session s = openSession();
s.beginTransaction(); s.beginTransaction();
Vetoer v = new Vetoer(); Vetoer v = new Vetoer();
s.save(v); Serializable id = s.save(v); s.save(v);
s.save(v);
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
s = openSession(); s = openSession();
s.beginTransaction(); s.beginTransaction();
s.update( v, id ); s.update( v );
s.update( v, id ); s.update( v );
s.delete( v ); s.delete( v );
s.delete( v ); s.delete( v );
s.getTransaction().commit(); s.getTransaction().commit();
@ -4423,9 +4430,9 @@ public void testLoadAfterDelete() throws Exception {
err=true; err=true;
} }
assertTrue(err); assertTrue(err);
Fo fo = Fo.newFo(); id = FumTest.fumKey( "abc" ); //yuck!!
id = new FumTest().fumKey("abc"); //yuck!! Fo fo = Fo.newFo( (FumCompositeID) id );
s.save(fo, id); s.save(fo);
s.flush(); s.flush();
s.delete(fo); s.delete(fo);
err=false; err=false;

View File

@ -1,5 +1,6 @@
//$Id: FumTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ //$Id: FumTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -25,11 +26,10 @@
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MckoiDialect; import org.hibernate.dialect.MckoiDialect;
import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.MySQLDialect;
@ -296,13 +296,13 @@ public void testListIdentifiers() throws Exception {
} }
public FumCompositeID fumKey(String str) { public static FumCompositeID fumKey(String str) {
return fumKey(str,false); return fumKey(str,false);
} }
private FumCompositeID fumKey(String str, boolean aCompositeQueryTest) { private static FumCompositeID fumKey(String str, boolean aCompositeQueryTest) {
FumCompositeID id = new FumCompositeID(); FumCompositeID id = new FumCompositeID();
if ( Dialect.getDialect() instanceof MckoiDialect ) { if ( getDialect() instanceof MckoiDialect ) {
GregorianCalendar now = new GregorianCalendar(); GregorianCalendar now = new GregorianCalendar();
GregorianCalendar cal = new GregorianCalendar( GregorianCalendar cal = new GregorianCalendar(
now.get(java.util.Calendar.YEAR), now.get(java.util.Calendar.YEAR),
@ -581,13 +581,13 @@ public void testDeleteOwner() throws Exception {
public void testCompositeIDs() throws Exception { public void testCompositeIDs() throws Exception {
Session s = openSession(); Session s = openSession();
s.beginTransaction(); s.beginTransaction();
Fo fo = Fo.newFo(); Fo fo = Fo.newFo( fumKey("an instance of fo") );
Properties props = new Properties(); Properties props = new Properties();
props.setProperty("foo", "bar"); props.setProperty("foo", "bar");
props.setProperty("bar", "foo"); props.setProperty("bar", "foo");
fo.setSerial(props); fo.setSerial(props);
fo.setBuf( "abcdefghij1`23%$*^*$*\n\t".getBytes() ); fo.setBuf( "abcdefghij1`23%$*^*$*\n\t".getBytes() );
s.save( fo, fumKey("an instance of fo") ); s.save( fo );
s.flush(); s.flush();
props.setProperty("x", "y"); props.setProperty("x", "y");
s.getTransaction().commit(); s.getTransaction().commit();
@ -737,13 +737,13 @@ public void testUnflushedSessionSerialization() throws Exception {
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setAddress("123 Main St. Anytown USA"); simple.setAddress("123 Main St. Anytown USA");
simple.setCount(1); simple.setCount(1);
simple.setDate( new Date() ); simple.setDate( new Date() );
simple.setName("My UnflushedSessionSerialization Simple"); simple.setName("My UnflushedSessionSerialization Simple");
simple.setPay( new Float(5000) ); simple.setPay( Float.valueOf(5000) );
s.save( simple, new Long(10) ); s.save( simple );
// Now, try to serialize session without flushing... // Now, try to serialize session without flushing...
s.getTransaction().commit(); s.getTransaction().commit();
@ -753,9 +753,9 @@ public void testUnflushedSessionSerialization() throws Exception {
s.beginTransaction(); s.beginTransaction();
simple = (Simple) s.load( Simple.class, new Long(10) ); simple = (Simple) s.load( Simple.class, new Long(10) );
Simple other = new Simple(); Simple other = new Simple( Long.valueOf(11) );
other.init(); other.init();
s.save( other, new Long(11) ); s.save( other );
simple.setOther(other); simple.setOther(other);
s.flush(); s.flush();
@ -770,7 +770,7 @@ public void testUnflushedSessionSerialization() throws Exception {
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
simple = (Simple) s.get( Simple.class, new Long(10) ); simple = (Simple) s.get( Simple.class, Long.valueOf(10) );
assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) ); assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) );
assertTrue("Not same child instances", check.getOther().getName().equals( other.getName() ) ); assertTrue("Not same child instances", check.getOther().getName().equals( other.getName() ) );
@ -793,7 +793,7 @@ public void testUnflushedSessionSerialization() throws Exception {
s.setFlushMode(FlushMode.MANUAL); s.setFlushMode(FlushMode.MANUAL);
s.beginTransaction(); s.beginTransaction();
simple = (Simple) s.get( Simple.class, new Long(10) ); simple = (Simple) s.get( Simple.class, Long.valueOf( 10 ) );
assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) ); assertTrue("Not same parent instances", check.getName().equals( simple.getName() ) );
assertTrue("Not same child instances", check.getOther().getName().equals( other.getName() ) ); assertTrue("Not same child instances", check.getOther().getName().equals( other.getName() ) );

View File

@ -25,7 +25,7 @@
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.classic.Session; import org.hibernate.Session;
import org.junit.Test; import org.junit.Test;

View File

@ -1,9 +1,10 @@
//$Id: IJTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ //$Id: IJTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.classic.Session; import org.hibernate.Session;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
import org.junit.Test; import org.junit.Test;

View File

@ -24,10 +24,10 @@
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.DefaultNamingStrategy; import org.hibernate.cfg.DefaultNamingStrategy;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.classic.Session;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.hql.classic.ClassicQueryTranslatorFactory; import org.hibernate.hql.classic.ClassicQueryTranslatorFactory;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;

View File

@ -8,6 +8,7 @@
import java.util.Set; import java.util.Set;
public class Master implements Serializable, Named { public class Master implements Serializable, Named {
private Long id;
private Master otherMaster; private Master otherMaster;
private Set details = new HashSet(); private Set details = new HashSet();
private Set moreDetails = new HashSet(); private Set moreDetails = new HashSet();
@ -20,9 +21,21 @@ public class Master implements Serializable, Named {
private int x; private int x;
private Collection allDetails; private Collection allDetails;
public Master() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getX() { public int getX() {
return x; return x;
} }
public void setX(int x) { public void setX(int x) {
this.x = x; this.x = x;
} }

View File

@ -7,7 +7,7 @@
<class name="org.hibernate.test.legacy.Master" table="`master`"> <class name="org.hibernate.test.legacy.Master" table="`master`">
<meta attribute="foo">foo</meta> <meta attribute="foo">foo</meta>
<id column="master_key_column" type="long"> <id name="id" column="master_key_column" type="long">
<generator class="native"/> <generator class="native"/>
</id> </id>
<version name="version" access="field"/> <version name="version" access="field"/>

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Connection; import java.sql.Connection;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,8 +35,8 @@
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.ObjectNotFoundException; import org.hibernate.ObjectNotFoundException;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example; import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
@ -136,7 +137,7 @@ public void testCopy() throws Exception {
newCat.getSubcategories().add(newSubCat); newCat.getSubcategories().add(newSubCat);
s = openSession(); s = openSession();
Category copiedCat = (Category) s.saveOrUpdateCopy(cat); Category copiedCat = (Category) s.merge( cat );
s.flush(); s.flush();
s.connection().commit(); s.connection().commit();
s.close(); s.close();
@ -155,12 +156,6 @@ public void testCopy() throws Exception {
cat.setName("new new foo"); cat.setName("new new foo");
s = openSession(); s = openSession();
newSubCat = (Category) s.saveOrUpdateCopy( newSubCat, new Long( newSubCat.getId() ) );
assertTrue( newSubCat.getName().equals("new sub") );
assertTrue( newSubCat.getSubcategories().size()==1 );
cat = (Category) newSubCat.getSubcategories().get(0);
assertTrue( cat.getName().equals("new new foo") );
newSubCat.getSubcategories().remove(cat);
s.delete(cat); s.delete(cat);
s.delete(subCatBaz); s.delete(subCatBaz);
s.delete(catWA); s.delete(catWA);
@ -197,7 +192,9 @@ public void testNotNullDiscriminator() throws Exception {
//list = s.find("from Up down where down.class = Down"); //list = s.find("from Up down where down.class = Down");
assertTrue( list.size()==1 ); assertTrue( list.size()==1 );
assertTrue( list.get(0) instanceof Down ); assertTrue( list.get(0) instanceof Down );
s.delete("from Up up"); for ( Object entity : s.createQuery( "from Up" ).list() ) {
s.delete( entity );
}
t.commit(); t.commit();
s.close(); s.close();
@ -298,7 +295,9 @@ public void testNonLazyBidirectional() throws Exception {
s.close(); s.close();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.delete("from Single"); for ( Object entity : s.createQuery( "from Single" ).list() ) {
s.delete( entity );
}
t.commit(); t.commit();
s.close(); s.close();
} }
@ -569,7 +568,7 @@ public void testNamedQuery() throws Exception {
public void testUpdateLazyCollections() throws Exception { public void testUpdateLazyCollections() throws Exception {
Session s = openSession(); Session s = openSession();
Master m = new Master(); Master m = new Master();
Serializable mid = s.save(m); s.save( m );
Detail d1 = new Detail(); Detail d1 = new Detail();
Detail d2 = new Detail(); Detail d2 = new Detail();
d2.setX(14); d2.setX(14);
@ -584,12 +583,12 @@ public void testUpdateLazyCollections() throws Exception {
s.close(); s.close();
s = openSession(); s = openSession();
m = (Master) s.load(Master.class, mid); m = (Master) s.load( Master.class, m.getId() );
s.connection().commit(); s.connection().commit();
s.close(); s.close();
m.setName("New Name"); m.setName("New Name");
s = openSession(); s = openSession();
s.update(m, mid); s.update( m );
Iterator iter = m.getDetails().iterator(); Iterator iter = m.getDetails().iterator();
int i=0; int i=0;
while ( iter.hasNext() ) { while ( iter.hasNext() ) {
@ -1021,7 +1020,9 @@ public void testNoUpdateManyToOne() throws Exception {
s.update(z); s.update(z);
s.flush(); s.flush();
s.delete(z); s.delete(z);
s.delete("from W"); for ( Object entity : s.createQuery( "from W" ).list() ) {
s.delete( entity );
}
s.flush(); s.flush();
s.connection().commit(); s.connection().commit();
s.close(); s.close();

View File

@ -1,5 +1,6 @@
//$Id: MultiTableTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ //$Id: MultiTableTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -11,8 +12,8 @@
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.FetchMode; import org.hibernate.FetchMode;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.MySQLDialect;
@ -167,7 +168,7 @@ public void testCollectionOnly() throws Exception {
s.close(); s.close();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update(m, id); s.update( m );
s.flush(); s.flush();
m.setAddress("foo bar"); m.setAddress("foo bar");
s.flush(); s.flush();
@ -246,11 +247,11 @@ public void testMultiTable() throws Exception {
multi.setExtraProp( multi.getExtraProp() + "2" ); multi.setExtraProp( multi.getExtraProp() + "2" );
//multi.setCount( multi.getCount() + 1 ); //multi.setCount( multi.getCount() + 1 );
multi.setName("new name"); multi.setName("new name");
s.update(multi, mid); s.update( multi );
simp.setName("new name"); simp.setName("new name");
s.update(simp, sid); s.update( simp );
sm.setAmount(456.7f); sm.setAmount(456.7f);
s.update(sm, smid); s.update( sm );
t.commit(); t.commit();
s.close(); s.close();
@ -351,7 +352,7 @@ public void testMultiTable() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update(multi, mid); s.update(multi);
s.delete(multi); s.delete(multi);
assertEquals( 2, doDelete( s, "from Top" ) ); assertEquals( 2, doDelete( s, "from Top" ) );
t.commit(); t.commit();
@ -384,11 +385,11 @@ public void testMultiTableGeneratedId() throws Exception {
multi.setExtraProp( multi.getExtraProp() + "2" ); multi.setExtraProp( multi.getExtraProp() + "2" );
//multi.setCount( multi.getCount() + 1 ); //multi.setCount( multi.getCount() + 1 );
multi.setName("new name"); multi.setName("new name");
s.update( multi, multiId ); s.update( multi );
simp.setName("new name"); simp.setName("new name");
s.update( simp, simpId ); s.update( simp );
sm.setAmount(456.7f); sm.setAmount(456.7f);
s.update( sm, smId ); s.update( sm );
t.commit(); t.commit();
s.close(); s.close();
@ -469,7 +470,7 @@ public void testMultiTableGeneratedId() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( multi, multiId ); s.update( multi );
s.delete(multi); s.delete(multi);
assertEquals( 2, doDelete( s, "from Top" ) ); assertEquals( 2, doDelete( s, "from Top" ) );
t.commit(); t.commit();

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
@ -40,8 +41,8 @@
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.ObjectNotFoundException; import org.hibernate.ObjectNotFoundException;
import org.hibernate.ReplicationMode; import org.hibernate.ReplicationMode;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
@ -63,6 +64,7 @@
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@SuppressWarnings( {"UnnecessaryBoxing"})
public class ParentChildTest extends LegacyTestCase { public class ParentChildTest extends LegacyTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {
@ -183,13 +185,15 @@ public void testProxyReuse() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
foo.setFloat( new Float(1.2f) ); foo.setKey( "xyzid" );
foo.setFloat( new Float( 1.2f ) );
foo2.setKey( (String) id ); //intentionally id, not id2!
foo2.setFloat( new Float(1.3f) ); foo2.setFloat( new Float(1.3f) );
foo2.getDependent().setKey(null); foo2.getDependent().setKey( null );
foo2.getComponent().getSubcomponent().getFee().setKey(null); foo2.getComponent().getSubcomponent().getFee().setKey(null);
assertFalse( foo2.getKey().equals(id) ); assertFalse( foo2.getKey().equals( id ) );
s.save(foo, "xyzid"); s.save( foo );
s.update(foo2, id); //intentionally id, not id2! s.update( foo2 );
assertEquals( foo2.getKey(), id ); assertEquals( foo2.getKey(), id );
assertTrue( foo2.getInt()==1234567 ); assertTrue( foo2.getInt()==1234567 );
assertEquals( foo.getKey(), "xyzid" ); assertEquals( foo.getKey(), "xyzid" );
@ -537,14 +541,16 @@ public void testCollectionQuery() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple s1 = new Simple(); Simple s1 = new Simple( Long.valueOf(1) );
s1.setName("s"); s1.setName("s");
s1.setCount(0); s1.setCount(0);
Simple s2 = new Simple(); Simple s2 = new Simple( Long.valueOf(2) );
s2.setCount(2); s2.setCount(2);
Simple s3 = new Simple(); Simple s3 = new Simple( Long.valueOf(3) );
s3.setCount(3); s3.setCount(3);
s.save( s1, new Long(1) ); s.save( s2, new Long(2) ); s.save( s3, new Long(3) ); s.save( s1 );
s.save( s2 );
s.save( s3 );
Container c = new Container(); Container c = new Container();
Contained cd = new Contained(); Contained cd = new Contained();
List bag = new ArrayList(); List bag = new ArrayList();
@ -563,10 +569,10 @@ public void testCollectionQuery() throws Exception {
s.save(c); s.save(c);
Container cx = new Container(); Container cx = new Container();
s.save(cx); s.save(cx);
Simple sx = new Simple(); Simple sx = new Simple( Long.valueOf(5) );
sx.setCount(5); sx.setCount(5);
sx.setName("s"); sx.setName("s");
s.save( sx, new Long(5) ); s.save( sx );
assertTrue( assertTrue(
s.createQuery( "select c from ContainerX c, Simple s where c.oneToMany[2] = s" ).list() s.createQuery( "select c from ContainerX c, Simple s where c.oneToMany[2] = s" ).list()
.size() == 1 .size() == 1
@ -716,8 +722,8 @@ public void testManyToMany() throws Exception {
Container c = new Container(); Container c = new Container();
c.setManyToMany( new ArrayList() ); c.setManyToMany( new ArrayList() );
c.setBag( new ArrayList() ); c.setBag( new ArrayList() );
Simple s1 = new Simple(); Simple s1 = new Simple( Long.valueOf(12) );
Simple s2 = new Simple(); Simple s2 = new Simple( Long.valueOf(-1) );
s1.setCount(123); s2.setCount(654); s1.setCount(123); s2.setCount(654);
Contained c1 = new Contained(); Contained c1 = new Contained();
c1.setBag( new ArrayList() ); c1.setBag( new ArrayList() );
@ -725,8 +731,9 @@ public void testManyToMany() throws Exception {
c.getBag().add(c1); c.getBag().add(c1);
c.getManyToMany().add(s1); c.getManyToMany().add(s1);
c.getManyToMany().add(s2); c.getManyToMany().add(s2);
Serializable cid = s.save(c); //s.save(c1); Serializable cid = s.save(c);
s.save(s1, new Long(12) ); s.save(s2, new Long(-1) ); s.save( s1 );
s.save( s2 );
t.commit(); t.commit();
s.close(); s.close();
@ -762,9 +769,12 @@ public void testContainer() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Container c = new Container(); Container c = new Container();
Simple x = new Simple(); x.setCount(123); Simple x = new Simple( Long.valueOf(1) );
Simple y = new Simple(); y.setCount(456); x.setCount(123);
s.save( x, new Long(1) ); s.save( y, new Long(0) ); Simple y = new Simple( Long.valueOf(0) );
y.setCount(456);
s.save( x );
s.save( y );
List o2m = new ArrayList(); List o2m = new ArrayList();
o2m.add(x); o2m.add(null); o2m.add(y); o2m.add(x); o2m.add(null); o2m.add(y);
List m2m = new ArrayList(); List m2m = new ArrayList();
@ -1080,14 +1090,18 @@ public void testDeleteEmpty() throws Exception {
public void testLocking() throws Exception { public void testLocking() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
Simple s1 = new Simple(); s1.setCount(1); Simple s1 = new Simple( Long.valueOf(1) );
Simple s2 = new Simple(); s2.setCount(2); s1.setCount(1);
Simple s3 = new Simple(); s3.setCount(3); Simple s2 = new Simple( Long.valueOf(2) );
Simple s4 = new Simple(); s4.setCount(4); s2.setCount(2);
s.save(s1, new Long(1) ); Simple s3 = new Simple( Long.valueOf(3) );
s.save(s2, new Long(2) ); s3.setCount(3);
s.save(s3, new Long(3) ); Simple s4 = new Simple( Long.valueOf(4) );
s.save(s4, new Long(4) ); s4.setCount(4);
s.save( s1 );
s.save( s2 );
s.save( s3 );
s.save( s4 );
assertTrue( s.getCurrentLockMode(s1)==LockMode.WRITE ); assertTrue( s.getCurrentLockMode(s1)==LockMode.WRITE );
tx.commit(); tx.commit();
s.close(); s.close();
@ -1196,20 +1210,20 @@ public void testLoadAfterNonExists() throws HibernateException, SQLException {
// Next, lets create that entity "under the covers" // Next, lets create that entity "under the covers"
Session anotherSession = sessionFactory().openSession(); Session anotherSession = sessionFactory().openSession();
anotherSession.beginTransaction(); anotherSession.beginTransaction();
Simple myNewSimple = new Simple(); Simple myNewSimple = new Simple( Long.valueOf(-1) );
myNewSimple.setName("My under the radar Simple entity"); myNewSimple.setName("My under the radar Simple entity");
myNewSimple.setAddress("SessionCacheTest.testLoadAfterNonExists"); myNewSimple.setAddress("SessionCacheTest.testLoadAfterNonExists");
myNewSimple.setCount(1); myNewSimple.setCount(1);
myNewSimple.setDate( new Date() ); myNewSimple.setDate( new Date() );
myNewSimple.setPay( new Float(100000000) ); myNewSimple.setPay( Float.valueOf( 100000000 ) );
anotherSession.save( myNewSimple, new Long(-1) ); anotherSession.save( myNewSimple );
anotherSession.getTransaction().commit(); anotherSession.getTransaction().commit();
anotherSession.close(); anotherSession.close();
// Now, lets make sure the original session can see the created row... // Now, lets make sure the original session can see the created row...
session.clear(); session.clear();
try { try {
Simple dummy = (Simple) session.get( Simple.class, new Long(-1) ); Simple dummy = (Simple) session.get( Simple.class, Long.valueOf(-1) );
assertNotNull("Unable to locate entity Simple with id = -1", dummy); assertNotNull("Unable to locate entity Simple with id = -1", dummy);
session.delete( dummy ); session.delete( dummy );
} }

View File

@ -25,8 +25,8 @@
import java.util.List; import java.util.List;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example; import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
@ -131,7 +131,9 @@ private void initData() throws Exception {
private void deleteData() throws Exception { private void deleteData() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
s.delete("from Componentizable"); for ( Object entity : s.createQuery( "from Componentizable" ).list() ) {
s.delete( entity );
}
t.commit(); t.commit();
s.close(); s.close();
} }

View File

@ -22,7 +22,7 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import static org.hibernate.testing.TestLogger.LOG;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -36,8 +36,8 @@
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.ScrollableResults; import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.InterbaseDialect; import org.hibernate.dialect.InterbaseDialect;
@ -54,11 +54,13 @@
import org.junit.Test; import org.junit.Test;
import static org.hibernate.testing.TestLogger.LOG;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@SuppressWarnings( {"UnnecessaryUnboxing", "UnnecessaryBoxing"})
public class SQLFunctionsTest extends LegacyTestCase { public class SQLFunctionsTest extends LegacyTestCase {
private static final Logger log = LoggerFactory.getLogger(SQLFunctionsTest.class); private static final Logger log = LoggerFactory.getLogger(SQLFunctionsTest.class);
@ -80,12 +82,12 @@ public void testDialectSQLFunctions() throws Exception {
if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null ); if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null );
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple Dialect Function Test"); simple.setName("Simple Dialect Function Test");
simple.setAddress("Simple Address"); simple.setAddress("Simple Address");
simple.setPay(new Float(45.8)); simple.setPay( Float.valueOf(45.8f) );
simple.setCount(2); simple.setCount(2);
s.save(simple, new Long(10) ); s.save( simple );
// Test to make sure allocating an specified object operates correctly. // Test to make sure allocating an specified object operates correctly.
assertTrue( assertTrue(
@ -105,15 +107,15 @@ public void testDialectSQLFunctions() throws Exception {
List rset = s.createQuery( "select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s" ).list(); List rset = s.createQuery( "select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s" ).list();
assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0])); assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0]));
assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1])); assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1]));
assertEquals("trunc(45.8) result was incorrect ", new Float(45), ( (Object[]) rset.get(0) )[2] ); assertEquals("trunc(45.8) result was incorrect ", Float.valueOf(45), ( (Object[]) rset.get(0) )[2] );
assertEquals("round(45.8) result was incorrect ", new Float(46), ( (Object[]) rset.get(0) )[3] ); assertEquals("round(45.8) result was incorrect ", Float.valueOf(46), ( (Object[]) rset.get(0) )[3] );
simple.setPay(new Float(-45.8)); simple.setPay(new Float(-45.8));
s.update(simple); s.update(simple);
// Test type conversions while using nested functions (Float to Int). // Test type conversions while using nested functions (Float to Int).
rset = s.createQuery( "select abs(round(s.pay)) from Simple s" ).list(); rset = s.createQuery( "select abs(round(s.pay)) from Simple s" ).list();
assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0)); assertEquals("abs(round(-45.8)) result was incorrect ", Float.valueOf( 46 ), rset.get(0));
// Test a larger depth 3 function example - Not a useful combo other than for testing // Test a larger depth 3 function example - Not a useful combo other than for testing
assertTrue( assertTrue(
@ -147,9 +149,9 @@ public void testDialectSQLFunctions() throws Exception {
public void testSetProperties() throws Exception { public void testSetProperties() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save(simple, new Long(10) ); s.save( simple );
Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count"); Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count");
q.setProperties(simple); q.setProperties(simple);
assertTrue( q.list().get(0)==simple ); assertTrue( q.list().get(0)==simple );
@ -187,9 +189,9 @@ public void testSetProperties() throws Exception {
public void testSetPropertiesMap() throws Exception { public void testSetPropertiesMap() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save(simple, new Long(10) ); s.save( simple );
Map parameters = new HashMap(); Map parameters = new HashMap();
parameters.put("name", simple.getName()); parameters.put("name", simple.getName());
parameters.put("count", new Integer(simple.getCount())); parameters.put("count", new Integer(simple.getCount()));
@ -252,21 +254,21 @@ public void testBroken() throws Exception {
public void testNothinToUpdate() throws Exception { public void testNothinToUpdate() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, new Long(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, new Long(10) ); s.update( simple );
t.commit(); t.commit();
s.close(); s.close();
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, new Long(10) ); s.update( simple );
s.delete(simple); s.delete(simple);
t.commit(); t.commit();
s.close(); s.close();
@ -276,9 +278,11 @@ public void testNothinToUpdate() throws Exception {
public void testCachedQuery() throws Exception { public void testCachedQuery() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName( "Simple 1" );
s.save( simple, new Long(10) ); Long id = (Long) s.save( simple );
assertEquals( Long.valueOf( 10 ), id );
assertEquals( Long.valueOf( 10 ), simple.getId() );
t.commit(); t.commit();
s.close(); s.close();
@ -317,7 +321,7 @@ public void testCachedQuery() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, new Long(10) ); s.update( simple );
s.delete(simple); s.delete(simple);
t.commit(); t.commit();
s.close(); s.close();
@ -337,9 +341,9 @@ public void testCachedQuery() throws Exception {
public void testCachedQueryRegion() throws Exception { public void testCachedQueryRegion() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, new Long(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
@ -370,7 +374,7 @@ public void testCachedQueryRegion() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.update( simple, new Long(10) ); s.update( simple );
s.delete(simple); s.delete(simple);
t.commit(); t.commit();
s.close(); s.close();
@ -391,9 +395,9 @@ public void testCachedQueryRegion() throws Exception {
public void testSQLFunctions() throws Exception { public void testSQLFunctions() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save(simple, new Long(10) ); s.save( simple );
if ( getDialect() instanceof DB2Dialect) { if ( getDialect() instanceof DB2Dialect) {
s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list(); s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
@ -428,11 +432,11 @@ public void testSQLFunctions() throws Exception {
); );
} }
Simple other = new Simple(); Simple other = new Simple( Long.valueOf(20) );
other.setName("Simple 2"); other.setName("Simple 2");
other.setCount(12); other.setCount(12);
simple.setOther(other); simple.setOther(other);
s.save( other, new Long(20) ); s.save( other );
//s.find("from Simple s where s.name ## 'cat|rat|bag'"); //s.find("from Simple s where s.name ## 'cat|rat|bag'");
assertTrue( assertTrue(
s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1 s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1
@ -452,9 +456,9 @@ public void testSQLFunctions() throws Exception {
).list() ).list()
.size()==1 .size()==1
); );
Simple min = new Simple(); Simple min = new Simple( Long.valueOf(30) );
min.setCount(-1); min.setCount(-1);
s.save(min, new Long(30) ); s.save( min );
if ( ! (getDialect() instanceof MySQLDialect) && ! (getDialect() instanceof HSQLDialect) ) { //My SQL has no subqueries if ( ! (getDialect() instanceof MySQLDialect) && ! (getDialect() instanceof HSQLDialect) ) { //My SQL has no subqueries
assertTrue( assertTrue(
s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" ) s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" )
@ -480,7 +484,7 @@ public void testSQLFunctions() throws Exception {
Iterator iter = s.createQuery( "select sum(s.count) from Simple s group by s.count having sum(s.count) > 10" ) Iterator iter = s.createQuery( "select sum(s.count) from Simple s group by s.count having sum(s.count) > 10" )
.iterate(); .iterate();
assertTrue( iter.hasNext() ); assertTrue( iter.hasNext() );
assertEquals( new Long(12), iter.next() ); assertEquals( Long.valueOf(12), iter.next() );
assertTrue( !iter.hasNext() ); assertTrue( !iter.hasNext() );
if ( ! (getDialect() instanceof MySQLDialect) ) { if ( ! (getDialect() instanceof MySQLDialect) ) {
iter = s.createQuery( "select s.count from Simple s group by s.count having s.count = 12" ).iterate(); iter = s.createQuery( "select s.count from Simple s group by s.count having s.count = 12" ).iterate();
@ -532,7 +536,7 @@ public void testSQLFunctions() throws Exception {
HashSet set = new HashSet(); HashSet set = new HashSet();
set.add("Simple 1"); set.add("foo"); set.add("Simple 1"); set.add("foo");
q.setParameterList( "name_list", set ); q.setParameterList( "name_list", set );
q.setParameter("count", new Integer(-1) ); q.setParameter("count", Integer.valueOf( -1 ) );
assertTrue( q.list().size()==1 ); assertTrue( q.list().size()==1 );
ScrollableResults sr = s.createQuery("from Simple s").scroll(); ScrollableResults sr = s.createQuery("from Simple s").scroll();
@ -613,9 +617,9 @@ public void testSqlFunctionAsAlias() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, new Long(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
@ -644,9 +648,9 @@ private String locateAppropriateDialectFunctionNameForAliasTest() {
public void testCachedQueryOnInsert() throws Exception { public void testCachedQueryOnInsert() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(10) );
simple.setName("Simple 1"); simple.setName("Simple 1");
s.save( simple, new Long(10) ); s.save( simple );
t.commit(); t.commit();
s.close(); s.close();
@ -668,9 +672,9 @@ public void testCachedQueryOnInsert() throws Exception {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
Simple simple2 = new Simple(); Simple simple2 = new Simple( Long.valueOf(12) );
simple2.setCount(133); simple2.setCount(133);
s.save( simple2, new Long(12) ); s.save( simple2 );
t.commit(); t.commit();
s.close(); s.close();

View File

@ -1,5 +1,6 @@
//$Id: SQLLoaderTest.java 11383 2007-04-02 15:34:02Z steve.ebersole@jboss.com $ //$Id: SQLLoaderTest.java 11383 2007-04-02 15:34:02Z steve.ebersole@jboss.com $
package org.hibernate.test.legacy; package org.hibernate.test.legacy;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -7,8 +8,9 @@
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.dialect.PostgreSQLDialect;
@ -26,7 +28,6 @@
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class SQLLoaderTest extends LegacyTestCase { public class SQLLoaderTest extends LegacyTestCase {
static int nextInt = 1; static int nextInt = 1;
static long nextLong = 1; static long nextLong = 1;
@ -48,10 +49,10 @@ public String[] getMappings() {
public void testTS() throws Exception { public void testTS() throws Exception {
Session session = openSession(); Session session = openSession();
Transaction txn = session.beginTransaction(); Transaction txn = session.beginTransaction();
Simple sim = new Simple(); Simple sim = new Simple( Long.valueOf(1) );
sim.setDate( new Date() ); sim.setDate( new Date() );
session.save( sim, new Long(1) ); session.save( sim );
Query q = session.createSQLQuery("select {sim.*} from Simple {sim} where {sim}.date_ = ?", "sim", Simple.class); Query q = session.createSQLQuery( "select {sim.*} from Simple {sim} where {sim}.date_ = ?" ).addEntity( "sim", Simple.class );
q.setTimestamp( 0, sim.getDate() ); q.setTimestamp( 0, sim.getDate() );
assertTrue ( q.list().size()==1 ); assertTrue ( q.list().size()==1 );
session.delete(sim); session.delete(sim);
@ -62,18 +63,26 @@ public void testTS() throws Exception {
@Test @Test
public void testFindBySQLStar() throws HibernateException, SQLException { public void testFindBySQLStar() throws HibernateException, SQLException {
Session session = openSession(); Session session = openSession();
session.delete("from Assignable"); for ( Object entity : session.createQuery( "from Assignable" ).list() ) {
session.delete("from Category"); session.delete( entity );
session.delete("from Simple"); }
session.delete("from A"); for ( Object entity : session.createQuery( "from Category" ).list() ) {
session.delete( entity );
}
for ( Object entity : session.createQuery( "from Simple" ).list() ) {
session.delete( entity );
}
for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
Category s = new Category(); Category s = new Category();
s.setName(String.valueOf(nextLong++)); s.setName(String.valueOf(nextLong++));
session.save(s); session.save(s);
Simple simple = new Simple(); Simple simple = new Simple( Long.valueOf(nextLong++) );
simple.init(); simple.init();
session.save(simple, new Long(nextLong++)); session.save( simple );
A a = new A(); A a = new A();
session.save(a); session.save(a);
@ -82,9 +91,9 @@ public void testFindBySQLStar() throws HibernateException, SQLException {
session.save(b); session.save(b);
session.flush(); session.flush();
session.createSQLQuery("select {category.*} from category {category}", "category", Category.class).list(); session.createSQLQuery( "select {category.*} from category {category}" ).addEntity( "category", Category.class ).list();
session.createSQLQuery("select {simple.*} from Simple {simple}", "simple", Simple.class).list(); session.createSQLQuery( "select {simple.*} from Simple {simple}" ).addEntity( "simple", Simple.class ).list();
session.createSQLQuery("select {a.*} from TA {a}", "a", A.class).list(); session.createSQLQuery( "select {a.*} from TA {a}" ).addEntity( "a", A.class ).list();
session.connection().commit(); session.connection().commit();
session.close(); session.close();
@ -93,7 +102,9 @@ public void testFindBySQLStar() throws HibernateException, SQLException {
@Test @Test
public void testFindBySQLProperties() throws HibernateException, SQLException { public void testFindBySQLProperties() throws HibernateException, SQLException {
Session session = openSession(); Session session = openSession();
session.delete("from Category"); for ( Object entity : session.createQuery( "from Category" ).list() ) {
session.delete( entity );
}
Category s = new Category(); Category s = new Category();
s.setName(String.valueOf(nextLong++)); s.setName(String.valueOf(nextLong++));
@ -103,28 +114,33 @@ public void testFindBySQLProperties() throws HibernateException, SQLException {
s.setName("WannaBeFound"); s.setName("WannaBeFound");
session.flush(); session.flush();
Query query = session.createSQLQuery("select {category.*} from category {category} where {category}.name = :name", "category", Category.class); Query query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name = :name" )
.addEntity( "category", Category.class );
query.setProperties(s); query.setProperties(s);
//query.setParameter("name", s.getName()); //query.setParameter("name", s.getName());
query.list(); query.list();
query = session.createSQLQuery("select {category.*} from category {category} where {category}.name in (:names)", "category", Category.class); query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in (:names)" )
.addEntity( "category", Category.class );
String[] str = new String[] { "WannaBeFound", "NotThere" }; String[] str = new String[] { "WannaBeFound", "NotThere" };
query.setParameterList("names", str); query.setParameterList("names", str);
query.uniqueResult(); query.uniqueResult();
query = session.createSQLQuery("select {category.*} from category {category} where {category}.name in :names", "category", Category.class); query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in :names" )
.addEntity( "category", Category.class );
query.setParameterList("names", str); query.setParameterList("names", str);
query.uniqueResult(); query.uniqueResult();
query = session.createSQLQuery("select {category.*} from category {category} where {category}.name in (:names)", "category", Category.class); query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in (:names)" )
.addEntity( "category", Category.class );
str = new String[] { "WannaBeFound" }; str = new String[] { "WannaBeFound" };
query.setParameterList("names", str); query.setParameterList("names", str);
query.uniqueResult(); query.uniqueResult();
query = session.createSQLQuery("select {category.*} from category {category} where {category}.name in :names", "category", Category.class); query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in :names" )
.addEntity( "category", Category.class );
query.setParameterList("names", str); query.setParameterList("names", str);
query.uniqueResult(); query.uniqueResult();
@ -135,8 +151,12 @@ public void testFindBySQLProperties() throws HibernateException, SQLException {
@Test @Test
public void testFindBySQLAssociatedObjects() throws HibernateException, SQLException { public void testFindBySQLAssociatedObjects() throws HibernateException, SQLException {
Session s = openSession(); Session s = openSession();
s.delete("from Assignable"); for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete("from Category"); s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
Category c = new Category(); Category c = new Category();
c.setName("NAME"); c.setName("NAME");
@ -152,7 +172,7 @@ public void testFindBySQLAssociatedObjects() throws HibernateException, SQLExcep
s.close(); s.close();
s = openSession(); s = openSession();
List list = s.createSQLQuery("select {category.*} from category {category}", "category", Category.class).list(); List list = s.createSQLQuery( "select {category.*} from category {category}" ).addEntity( "category", Category.class ).list();
list.get(0); list.get(0);
s.connection().commit(); s.connection().commit();
s.close(); s.close();
@ -181,8 +201,12 @@ public void testFindBySQLAssociatedObjects() throws HibernateException, SQLExcep
@SkipForDialect( MySQLDialect.class ) @SkipForDialect( MySQLDialect.class )
public void testPropertyResultSQL() throws HibernateException, SQLException { public void testPropertyResultSQL() throws HibernateException, SQLException {
Session s = openSession(); Session s = openSession();
s.delete("from Assignable"); for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete("from Category"); s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
Category c = new Category(); Category c = new Category();
c.setName("NAME"); c.setName("NAME");
@ -214,8 +238,13 @@ public void testPropertyResultSQL() throws HibernateException, SQLException {
@Test @Test
public void testFindBySQLMultipleObject() throws HibernateException, SQLException { public void testFindBySQLMultipleObject() throws HibernateException, SQLException {
Session s = openSession(); Session s = openSession();
s.delete("from Assignable"); for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete("from Category"); s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
s.flush(); s.flush();
s.connection().commit(); s.connection().commit();
s.close(); s.close();
@ -251,7 +280,9 @@ public void testFindBySQLMultipleObject() throws HibernateException, SQLExceptio
if ( getDialect() instanceof MySQLDialect ) return; if ( getDialect() instanceof MySQLDialect ) return;
s = openSession(); s = openSession();
List list = s.createSQLQuery("select {category.*}, {assignable.*} from category {category}, \"assign-able\" {assignable}", new String[] { "category", "assignable" }, new Class[] { Category.class, Assignable.class }).list(); String sql = "select {category.*}, {assignable.*} from category {category}, \"assign-able\" {assignable}";
List list = s.createSQLQuery( sql ).addEntity( "category", Category.class ).addEntity( "assignable", Assignable.class ).list();
assertTrue(list.size() == 6); // crossproduct of 2 categories x 3 assignables assertTrue(list.size() == 6); // crossproduct of 2 categories x 3 assignables
assertTrue(list.get(0) instanceof Object[]); assertTrue(list.get(0) instanceof Object[]);
@ -262,8 +293,12 @@ public void testFindBySQLMultipleObject() throws HibernateException, SQLExceptio
@Test @Test
public void testFindBySQLParameters() throws HibernateException, SQLException { public void testFindBySQLParameters() throws HibernateException, SQLException {
Session s = openSession(); Session s = openSession();
s.delete("from Assignable"); for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete("from Category"); s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
s.flush(); s.flush();
s.connection().commit(); s.connection().commit();
s.close(); s.close();
@ -307,17 +342,20 @@ public void testFindBySQLParameters() throws HibernateException, SQLException {
s.close(); s.close();
s = openSession(); s = openSession();
Query basicParam = s.createSQLQuery("select {category.*} from category {category} where {category}.name = 'Best'", "category", Category.class); Query basicParam = s.createSQLQuery( "select {category.*} from category {category} where {category}.name = 'Best'" )
.addEntity( "category", Category.class );
List list = basicParam.list(); List list = basicParam.list();
assertEquals(1, list.size()); assertEquals(1, list.size());
Query unnamedParam = s.createSQLQuery("select {category.*} from category {category} where {category}.name = ? or {category}.name = ?", "category", Category.class); Query unnamedParam = s.createSQLQuery( "select {category.*} from category {category} where {category}.name = ? or {category}.name = ?" )
.addEntity( "category", Category.class );
unnamedParam.setString(0, "Good"); unnamedParam.setString(0, "Good");
unnamedParam.setString(1, "Best"); unnamedParam.setString(1, "Best");
list = unnamedParam.list(); list = unnamedParam.list();
assertEquals(2, list.size()); assertEquals(2, list.size());
Query namedParam = s.createSQLQuery("select {category.*} from category {category} where ({category}.name=:firstCat or {category}.name=:secondCat)", "category", Category.class); Query namedParam = s.createSQLQuery( "select {category.*} from category {category} where ({category}.name=:firstCat or {category}.name=:secondCat)" )
.addEntity( "category", Category.class);
namedParam.setString("firstCat", "Better"); namedParam.setString("firstCat", "Better");
namedParam.setString("secondCat", "Best"); namedParam.setString("secondCat", "Best");
list = namedParam.list(); list = namedParam.list();
@ -331,7 +369,9 @@ public void testFindBySQLParameters() throws HibernateException, SQLException {
@SkipForDialect( { HSQLDialect.class, PostgreSQLDialect.class } ) @SkipForDialect( { HSQLDialect.class, PostgreSQLDialect.class } )
public void testEscapedJDBC() throws HibernateException, SQLException { public void testEscapedJDBC() throws HibernateException, SQLException {
Session session = openSession(); Session session = openSession();
session.delete("from A"); for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A(); A savedA = new A();
savedA.setName("Max"); savedA.setName("Max");
session.save(savedA); session.save(savedA);
@ -349,9 +389,12 @@ public void testEscapedJDBC() throws HibernateException, SQLException {
if( getDialect() instanceof TimesTenDialect) { if( getDialect() instanceof TimesTenDialect) {
// TimesTen does not permit general expressions (like UPPER) in the second part of a LIKE expression, // TimesTen does not permit general expressions (like UPPER) in the second part of a LIKE expression,
// so we execute a similar test // so we execute a similar test
query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like 'MAX'", "a", A.class); query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like 'MAX'" )
} else { .addEntity( "a", A.class );
query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like {fn ucase('max')}", "a", A.class); }
else {
query = session.createSQLQuery( "select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like {fn ucase('max')}" )
.addEntity( "a", A.class );
} }
List list = query.list(); List list = query.list();
@ -364,7 +407,9 @@ public void testEscapedJDBC() throws HibernateException, SQLException {
@Test @Test
public void testDoubleAliasing() throws HibernateException, SQLException { public void testDoubleAliasing() throws HibernateException, SQLException {
Session session = openSession(); Session session = openSession();
session.delete("from A"); for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A(); A savedA = new A();
savedA.setName("Max"); savedA.setName("Max");
session.save(savedA); session.save(savedA);
@ -378,10 +423,17 @@ public void testDoubleAliasing() throws HibernateException, SQLException {
session = openSession(); session = openSession();
Query query = session.createSQLQuery("select a.identifier_column as {a1.id}, a.clazz_discriminata as {a1.class}, a.count_ as {a1.count}, a.name as {a1.name} " + String sql = "select a.identifier_column as {a1.id}, " +
", b.identifier_column as {a2.id}, b.clazz_discriminata as {a2.class}, b.count_ as {a2.count}, b.name as {a2.name} " + " a.clazz_discriminata as {a1.class}, " +
" from TA a, TA b" + " a.count_ as {a1.count}, " +
" where a.identifier_column = b.identifier_column", new String[] {"a1", "a2" }, new Class[] {A.class, A.class}); " a.name as {a1.name}, " +
" b.identifier_column as {a2.id}, " +
" b.clazz_discriminata as {a2.class}, " +
" b.count_ as {a2.count}, " +
" b.name as {a2.name} " +
"from TA a, TA b " +
"where a.identifier_column = b.identifier_column";
Query query = session.createSQLQuery( sql ).addEntity( "a1", A.class ).addEntity( "a2", A.class );
List list = query.list(); List list = query.list();
assertNotNull(list); assertNotNull(list);
@ -403,7 +455,7 @@ public void testEmbeddedCompositeProperties() throws HibernateException, SQLExce
session.clear(); session.clear();
Query query = session.createSQLQuery("select {sing.*} from Single {sing}", "sing", Single.class); SQLQuery query = session.createSQLQuery( "select {sing.*} from Single {sing}" ).addEntity( "sing", Single.class );
List list = query.list(); List list = query.list();
@ -411,7 +463,7 @@ public void testEmbeddedCompositeProperties() throws HibernateException, SQLExce
session.clear(); session.clear();
query = session.createSQLQuery("select {sing.*} from Single {sing} where sing.id = ?", "sing", Single.class); query = session.createSQLQuery( "select {sing.*} from Single {sing} where sing.id = ?" ).addEntity( "sing", Single.class );
query.setString(0, "my id"); query.setString(0, "my id");
list = query.list(); list = query.list();
@ -419,7 +471,8 @@ public void testEmbeddedCompositeProperties() throws HibernateException, SQLExce
session.clear(); session.clear();
query = session.createSQLQuery("select s.id as {sing.id}, s.string_ as {sing.string}, s.prop as {sing.prop} from Single s where s.id = ?", "sing", Single.class); query = session.createSQLQuery( "select s.id as {sing.id}, s.string_ as {sing.string}, s.prop as {sing.prop} from Single s where s.id = ?" )
.addEntity( "sing", Single.class );
query.setString(0, "my id"); query.setString(0, "my id");
list = query.list(); list = query.list();
@ -427,7 +480,8 @@ public void testEmbeddedCompositeProperties() throws HibernateException, SQLExce
session.clear(); session.clear();
query = session.createSQLQuery("select s.id as {sing.id}, s.string_ as {sing.string}, s.prop as {sing.prop} from Single s where s.id = ?", "sing", Single.class); query = session.createSQLQuery( "select s.id as {sing.id}, s.string_ as {sing.string}, s.prop as {sing.prop} from Single s where s.id = ?" )
.addEntity( "sing", Single.class );
query.setString(0, "my id"); query.setString(0, "my id");
list = query.list(); list = query.list();
@ -475,7 +529,8 @@ private void componentTest(String sql) throws SQLException {
Componentizable c = setupComponentData( session ); Componentizable c = setupComponentData( session );
Query q = session.createSQLQuery(sql, "comp", Componentizable.class); SQLQuery q = session.createSQLQuery( sql )
.addEntity( "comp", Componentizable.class );
List list = q.list(); List list = q.list();
assertEquals(list.size(),1); assertEquals(list.size(),1);
@ -521,7 +576,8 @@ public void testFindSimpleBySQL() throws Exception {
session.save(s); session.save(s);
session.flush(); session.flush();
Query query = session.createSQLQuery("select s.category_key_col as {category.id}, s.name as {category.name}, s.\"assign-able-id\" as {category.assignable} from {category} s", "category", Category.class); Query query = session.createSQLQuery( "select s.category_key_col as {category.id}, s.name as {category.name}, s.\"assign-able-id\" as {category.assignable} from {category} s" )
.addEntity( "category", Category.class );
List list = query.list(); List list = query.list();
assertNotNull(list); assertNotNull(list);
@ -546,7 +602,8 @@ public void testFindBySQLSimpleByDiffSessions() throws Exception {
session = openSession(); session = openSession();
Query query = session.createSQLQuery("select s.category_key_col as {category.id}, s.name as {category.name}, s.\"assign-able-id\" as {category.assignable} from {category} s", "category", Category.class); Query query = session.createSQLQuery( "select s.category_key_col as {category.id}, s.name as {category.name}, s.\"assign-able-id\" as {category.assignable} from {category} s" )
.addEntity( "category", Category.class );
List list = query.list(); List list = query.list();
assertNotNull(list); assertNotNull(list);
@ -562,7 +619,9 @@ public void testFindBySQLSimpleByDiffSessions() throws Exception {
@Test @Test
public void testFindBySQLDiscriminatedSameSession() throws Exception { public void testFindBySQLDiscriminatedSameSession() throws Exception {
Session session = openSession(); Session session = openSession();
session.delete("from A"); for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A(); A savedA = new A();
session.save(savedA); session.save(savedA);
@ -570,7 +629,8 @@ public void testFindBySQLDiscriminatedSameSession() throws Exception {
session.save(savedB); session.save(savedB);
session.flush(); session.flush();
Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, name as {a.name}, count_ as {a.count} from TA {a}", "a", A.class); Query query = session.createSQLQuery( "select identifier_column as {a.id}, clazz_discriminata as {a.class}, name as {a.name}, count_ as {a.count} from TA {a}" )
.addEntity( "a", A.class );
List list = query.list(); List list = query.list();
assertNotNull(list); assertNotNull(list);
@ -602,7 +662,9 @@ public void testFindBySQLDiscriminatedSameSession() throws Exception {
@Test @Test
public void testFindBySQLDiscriminatedDiffSession() throws Exception { public void testFindBySQLDiscriminatedDiffSession() throws Exception {
Session session = openSession(); Session session = openSession();
session.delete("from A"); for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A(); A savedA = new A();
session.save(savedA); session.save(savedA);
@ -615,7 +677,8 @@ public void testFindBySQLDiscriminatedDiffSession() throws Exception {
session = openSession(); session = openSession();
Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class); Query query = session.createSQLQuery( "select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA" )
.addEntity( "a", A.class );
List list = query.list(); List list = query.list();
assertNotNull(list); assertNotNull(list);
@ -641,7 +704,8 @@ public void testCompositeIdId() throws HibernateException, SQLException {
s = openSession(); s = openSession();
// having a composite id with one property named id works since the map used by sqlloader to map names to properties handles it. // having a composite id with one property named id works since the map used by sqlloader to map names to properties handles it.
Query query = s.createSQLQuery("select system as {c.system}, id as {c.id}, name as {c.name}, foo as {c.composite.foo}, bar as {c.composite.bar} from CompositeIdId where system=? and id=?", "c", CompositeIdId.class); String sql = "select system as {c.system}, id as {c.id}, name as {c.name}, foo as {c.composite.foo}, bar as {c.composite.bar} from CompositeIdId where system=? and id=?";
SQLQuery query = s.createSQLQuery( sql ).addEntity( "c", CompositeIdId.class );
query.setString(0, "c64"); query.setString(0, "c64");
query.setString(1, "games"); query.setString(1, "games");

View File

@ -5,7 +5,7 @@
<hibernate-mapping default-lazy="false"> <hibernate-mapping default-lazy="false">
<class name="org.hibernate.test.legacy.Simple"> <class name="org.hibernate.test.legacy.Simple">
<id type="long" column="id_"> <id name="id" type="long" column="id_">
<generator class="assigned"/> <generator class="assigned"/>
</id> </id>
<property name="name"/> <property name="name"/>

View File

@ -1,8 +1,35 @@
//$Id: Simple.java 4599 2004-09-26 05:18:27Z oneovthafew $ /*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2004-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.test.legacy; package org.hibernate.test.legacy;
import java.io.Serializable; import java.io.Serializable;
/**
* @author Gavin King
*/
public class Simple implements Serializable { public class Simple implements Serializable {
private Long id;
private String name; private String name;
private String address; private String address;
private int count; private int count;
@ -12,6 +39,10 @@ public class Simple implements Serializable {
private Long parent; private Long parent;
public Simple(Long id) {
this.id = id;
}
public Simple(int c) { public Simple(int c) {
count=c; count=c;
} }
@ -24,6 +55,15 @@ public void init() {
date=new java.sql.Date(666); date=new java.sql.Date(666);
number=new Float(55.8); number=new Float(55.8);
} }
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/** /**
* Gets the name * Gets the name
* @return Returns a String * @return Returns a String

View File

@ -14,7 +14,9 @@ public class Top {
public Top(int c) { public Top(int c) {
count=c; count=c;
} }
public Top() {}
public Top() {
}
public void init() { public void init() {
name="Someone With Along Name"; name="Someone With Along Name";

View File

@ -5,7 +5,7 @@
<hibernate-mapping default-lazy="false"> <hibernate-mapping default-lazy="false">
<class name="org.hibernate.test.legacy.Vetoer"> <class name="org.hibernate.test.legacy.Vetoer">
<id type="string" column="id_" length="32"> <id name="id" type="string" column="id_" length="32">
<generator class="uuid.hex"/> <generator class="uuid.hex"/>
</id> </id>
<property name="name"/> <property name="name"/>

View File

@ -6,14 +6,38 @@
import org.hibernate.classic.Lifecycle; import org.hibernate.classic.Lifecycle;
public class Vetoer implements Lifecycle { public class Vetoer implements Lifecycle {
private String id;
private String name;
private String[] strings;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getStrings() {
return strings;
}
public void setStrings(String[] strings) {
this.strings = strings;
}
boolean onSaveCalled; boolean onSaveCalled;
boolean onUpdateCalled; boolean onUpdateCalled;
boolean onDeleteCalled; boolean onDeleteCalled;
private String name;
private String[] strings;
public boolean onSave(Session s) throws CallbackException { public boolean onSave(Session s) throws CallbackException {
boolean result = !onSaveCalled; boolean result = !onSaveCalled;
onSaveCalled = true; onSaveCalled = true;
@ -33,23 +57,6 @@ public boolean onDelete(Session s) throws CallbackException {
} }
public void onLoad(Session s, Serializable id) {} public void onLoad(Session s, Serializable id) {}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getStrings() {
return strings;
}
public void setStrings(String[] strings) {
this.strings = strings;
}
} }

View File

@ -57,8 +57,8 @@ public String[] getMappings() {
} }
@Override @Override
public org.hibernate.classic.Session openSession() { public Session openSession() {
org.hibernate.classic.Session s = super.openSession(); Session s = super.openSession();
s.setCacheMode( getSessionCacheMode() ); s.setCacheMode( getSessionCacheMode() );
return s; return s;
} }

View File

@ -23,6 +23,7 @@
*/ */
package org.hibernate.test.readonly; package org.hibernate.test.readonly;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
@ -45,8 +46,8 @@ public String getCacheConcurrencyStrategy() {
return null; return null;
} }
public org.hibernate.classic.Session openSession() { public Session openSession() {
org.hibernate.classic.Session s = super.openSession(); Session s = super.openSession();
s.setCacheMode( getSessionCacheMode() ); s.setCacheMode( getSessionCacheMode() );
return s; return s;
} }

View File

@ -27,8 +27,8 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.junit.Test; import org.junit.Test;

View File

@ -27,8 +27,8 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.junit.Test; import org.junit.Test;

View File

@ -28,8 +28,8 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.junit.Test; import org.junit.Test;
@ -98,7 +98,9 @@ public void testFiltersWithUnionSubclass() {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
s.delete( "from Person" ); for ( Object entity : s.createQuery( "from Person" ).list() ) {
s.delete( entity );
}
t.commit(); t.commit();
s.close(); s.close();

View File

@ -128,7 +128,9 @@ public void testTernary() {
emp.setManagerBySite( new HashMap() ); emp.setManagerBySite( new HashMap() );
s.delete( emp ); s.delete( emp );
} }
((org.hibernate.classic.Session)s).delete("from Site"); for ( Object entity : s.createQuery( "from Site" ).list() ) {
s.delete( entity );
}
t.commit(); t.commit();
s.close(); s.close();
} }

View File

@ -28,8 +28,8 @@
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.junit.Test; import org.junit.Test;

View File

@ -48,9 +48,8 @@ public EJB3DeleteEventListener(EntityCallbackHandler callbackHandler) {
} }
@Override @Override
protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) { protected void invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
callbackHandler.preRemove( entity ); callbackHandler.preRemove( entity );
return super.invokeDeleteLifecycle( session, entity, persister );
} }
@Override @Override

View File

@ -28,11 +28,11 @@
import java.util.Set; import java.util.Set;
import org.hibernate.FlushMode; import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.cache.RegionFactory; import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.infinispan.InfinispanRegionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.classic.Session;
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory; import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.engine.transaction.spi.TransactionFactory; import org.hibernate.engine.transaction.spi.TransactionFactory;
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;

View File

@ -76,9 +76,9 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
private ServiceRegistryImpl serviceRegistry; private ServiceRegistryImpl serviceRegistry;
private SessionFactoryImplementor sessionFactory; private SessionFactoryImplementor sessionFactory;
private org.hibernate.classic.Session session; private Session session;
protected Dialect getDialect() { protected static Dialect getDialect() {
return DIALECT; return DIALECT;
} }
@ -94,12 +94,12 @@ protected SessionFactoryImplementor sessionFactory() {
return sessionFactory; return sessionFactory;
} }
protected org.hibernate.classic.Session openSession() throws HibernateException { protected Session openSession() throws HibernateException {
session = sessionFactory().openSession(); session = sessionFactory().openSession();
return session; return session;
} }
protected org.hibernate.classic.Session openSession(Interceptor interceptor) throws HibernateException { protected Session openSession(Interceptor interceptor) throws HibernateException {
session = sessionFactory().openSession(interceptor); session = sessionFactory().openSession(interceptor);
return session; return session;
} }
@ -231,7 +231,6 @@ protected boolean overrideCacheStrategy() {
} }
protected String getCacheConcurrencyStrategy() { protected String getCacheConcurrencyStrategy() {
// return "nonstrict-read-write";
return null; return null;
} }
@ -279,8 +278,6 @@ private void releaseSessionFactory() {
@OnFailure @OnFailure
@OnExpectedFailure @OnExpectedFailure
public void onFailure() { public void onFailure() {
// cleanupSession();
if ( rebuildSessionFactoryOnError() ) { if ( rebuildSessionFactoryOnError() ) {
rebuildSessionFactory(); rebuildSessionFactory();
} }
@ -303,7 +300,6 @@ protected void rebuildSessionFactory() {
@Before @Before
public final void beforeTest() throws Exception { public final void beforeTest() throws Exception {
System.out.println( " IN @Before CALLBACK!" );
prepareTest(); prepareTest();
} }
@ -312,7 +308,6 @@ protected void prepareTest() throws Exception {
@After @After
public final void afterTest() throws Exception { public final void afterTest() throws Exception {
System.out.println( " IN @After CALLBACK!" );
cleanupTest(); cleanupTest();
cleanupSession(); cleanupSession();