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
*
* 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
* 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,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,14 +20,15 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate;
import javax.naming.Referenceable;
import java.io.Serializable;
import java.sql.Connection;
import java.util.Map;
import java.util.Set;
import javax.naming.Referenceable;
import org.hibernate.engine.FilterDefinition;
import org.hibernate.metadata.ClassMetadata;
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.
*/
public org.hibernate.classic.Session openSession() throws HibernateException;
public Session openSession() throws HibernateException;
/**
* 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.
*/
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}.
@ -91,7 +92,7 @@ public interface SessionFactory extends Referenceable, Serializable {
*
* @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
@ -108,7 +109,7 @@ public interface SessionFactory extends Referenceable, Serializable {
*
* @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"
@ -123,7 +124,7 @@ public interface SessionFactory extends Referenceable, Serializable {
*
* @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.

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
*
* 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
* 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,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,11 +20,13 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.context;
import java.io.Serializable;
import org.hibernate.HibernateException;
import org.hibernate.Session;
/**
* 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
* 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
*
* 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
* 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,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,23 +20,24 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.context;
import java.util.Hashtable;
import java.util.Map;
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Hashtable;
import java.util.Map;
import org.jboss.logging.Logger;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
import org.hibernate.classic.Session;
import org.hibernate.Session;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.service.jta.platform.spi.JtaPlatform;
import org.jboss.logging.Logger;
/**
* An implementation of {@link CurrentSessionContext} which scopes the notion
@ -62,7 +63,6 @@ import org.jboss.logging.Logger;
* @author Steve Ebersole
*/
public class JTASessionContext implements CurrentSessionContext {
private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, JTASessionContext.class.getName());
protected final SessionFactoryImplementor factory;
@ -72,9 +72,7 @@ public class JTASessionContext implements CurrentSessionContext {
this.factory = factory;
}
/**
* {@inheritDoc}
*/
@Override
public Session currentSession() throws HibernateException {
final JtaPlatform jtaPlatform = factory.getServiceRegistry().getService( JtaPlatform.class );
final TransactionManager transactionManager = jtaPlatform.retrieveTransactionManager();

View File

@ -1,10 +1,10 @@
/*
* 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
* 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,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,14 +20,15 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.context;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.hibernate.engine.SessionFactoryImplementor;
/**
@ -56,16 +57,14 @@ import org.hibernate.engine.SessionFactoryImplementor;
*/
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;
public ManagedSessionContext(SessionFactoryImplementor factory) {
this.factory = factory;
}
/**
* {@inheritDoc}
*/
@Override
public Session currentSession() {
Session current = existingSession( factory );
if ( current == null ) {
@ -93,7 +92,7 @@ public class ManagedSessionContext implements CurrentSessionContext {
* @return Any previously bound session (should be null in most cases).
*/
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 class ManagedSessionContext implements CurrentSessionContext {
*/
public static Session unbind(SessionFactory factory) {
Session existing = null;
Map sessionMap = sessionMap();
Map<SessionFactory,Session> sessionMap = sessionMap();
if ( sessionMap != null ) {
existing = ( Session ) sessionMap.remove( factory );
existing = sessionMap.remove( factory );
doCleanup();
}
return existing;
@ -123,21 +122,21 @@ public class ManagedSessionContext implements CurrentSessionContext {
}
}
protected static Map sessionMap() {
protected static Map<SessionFactory,Session> sessionMap() {
return sessionMap( false );
}
private static synchronized Map sessionMap(boolean createMap) {
Map sessionMap = ( Map ) context.get();
private static synchronized Map<SessionFactory,Session> sessionMap(boolean createMap) {
Map<SessionFactory,Session> sessionMap = context.get();
if ( sessionMap == null && createMap ) {
sessionMap = new HashMap();
sessionMap = new HashMap<SessionFactory,Session>();
context.set( sessionMap );
}
return sessionMap;
}
private static synchronized void doCleanup() {
Map sessionMap = sessionMap( false );
Map<SessionFactory,Session> sessionMap = sessionMap( false );
if ( sessionMap != null ) {
if ( sessionMap.isEmpty() ) {
context.set( null );

View File

@ -1,10 +1,10 @@
/*
* 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
* 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,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,10 +20,10 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.context;
import javax.transaction.Synchronization;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@ -34,18 +34,19 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
import javax.transaction.Synchronization;
import org.jboss.logging.Logger;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.transaction.spi.TransactionContext;
import org.hibernate.event.EventSource;
import org.jboss.logging.Logger;
/**
* A {@link CurrentSessionContext} impl which scopes the notion of current

View File

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

View File

@ -304,33 +304,6 @@ public abstract class CascadingAction {
}
};
/**
* @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)
*/

View File

@ -32,6 +32,7 @@ import org.hibernate.ConnectionReleaseMode;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cache.QueryCache;
import org.hibernate.cache.Region;
@ -211,7 +212,7 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
/**
* 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
@ -226,7 +227,7 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
* @return An appropriate session.
* @throws HibernateException
*/
public org.hibernate.classic.Session openSession(
public Session openSession(
final Connection connection,
final boolean flushBeforeCompletionEnabled,
final boolean autoCloseSessionEnabled,

View File

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

View File

@ -71,11 +71,6 @@ public interface EventSource extends SessionImplementor, Session {
* Cascade refesh an entity instance
*/
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
*/

View File

@ -22,16 +22,20 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.event.def;
import java.io.Serializable;
import java.util.Map;
import org.jboss.logging.Logger;
import org.hibernate.HibernateLogger;
import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException;
import org.hibernate.action.internal.EntityIdentityInsertAction;
import org.hibernate.action.internal.EntityInsertAction;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable;
import org.hibernate.engine.Cascade;
import org.hibernate.engine.CascadingAction;
import org.hibernate.engine.EntityEntry;
@ -44,12 +48,10 @@ import org.hibernate.engine.Versioning;
import org.hibernate.event.EventSource;
import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.id.IdentifierGeneratorHelper;
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper;
import org.jboss.logging.Logger;
/**
* A convenience bas class for listeners responding to save events.
@ -211,12 +213,6 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
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
* the execution queue).
@ -242,8 +238,6 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
EventSource source,
boolean requiresImmediateIdAccess) {
validate( entity, persister, source );
Serializable id = key == null ? null : key.getIdentifier();
boolean inTxn = source.getTransactionCoordinator().isTransactionInProgress();

View File

@ -1,10 +1,10 @@
/*
* 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
* 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,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -20,11 +20,13 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.event.def;
import java.io.Serializable;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
@ -32,7 +34,7 @@ import org.hibernate.HibernateLogger;
import org.hibernate.StaleObjectStateException;
import org.hibernate.action.internal.DelayedPostInsertIdentifier;
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.EntityKey;
import org.hibernate.engine.Nullability;
@ -42,12 +44,10 @@ import org.hibernate.engine.Versioning;
import org.hibernate.event.EventSource;
import org.hibernate.event.FlushEntityEvent;
import org.hibernate.event.FlushEntityEventListener;
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
/**
* An event that occurs for each entity instance at flush time
@ -264,17 +264,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
} else LOG.trace("Updating entity: " + MessageHelper.infoString(persister, entry.getId(), session.getFactory()));
}
final boolean intercepted;
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 );
final boolean intercepted = !entry.isBeingReplicated() && handleInterception( event );
// increment the version number (if necessary)
final Object nextVersion = getNextVersion(event);
@ -315,13 +305,6 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
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) {
SessionImplementor session = event.getSession();
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.Interceptor;
import org.hibernate.MappingException;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.StatelessSession;
@ -145,7 +146,7 @@ import org.jboss.logging.Logger;
* safe, but also highly concurrent. Synchronization must be used extremely sparingly.
*
* @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.persister.entity.EntityPersister
* @see org.hibernate.persister.collection.CollectionPersister
@ -625,12 +626,11 @@ public final class SessionFactoryImpl
);
}
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);
}
public org.hibernate.classic.Session openSession(Interceptor sessionLocalInterceptor)
throws HibernateException {
public Session openSession(Interceptor sessionLocalInterceptor) throws HibernateException {
// note that this timestamp is not correct if the connection provider
// returns an older JDBC connection that was associated with a
// transaction that was already begun before openSession() was called
@ -639,15 +639,15 @@ public final class SessionFactoryImpl
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
}
public org.hibernate.classic.Session openSession() throws HibernateException {
public Session openSession() throws HibernateException {
return openSession(interceptor);
}
public org.hibernate.classic.Session openTemporarySession() throws HibernateException {
public Session openTemporarySession() throws HibernateException {
return new SessionImpl(
null,
this,
@ -661,7 +661,7 @@ public final class SessionFactoryImpl
);
}
public org.hibernate.classic.Session openSession(
public Session openSession(
final Connection connection,
final boolean flushBeforeCompletionEnabled,
final boolean autoCloseSessionEnabled,
@ -679,7 +679,7 @@ public final class SessionFactoryImpl
);
}
public org.hibernate.classic.Session getCurrentSession() throws HibernateException {
public Session getCurrentSession() throws HibernateException {
if ( currentSessionContext == null ) {
throw new HibernateException( "No CurrentSessionContext configured!" );
}

View File

@ -159,7 +159,7 @@ import org.jboss.logging.Logger;
public final class SessionImpl
extends AbstractSessionImpl
implements EventSource,
org.hibernate.classic.Session,
org.hibernate.Session,
TransactionContext,
LobCreationContext {
@ -697,10 +697,6 @@ public final class SessionImpl
// save() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void save(Object obj, Serializable id) throws HibernateException {
save(null, obj, id);
}
public Serializable save(Object obj) throws HibernateException {
return save( null, obj );
}
@ -709,10 +705,6 @@ public final class SessionImpl
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) {
errorIfClosed();
checkTransactionSynchStatus();
@ -730,18 +722,10 @@ public final class SessionImpl
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 {
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) {
errorIfClosed();
checkTransactionSynchStatus();
@ -887,52 +871,6 @@ public final class SessionImpl
}
// 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
@ -1239,22 +1177,6 @@ public final class SessionImpl
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 {
errorIfClosed();
checkTransactionSynchStatus();
@ -1317,18 +1239,6 @@ public final class SessionImpl
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 {
errorIfClosed();
checkTransactionSynchStatus();
@ -1359,35 +1269,6 @@ public final class SessionImpl
}
}
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) {
errorIfClosed();
checkTransactionSynchStatus();
@ -1534,23 +1415,6 @@ public final class SessionImpl
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(
Object collection,
String filter,
@ -1766,30 +1630,6 @@ public final class SessionImpl
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)
throws HibernateException {
errorIfClosed();

View File

@ -36,6 +36,7 @@ import org.hibernate.Cache;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;
import org.hibernate.TypeHelper;
@ -78,23 +79,23 @@ public class SessionFactoryStub implements SessionFactory {
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);
}
public org.hibernate.classic.Session openSession(Interceptor interceptor) throws HibernateException {
public Session openSession(Interceptor interceptor) throws HibernateException {
return getImpl().openSession(interceptor);
}
public org.hibernate.classic.Session openSession() throws HibernateException {
public Session openSession() throws HibernateException {
return getImpl().openSession();
}
public org.hibernate.classic.Session openSession(Connection conn) {
public Session openSession(Connection conn) {
return getImpl().openSession(conn);
}
public org.hibernate.classic.Session getCurrentSession() {
public Session getCurrentSession() {
return getImpl().getCurrentSession();
}

View File

@ -237,11 +237,6 @@ public interface ClassMetadata {
*/
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
* (or return null if not versioned)

View File

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

View File

@ -613,10 +613,6 @@ public interface EntityPersister extends OptimisticCacheSource {
*/
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
* cast to (optional operation).

View File

@ -633,10 +633,6 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
return false;
}
public boolean isValidatableImplementor() {
return false;
}
protected final EntityMetamodel getEntityMetamodel() {
return entityMetamodel;
}

View File

@ -1,308 +1,300 @@
/*
* 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
*
*/
/*
* 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.tuple.entity;
import java.io.Serializable;
import java.util.Map;
import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.property.Getter;
import org.hibernate.tuple.Tuplizer;
/**
* Defines further responsibilities reagarding tuplization based on
* a mapped entity.
* <p/>
* EntityTuplizer implementations should have the following constructor signature:
* (org.hibernate.tuple.entity.EntityMetamodel, org.hibernate.mapping.PersistentClass)
*
* @author Gavin King
* @author Steve Ebersole
*/
public interface EntityTuplizer extends Tuplizer {
/**
* Return the entity-mode handled by this tuplizer instance.
*
* @return The entity-mode
*/
public EntityMode getEntityMode();
/**
* Create an entity instance initialized with the given identifier.
*
* @param id The identifier value for the entity to be instantiated.
* @return The instantiated entity.
* @throws HibernateException
*
* @deprecated Use {@link #instantiate(Serializable, SessionImplementor)} instead.
* @noinspection JavaDoc
*/
public Object instantiate(Serializable id) throws HibernateException;
/**
* Create an entity instance initialized with the given identifier.
*
* @param id The identifier value for the entity to be instantiated.
* @param session The session from which is requests originates
*
* @return The instantiated entity.
*/
public Object instantiate(Serializable id, SessionImplementor session);
/**
* Extract the identifier value from the given entity.
*
* @param entity The entity from which to extract the identifier value.
*
* @return The identifier value.
*
* @throws HibernateException If the entity does not define an identifier property, or an
* error occurs accessing its value.
*
* @deprecated Use {@link #getIdentifier(Object,SessionImplementor)} instead.
*/
public Serializable getIdentifier(Object entity) throws HibernateException;
/**
* Extract the identifier value from the given entity.
*
* @param entity The entity from which to extract the identifier value.
* @param session The session from which is requests originates
*
* @return The identifier value.
*/
public Serializable getIdentifier(Object entity, SessionImplementor session);
/**
* Inject the identifier value into the given entity.
* </p>
* Has no effect if the entity does not define an identifier property
*
* @param entity The entity to inject with the identifier value.
* @param id The value to be injected as the identifier.
*
* @deprecated Use {@link #setIdentifier(Object, Serializable, SessionImplementor)} instead.
* @noinspection JavaDoc
*/
public void setIdentifier(Object entity, Serializable id) throws HibernateException;
/**
* Inject the identifier value into the given entity.
* </p>
* Has no effect if the entity does not define an identifier property
*
* @param entity The entity to inject with the identifier value.
* @param id The value to be injected as the identifier.
* @param session The session from which is requests originates
*/
public void setIdentifier(Object entity, Serializable id, SessionImplementor session);
/**
* Inject the given identifier and version into the entity, in order to
* "roll back" to their original values.
*
* @param entity The entity for which to reset the id/version values
* @param currentId The identifier value to inject into the entity.
* @param currentVersion The version value to inject into the entity.
*
* @deprecated Use {@link #resetIdentifier(Object, Serializable, Object, SessionImplementor)} instead
*/
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion);
/**
* Inject the given identifier and version into the entity, in order to
* "roll back" to their original values.
*
* @param entity The entity for which to reset the id/version values
* @param currentId The identifier value to inject into the entity.
* @param currentVersion The version value to inject into the entity.
* @param session The session from which the request originated
*/
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SessionImplementor session);
/**
* Extract the value of the version property from the given entity.
*
* @param entity The entity from which to extract the version value.
* @return The value of the version property, or null if not versioned.
* @throws HibernateException
*/
public Object getVersion(Object entity) throws HibernateException;
/**
* Inject the value of a particular property.
*
* @param entity The entity into which to inject the value.
* @param i The property's index.
* @param value The property value to inject.
* @throws HibernateException
*/
public void setPropertyValue(Object entity, int i, Object value) throws HibernateException;
/**
* Inject the value of a particular property.
*
* @param entity The entity into which to inject the value.
* @param propertyName The name of the property.
* @param value The property value to inject.
* @throws HibernateException
*/
public void setPropertyValue(Object entity, String propertyName, Object value) throws HibernateException;
/**
* Extract the values of the insertable properties of the entity (including backrefs)
*
* @param entity The entity from which to extract.
* @param mergeMap a map of instances being merged to merged instances
* @param session The session in which the resuest is being made.
* @return The insertable property values.
* @throws HibernateException
*/
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session)
throws HibernateException;
/**
* Extract the value of a particular property from the given entity.
*
* @param entity The entity from which to extract the property value.
* @param propertyName The name of the property for which to extract the value.
* @return The current value of the given property on the given entity.
* @throws HibernateException
*/
public Object getPropertyValue(Object entity, String propertyName) throws HibernateException;
/**
* Called just after the entities properties have been initialized.
*
* @param entity The entity being initialized.
* @param lazyPropertiesAreUnfetched Are defined lazy properties currently unfecthed
* @param session The session initializing this entity.
*/
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session);
/**
* Does this entity, for this mode, present a possibility for proxying?
*
* @return True if this tuplizer can generate proxies for this entity.
*/
public boolean hasProxy();
/**
* Generates an appropriate proxy representation of this entity for this
* entity-mode.
*
* @param id The id of the instance for which to generate a proxy.
* @param session The session to which the proxy should be bound.
* @return The generate proxies.
* @throws HibernateException Indicates an error generating the proxy.
*/
public Object createProxy(Serializable id, SessionImplementor session) throws HibernateException;
/**
* Does the {@link #getMappedClass() class} managed by this tuplizer implement
* the {@link org.hibernate.classic.Lifecycle} interface.
*
* @return True if the Lifecycle interface is implemented; false otherwise.
*/
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.
* <p/>
* todo : look at fully encapsulating {@link org.hibernate.engine.PersistenceContext#narrowProxy} here,
* since that is the only external use of this method
*
* @return The java class to which generated proxies will be typed
*/
public Class getConcreteProxyClass();
/**
* Does the given entity instance have any currently uninitialized lazy properties?
*
* @param entity The entity to be check for uninitialized lazy properties.
* @return True if uninitialized lazy properties were found; false otherwise.
*/
public boolean hasUninitializedLazyProperties(Object entity);
/**
* Is it an instrumented POJO?
*/
public boolean isInstrumented();
/**
* Get any {@link EntityNameResolver EntityNameResolvers} associated with this {@link Tuplizer}.
*
* @return The associated resolvers. May be null or empty.
*/
public EntityNameResolver[] getEntityNameResolvers();
/**
* Given an entity instance, determine the most appropriate (most targeted) entity-name which represents it.
* This is called in situations where we already know an entity name for the given entityInstance; we are being
* asked to determine if there is a more appropriate entity-name to use, specifically within an inheritence
* hierarchy.
* <p/>
* For example, consider a case where a user calls <tt>session.update( "Animal", cat );</tt>. Here, the
* user has explicitly provided <tt>Animal</tt> as the entity-name. However, they have passed in an instance
* of <tt>Cat</tt> which is a subclass of <tt>Animal</tt>. In this case, we would return <tt>Cat</tt> as the
* entity-name.
* <p/>
* <tt>null</tt> may be returned from calls to this method. The meaining of <tt>null</tt> in that case is assumed
* to be that we should use whatever explicit entity-name the user provided (<tt>Animal</tt> rather than <tt>Cat</tt>
* in the example above).
*
* @param entityInstance The entity instance.
* @param factory Reference to the SessionFactory.
*
* @return The most appropriate entity name to use.
*
* @throws HibernateException If we are unable to determine an entity-name within the inheritence hierarchy.
*/
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory);
/**
* Retrieve the getter for the identifier property. May return null.
*
* @return The getter for the identifier property.
*/
public Getter getIdentifierGetter();
/**
* Retrieve the getter for the version property. May return null.
*
* @return The getter for the version property.
*/
public Getter getVersionGetter();
import java.io.Serializable;
import java.util.Map;
import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.property.Getter;
import org.hibernate.tuple.Tuplizer;
/**
* Defines further responsibilities reagarding tuplization based on
* a mapped entity.
* <p/>
* EntityTuplizer implementations should have the following constructor signature:
* (org.hibernate.tuple.entity.EntityMetamodel, org.hibernate.mapping.PersistentClass)
*
* @author Gavin King
* @author Steve Ebersole
*/
public interface EntityTuplizer extends Tuplizer {
/**
* Return the entity-mode handled by this tuplizer instance.
*
* @return The entity-mode
*/
public EntityMode getEntityMode();
/**
* Create an entity instance initialized with the given identifier.
*
* @param id The identifier value for the entity to be instantiated.
* @return The instantiated entity.
* @throws HibernateException
*
* @deprecated Use {@link #instantiate(Serializable, SessionImplementor)} instead.
* @noinspection JavaDoc
*/
public Object instantiate(Serializable id) throws HibernateException;
/**
* Create an entity instance initialized with the given identifier.
*
* @param id The identifier value for the entity to be instantiated.
* @param session The session from which is requests originates
*
* @return The instantiated entity.
*/
public Object instantiate(Serializable id, SessionImplementor session);
/**
* Extract the identifier value from the given entity.
*
* @param entity The entity from which to extract the identifier value.
*
* @return The identifier value.
*
* @throws HibernateException If the entity does not define an identifier property, or an
* error occurs accessing its value.
*
* @deprecated Use {@link #getIdentifier(Object,SessionImplementor)} instead.
*/
public Serializable getIdentifier(Object entity) throws HibernateException;
/**
* Extract the identifier value from the given entity.
*
* @param entity The entity from which to extract the identifier value.
* @param session The session from which is requests originates
*
* @return The identifier value.
*/
public Serializable getIdentifier(Object entity, SessionImplementor session);
/**
* Inject the identifier value into the given entity.
* </p>
* Has no effect if the entity does not define an identifier property
*
* @param entity The entity to inject with the identifier value.
* @param id The value to be injected as the identifier.
*
* @deprecated Use {@link #setIdentifier(Object, Serializable, SessionImplementor)} instead.
* @noinspection JavaDoc
*/
public void setIdentifier(Object entity, Serializable id) throws HibernateException;
/**
* Inject the identifier value into the given entity.
* </p>
* Has no effect if the entity does not define an identifier property
*
* @param entity The entity to inject with the identifier value.
* @param id The value to be injected as the identifier.
* @param session The session from which is requests originates
*/
public void setIdentifier(Object entity, Serializable id, SessionImplementor session);
/**
* Inject the given identifier and version into the entity, in order to
* "roll back" to their original values.
*
* @param entity The entity for which to reset the id/version values
* @param currentId The identifier value to inject into the entity.
* @param currentVersion The version value to inject into the entity.
*
* @deprecated Use {@link #resetIdentifier(Object, Serializable, Object, SessionImplementor)} instead
*/
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion);
/**
* Inject the given identifier and version into the entity, in order to
* "roll back" to their original values.
*
* @param entity The entity for which to reset the id/version values
* @param currentId The identifier value to inject into the entity.
* @param currentVersion The version value to inject into the entity.
* @param session The session from which the request originated
*/
public void resetIdentifier(Object entity, Serializable currentId, Object currentVersion, SessionImplementor session);
/**
* Extract the value of the version property from the given entity.
*
* @param entity The entity from which to extract the version value.
* @return The value of the version property, or null if not versioned.
* @throws HibernateException
*/
public Object getVersion(Object entity) throws HibernateException;
/**
* Inject the value of a particular property.
*
* @param entity The entity into which to inject the value.
* @param i The property's index.
* @param value The property value to inject.
* @throws HibernateException
*/
public void setPropertyValue(Object entity, int i, Object value) throws HibernateException;
/**
* Inject the value of a particular property.
*
* @param entity The entity into which to inject the value.
* @param propertyName The name of the property.
* @param value The property value to inject.
* @throws HibernateException
*/
public void setPropertyValue(Object entity, String propertyName, Object value) throws HibernateException;
/**
* Extract the values of the insertable properties of the entity (including backrefs)
*
* @param entity The entity from which to extract.
* @param mergeMap a map of instances being merged to merged instances
* @param session The session in which the resuest is being made.
* @return The insertable property values.
* @throws HibernateException
*/
public Object[] getPropertyValuesToInsert(Object entity, Map mergeMap, SessionImplementor session)
throws HibernateException;
/**
* Extract the value of a particular property from the given entity.
*
* @param entity The entity from which to extract the property value.
* @param propertyName The name of the property for which to extract the value.
* @return The current value of the given property on the given entity.
* @throws HibernateException
*/
public Object getPropertyValue(Object entity, String propertyName) throws HibernateException;
/**
* Called just after the entities properties have been initialized.
*
* @param entity The entity being initialized.
* @param lazyPropertiesAreUnfetched Are defined lazy properties currently unfecthed
* @param session The session initializing this entity.
*/
public void afterInitialize(Object entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session);
/**
* Does this entity, for this mode, present a possibility for proxying?
*
* @return True if this tuplizer can generate proxies for this entity.
*/
public boolean hasProxy();
/**
* Generates an appropriate proxy representation of this entity for this
* entity-mode.
*
* @param id The id of the instance for which to generate a proxy.
* @param session The session to which the proxy should be bound.
* @return The generate proxies.
* @throws HibernateException Indicates an error generating the proxy.
*/
public Object createProxy(Serializable id, SessionImplementor session) throws HibernateException;
/**
* Does the {@link #getMappedClass() class} managed by this tuplizer implement
* the {@link org.hibernate.classic.Lifecycle} interface.
*
* @return True if the Lifecycle interface is implemented; false otherwise.
*/
public boolean isLifecycleImplementor();
/**
* Returns the java class to which generated proxies will be typed.
* <p/>
* todo : look at fully encapsulating {@link org.hibernate.engine.PersistenceContext#narrowProxy} here,
* since that is the only external use of this method
*
* @return The java class to which generated proxies will be typed
*/
public Class getConcreteProxyClass();
/**
* Does the given entity instance have any currently uninitialized lazy properties?
*
* @param entity The entity to be check for uninitialized lazy properties.
* @return True if uninitialized lazy properties were found; false otherwise.
*/
public boolean hasUninitializedLazyProperties(Object entity);
/**
* Is it an instrumented POJO?
*/
public boolean isInstrumented();
/**
* Get any {@link EntityNameResolver EntityNameResolvers} associated with this {@link Tuplizer}.
*
* @return The associated resolvers. May be null or empty.
*/
public EntityNameResolver[] getEntityNameResolvers();
/**
* Given an entity instance, determine the most appropriate (most targeted) entity-name which represents it.
* This is called in situations where we already know an entity name for the given entityInstance; we are being
* asked to determine if there is a more appropriate entity-name to use, specifically within an inheritence
* hierarchy.
* <p/>
* For example, consider a case where a user calls <tt>session.update( "Animal", cat );</tt>. Here, the
* user has explicitly provided <tt>Animal</tt> as the entity-name. However, they have passed in an instance
* of <tt>Cat</tt> which is a subclass of <tt>Animal</tt>. In this case, we would return <tt>Cat</tt> as the
* entity-name.
* <p/>
* <tt>null</tt> may be returned from calls to this method. The meaining of <tt>null</tt> in that case is assumed
* to be that we should use whatever explicit entity-name the user provided (<tt>Animal</tt> rather than <tt>Cat</tt>
* in the example above).
*
* @param entityInstance The entity instance.
* @param factory Reference to the SessionFactory.
*
* @return The most appropriate entity name to use.
*
* @throws HibernateException If we are unable to determine an entity-name within the inheritence hierarchy.
*/
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory);
/**
* Retrieve the getter for the identifier property. May return null.
*
* @return The getter for the identifier property.
*/
public Getter getIdentifierGetter();
/**
* Retrieve the getter for the version property. May return null.
*
* @return The getter for the version property.
*/
public Getter getVersionGetter();
}

View File

@ -29,19 +29,21 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.jboss.logging.Logger;
import org.hibernate.EntityMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
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.cfg.Environment;
import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable;
import org.hibernate.engine.SessionFactoryImplementor;
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.mapping.PersistentClass;
import org.hibernate.mapping.Property;
@ -53,7 +55,6 @@ import org.hibernate.proxy.ProxyFactory;
import org.hibernate.tuple.Instantiator;
import org.hibernate.tuple.PojoInstantiator;
import org.hibernate.type.CompositeType;
import org.jboss.logging.Logger;
/**
* 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 proxyInterface;
private final boolean lifecycleImplementor;
private final boolean validatableImplementor;
private final Set lazyPropertyNames = new HashSet();
private final ReflectionOptimizer optimizer;
@ -77,7 +77,6 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
this.mappedClass = mappedEntity.getMappedClass();
this.proxyInterface = mappedEntity.getProxyInterface();
this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass );
Iterator iter = mappedEntity.getPropertyClosureIterator();
while ( iter.hasNext() ) {
@ -282,14 +281,6 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
return lifecycleImplementor;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isValidatableImplementor() {
return validatableImplementor;
}
/**
* {@inheritDoc}
*/

View File

@ -26,18 +26,19 @@ package org.hibernate.type;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Properties;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.HibernateLogger;
import org.hibernate.MappingException;
import org.hibernate.classic.Lifecycle;
import org.hibernate.classic.Validatable;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.tuple.component.ComponentMetamodel;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
import org.jboss.logging.Logger;
/**
* Used internally to build instances of {@link Type}, specifically it builds instances of
@ -98,7 +99,7 @@ public final class TypeFactory implements Serializable {
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*
return manyToOne( clazz.getName() );
}

View File

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

View File

@ -1,18 +1,18 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.dialect.functional.cache" >
<class name="TestInterSystemsFunctionsClass" table="SQLUser.TestInterSystemsFunctionsClass">
<id type="long" column="id_">
<generator class="assigned"/>
</id>
<property name="date" column="date_"/>
<property name="date1" column="date1_"/>
<property name="date3" column="date3_"/>
<property name="dateText" column="dateText_"/>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.dialect.functional.cache" >
<class name="TestInterSystemsFunctionsClass" table="SQLUser.TestInterSystemsFunctionsClass">
<id name="id" type="long" column="id_">
<generator class="assigned"/>
</id>
<property name="date" column="date_"/>
<property name="date1" column="date1_"/>
<property name="date3" column="date3_"/>
<property name="dateText" column="dateText_"/>
</class>
</hibernate-mapping>

View File

@ -1,50 +1,66 @@
package org.hibernate.test.dialect.functional.cache;
import java.util.Date;
/**
* Entity for testing function support of InterSystems' CacheSQL...
*
* @author Jonathan Levinson
*/
public class TestInterSystemsFunctionsClass {
private java.util.Date date3;
private java.util.Date date1;
private java.util.Date date;
private String dateText;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getDateText() {
return dateText;
}
public void setDateText(String dateText) {
this.dateText = dateText;
}
public Date getDate1() {
return date1;
}
public void setDate1(Date date1) {
this.date1 = date1;
}
public Date getDate3() {
return date3;
}
public void setDate3(Date date3) {
this.date3 = date3;
}
}
/**
* Entity for testing function support of InterSystems' CacheSQL...
*
* @author Jonathan Levinson
*/
public class TestInterSystemsFunctionsClass {
private Long id;
private java.util.Date date3;
private java.util.Date date1;
private java.util.Date date;
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() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getDateText() {
return dateText;
}
public void setDateText(String dateText) {
this.dateText = dateText;
}
public Date getDate1() {
return date1;
}
public void setDate1(Date date1) {
this.date1 = date1;
}
public Date getDate3() {
return date3;
}
public void setDate3(Date date3) {
this.date3 = date3;
}
}

View File

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

View File

@ -22,13 +22,14 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.hql;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.hql.ast.HqlSqlWalker;

View File

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

View File

@ -1,14 +1,17 @@
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.Session;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.test.instrument.domain.Document;
import org.hibernate.test.instrument.domain.Folder;
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
*/

View File

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

View File

@ -36,10 +36,14 @@
<generator class="assigned"/>
</id>
<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">
<formula>(id)</formula>
</many-to-one>
<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)"/-->
</class>

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.legacy;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
@ -29,8 +30,8 @@ import java.util.Map;
import org.hibernate.Hibernate;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.HSQLDialect;
import org.junit.Test;
@ -218,7 +219,9 @@ public class ABCProxyTest extends LegacyTestCase {
(c1b.getCount()==23432) &&
c1b.getName().equals("c1")
);
System.out.println( s.delete("from A") );
for ( Object a : s.createQuery( "from A" ).list() ) {
s.delete( a );
}
t.commit();
s.close();
@ -228,7 +231,9 @@ public class ABCProxyTest extends LegacyTestCase {
s.save( new A() );
assertTrue( s.createQuery( "from B" ).list().size()==1 );
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();
s.close();
}
@ -279,7 +284,9 @@ public class ABCProxyTest extends LegacyTestCase {
s = openSession();
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 );
l = s.createQuery( "from E e join fetch e.reverse" ).list();
assertTrue( l.size()==2 );

View File

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

View File

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

View File

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

View File

@ -7,12 +7,18 @@ public class D {
private float amount;
private A reverse;
public A inverse;
public D() {
// try to induce an infinite loop in the lazy-loading machinery
setAmount(100.0f);
getAmount();
}
public D(Long id) {
this();
this.id = id;
}
/**
* Returns the amount.
* @return float

View File

@ -15,7 +15,7 @@ public class Fee implements Serializable {
public Fee() {
}
public Fee getFee() {
return fee;
}

View File

@ -5,7 +5,7 @@
<hibernate-mapping default-lazy="false">
<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">
<column name="string_" length="20"/>
</key-property>

View File

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

View File

@ -78,6 +78,10 @@ public class Foo implements Lifecycle, FooProxy, Serializable {
public Foo() {
}
public Foo(String key) {
this.key = key;
}
public Foo(int x) {
this.x=x;
}

View File

@ -23,7 +23,6 @@
*/
package org.hibernate.test.legacy;
import static org.hibernate.testing.TestLogger.LOG;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.Time;
@ -53,8 +52,8 @@ import org.hibernate.ObjectNotFoundException;
import org.hibernate.Query;
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
@ -85,6 +84,7 @@ import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.env.ConnectionProviderBuilder;
import static org.hibernate.testing.TestLogger.LOG;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@ -136,7 +136,7 @@ public class FooBarTest extends LegacyTestCase {
s = openSession();
s.beginTransaction();
Bar bar2 = (Bar) s.saveOrUpdateCopy(bar);
Bar bar2 = (Bar) s.merge( bar );
s.flush();
s.delete(bar2);
s.flush();
@ -783,7 +783,9 @@ public class FooBarTest extends LegacyTestCase {
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);
s.delete("from Holder");
for ( Object entity : s.createQuery( "from Holder" ).list() ) {
s.delete( entity );
}
txn.commit();
s.close();
@ -2678,8 +2680,8 @@ public class FooBarTest extends LegacyTestCase {
Session s = openSession();
s.beginTransaction();
Fee fee = new Fee();
s.save( fee, "key" );
fee.setFi("blah");
s.save( fee );
fee.setFi( "blah" );
s.getTransaction().commit();
s.close();
@ -2687,7 +2689,6 @@ public class FooBarTest extends LegacyTestCase {
s.beginTransaction();
fee = (Fee) s.load( Fee.class, fee.getKey() );
assertTrue( "blah".equals( fee.getFi() ) );
assertTrue( "key".equals( fee.getKey() ) );
s.delete(fee);
s.getTransaction().commit();
s.close();
@ -2717,14 +2718,14 @@ public class FooBarTest extends LegacyTestCase {
s = openSession();
s.beginTransaction();
foo = new Foo();
s.save(foo, "assignedid");
s.save(foo);
foo.setString("dirty");
s.getTransaction().commit();
s.close();
s = openSession();
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
assertTrue( "create-update", foo.equalsFoo(foo2) );
//System.out.println( s.print(foo2) );
@ -3474,7 +3475,12 @@ public class FooBarTest extends LegacyTestCase {
assertTrue( iter.last() );
assertTrue( iter.get(0)==f4 );
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();
assertTrue( s.createQuery( "from java.lang.Object" ).list().size()==0 );
txn.commit();
@ -3695,7 +3701,7 @@ public class FooBarTest extends LegacyTestCase {
s = openSession();
s.beginTransaction();
s.saveOrUpdate(fee2);
s.update( fee1, fee1.getKey() );
s.update( fee1 );
s.getTransaction().commit();
s.close();
@ -3799,7 +3805,7 @@ public class FooBarTest extends LegacyTestCase {
Session s = openSession();
Transaction txn = s.beginTransaction();
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);
foo.getComponent().setName( "IFA" );
txn.commit();
@ -4233,13 +4239,14 @@ public class FooBarTest extends LegacyTestCase {
Session s = openSession();
s.beginTransaction();
Vetoer v = new Vetoer();
s.save(v); Serializable id = s.save(v);
s.save(v);
s.save(v);
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
s.update( v, id );
s.update( v, id );
s.update( v );
s.update( v );
s.delete( v );
s.delete( v );
s.getTransaction().commit();
@ -4423,9 +4430,9 @@ public class FooBarTest extends LegacyTestCase {
err=true;
}
assertTrue(err);
Fo fo = Fo.newFo();
id = new FumTest().fumKey("abc"); //yuck!!
s.save(fo, id);
id = FumTest.fumKey( "abc" ); //yuck!!
Fo fo = Fo.newFo( (FumCompositeID) id );
s.save(fo);
s.flush();
s.delete(fo);
err=false;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
//$Id: SQLLoaderTest.java 11383 2007-04-02 15:34:02Z steve.ebersole@jboss.com $
package org.hibernate.test.legacy;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
@ -7,8 +8,9 @@ import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.PostgreSQLDialect;
@ -26,7 +28,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class SQLLoaderTest extends LegacyTestCase {
static int nextInt = 1;
static long nextLong = 1;
@ -48,10 +49,10 @@ public class SQLLoaderTest extends LegacyTestCase {
public void testTS() throws Exception {
Session session = openSession();
Transaction txn = session.beginTransaction();
Simple sim = new Simple();
Simple sim = new Simple( Long.valueOf(1) );
sim.setDate( new Date() );
session.save( sim, new Long(1) );
Query q = session.createSQLQuery("select {sim.*} from Simple {sim} where {sim}.date_ = ?", "sim", Simple.class);
session.save( sim );
Query q = session.createSQLQuery( "select {sim.*} from Simple {sim} where {sim}.date_ = ?" ).addEntity( "sim", Simple.class );
q.setTimestamp( 0, sim.getDate() );
assertTrue ( q.list().size()==1 );
session.delete(sim);
@ -62,18 +63,26 @@ public class SQLLoaderTest extends LegacyTestCase {
@Test
public void testFindBySQLStar() throws HibernateException, SQLException {
Session session = openSession();
session.delete("from Assignable");
session.delete("from Category");
session.delete("from Simple");
session.delete("from A");
for ( Object entity : session.createQuery( "from Assignable" ).list() ) {
session.delete( entity );
}
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();
s.setName(String.valueOf(nextLong++));
session.save(s);
Simple simple = new Simple();
Simple simple = new Simple( Long.valueOf(nextLong++) );
simple.init();
session.save(simple, new Long(nextLong++));
session.save( simple );
A a = new A();
session.save(a);
@ -82,9 +91,9 @@ public class SQLLoaderTest extends LegacyTestCase {
session.save(b);
session.flush();
session.createSQLQuery("select {category.*} from category {category}", "category", Category.class).list();
session.createSQLQuery("select {simple.*} from Simple {simple}", "simple", Simple.class).list();
session.createSQLQuery("select {a.*} from TA {a}", "a", A.class).list();
session.createSQLQuery( "select {category.*} from category {category}" ).addEntity( "category", Category.class ).list();
session.createSQLQuery( "select {simple.*} from Simple {simple}" ).addEntity( "simple", Simple.class ).list();
session.createSQLQuery( "select {a.*} from TA {a}" ).addEntity( "a", A.class ).list();
session.connection().commit();
session.close();
@ -92,51 +101,62 @@ public class SQLLoaderTest extends LegacyTestCase {
@Test
public void testFindBySQLProperties() throws HibernateException, SQLException {
Session session = openSession();
session.delete("from Category");
Session session = openSession();
for ( Object entity : session.createQuery( "from Category" ).list() ) {
session.delete( entity );
}
Category s = new Category();
s.setName(String.valueOf(nextLong++));
session.save(s);
Category s = new Category();
s.setName(String.valueOf(nextLong++));
session.save(s);
s = new Category();
s.setName("WannaBeFound");
session.flush();
s = new Category();
s.setName("WannaBeFound");
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.setParameter("name", s.getName());
query.setProperties(s);
//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);
String[] str = new String[] { "WannaBeFound", "NotThere" };
query.setParameterList("names", str);
query.uniqueResult();
query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in (:names)" )
.addEntity( "category", Category.class );
String[] str = new String[] { "WannaBeFound", "NotThere" };
query.setParameterList("names", str);
query.uniqueResult();
query = session.createSQLQuery("select {category.*} from category {category} where {category}.name in :names", "category", Category.class);
query.setParameterList("names", str);
query.uniqueResult();
query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in :names" )
.addEntity( "category", Category.class );
query.setParameterList("names", str);
query.uniqueResult();
query = session.createSQLQuery("select {category.*} from category {category} where {category}.name in (:names)", "category", Category.class);
str = new String[] { "WannaBeFound" };
query.setParameterList("names", str);
query.uniqueResult();
query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in (:names)" )
.addEntity( "category", Category.class );
str = new String[] { "WannaBeFound" };
query.setParameterList("names", str);
query.uniqueResult();
query = session.createSQLQuery("select {category.*} from category {category} where {category}.name in :names", "category", Category.class);
query.setParameterList("names", str);
query.uniqueResult();
query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in :names" )
.addEntity( "category", Category.class );
query.setParameterList("names", str);
query.uniqueResult();
session.connection().commit();
session.close();
session.connection().commit();
session.close();
}
@Test
public void testFindBySQLAssociatedObjects() throws HibernateException, SQLException {
Session s = openSession();
s.delete("from Assignable");
s.delete("from Category");
for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
Category c = new Category();
c.setName("NAME");
@ -152,7 +172,7 @@ public class SQLLoaderTest extends LegacyTestCase {
s.close();
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);
s.connection().commit();
s.close();
@ -181,8 +201,12 @@ public class SQLLoaderTest extends LegacyTestCase {
@SkipForDialect( MySQLDialect.class )
public void testPropertyResultSQL() throws HibernateException, SQLException {
Session s = openSession();
s.delete("from Assignable");
s.delete("from Category");
for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
Category c = new Category();
c.setName("NAME");
@ -214,8 +238,13 @@ public class SQLLoaderTest extends LegacyTestCase {
@Test
public void testFindBySQLMultipleObject() throws HibernateException, SQLException {
Session s = openSession();
s.delete("from Assignable");
s.delete("from Category");
for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
s.flush();
s.connection().commit();
s.close();
@ -251,7 +280,9 @@ public class SQLLoaderTest extends LegacyTestCase {
if ( getDialect() instanceof MySQLDialect ) return;
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.get(0) instanceof Object[]);
@ -262,8 +293,12 @@ public class SQLLoaderTest extends LegacyTestCase {
@Test
public void testFindBySQLParameters() throws HibernateException, SQLException {
Session s = openSession();
s.delete("from Assignable");
s.delete("from Category");
for ( Object entity : s.createQuery( "from Assignable" ).list() ) {
s.delete( entity );
}
for ( Object entity : s.createQuery( "from Category" ).list() ) {
s.delete( entity );
}
s.flush();
s.connection().commit();
s.close();
@ -307,17 +342,20 @@ public class SQLLoaderTest extends LegacyTestCase {
s.close();
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();
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(1, "Best");
list = unnamedParam.list();
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("secondCat", "Best");
list = namedParam.list();
@ -331,7 +369,9 @@ public class SQLLoaderTest extends LegacyTestCase {
@SkipForDialect( { HSQLDialect.class, PostgreSQLDialect.class } )
public void testEscapedJDBC() throws HibernateException, SQLException {
Session session = openSession();
session.delete("from A");
for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A();
savedA.setName("Max");
session.save(savedA);
@ -349,9 +389,12 @@ public class SQLLoaderTest extends LegacyTestCase {
if( getDialect() instanceof TimesTenDialect) {
// TimesTen does not permit general expressions (like UPPER) in the second part of a LIKE expression,
// 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);
} 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')}", "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'" )
.addEntity( "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();
@ -364,7 +407,9 @@ public class SQLLoaderTest extends LegacyTestCase {
@Test
public void testDoubleAliasing() throws HibernateException, SQLException {
Session session = openSession();
session.delete("from A");
for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A();
savedA.setName("Max");
session.save(savedA);
@ -378,10 +423,17 @@ public class SQLLoaderTest extends LegacyTestCase {
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} " +
", 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", new String[] {"a1", "a2" }, new Class[] {A.class, A.class});
String sql = "select a.identifier_column as {a1.id}, " +
" a.clazz_discriminata as {a1.class}, " +
" a.count_ as {a1.count}, " +
" 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();
assertNotNull(list);
@ -403,7 +455,7 @@ public class SQLLoaderTest extends LegacyTestCase {
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();
@ -411,7 +463,7 @@ public class SQLLoaderTest extends LegacyTestCase {
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");
list = query.list();
@ -419,7 +471,8 @@ public class SQLLoaderTest extends LegacyTestCase {
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");
list = query.list();
@ -427,7 +480,8 @@ public class SQLLoaderTest extends LegacyTestCase {
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");
list = query.list();
@ -474,8 +528,9 @@ public class SQLLoaderTest extends LegacyTestCase {
Session session = openSession();
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();
assertEquals(list.size(),1);
@ -521,7 +576,8 @@ public class SQLLoaderTest extends LegacyTestCase {
session.save(s);
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();
assertNotNull(list);
@ -546,7 +602,8 @@ public class SQLLoaderTest extends LegacyTestCase {
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();
assertNotNull(list);
@ -562,7 +619,9 @@ public class SQLLoaderTest extends LegacyTestCase {
@Test
public void testFindBySQLDiscriminatedSameSession() throws Exception {
Session session = openSession();
session.delete("from A");
for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A();
session.save(savedA);
@ -570,7 +629,8 @@ public class SQLLoaderTest extends LegacyTestCase {
session.save(savedB);
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();
assertNotNull(list);
@ -602,7 +662,9 @@ public class SQLLoaderTest extends LegacyTestCase {
@Test
public void testFindBySQLDiscriminatedDiffSession() throws Exception {
Session session = openSession();
session.delete("from A");
for ( Object entity : session.createQuery( "from A" ).list() ) {
session.delete( entity );
}
A savedA = new A();
session.save(savedA);
@ -615,7 +677,8 @@ public class SQLLoaderTest extends LegacyTestCase {
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();
assertNotNull(list);
@ -641,7 +704,8 @@ public class SQLLoaderTest extends LegacyTestCase {
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.
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(1, "games");

View File

@ -5,7 +5,7 @@
<hibernate-mapping default-lazy="false">
<class name="org.hibernate.test.legacy.Simple">
<id type="long" column="id_">
<id name="id" type="long" column="id_">
<generator class="assigned"/>
</id>
<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;
import java.io.Serializable;
/**
* @author Gavin King
*/
public class Simple implements Serializable {
private Long id;
private String name;
private String address;
private int count;
@ -12,6 +39,10 @@ public class Simple implements Serializable {
private Long parent;
public Simple(Long id) {
this.id = id;
}
public Simple(int c) {
count=c;
}
@ -24,6 +55,15 @@ public class Simple implements Serializable {
date=new java.sql.Date(666);
number=new Float(55.8);
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
* Gets the name
* @return Returns a String

View File

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

View File

@ -5,7 +5,7 @@
<hibernate-mapping default-lazy="false">
<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"/>
</id>
<property name="name"/>

View File

@ -6,14 +6,38 @@ import org.hibernate.Session;
import org.hibernate.classic.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 onUpdateCalled;
boolean onDeleteCalled;
private String name;
private String[] strings;
public boolean onSave(Session s) throws CallbackException {
boolean result = !onSaveCalled;
onSaveCalled = true;
@ -33,23 +57,6 @@ public class Vetoer implements Lifecycle {
}
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 abstract class AbstractRecursiveBidirectionalOneToManyTest extends BaseCo
}
@Override
public org.hibernate.classic.Session openSession() {
org.hibernate.classic.Session s = super.openSession();
public Session openSession() {
Session s = super.openSession();
s.setCacheMode( getSessionCacheMode() );
return s;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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