Permalink
Browse files

HHH-7914 - Improve new stored procedure call support

  • Loading branch information...
1 parent 0713cea commit 5de1677ce73b87024a3d93f62b92c55ab5774960 @sebersole sebersole committed Jan 11, 2013
Showing with 1,746 additions and 946 deletions.
  1. +7 −4 hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java
  2. +0 −198 hibernate-core/src/main/java/org/hibernate/StoredProcedureCall.java
  3. +8 −7 hibernate-core/src/main/java/org/hibernate/internal/AbstractSessionImpl.java
  4. +4 −5 hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java
  5. +0 −608 hibernate-core/src/main/java/org/hibernate/internal/StoredProcedureCallImpl.java
  6. +136 −0 hibernate-core/src/main/java/org/hibernate/procedure/Call.java
  7. +30 −0 hibernate-core/src/main/java/org/hibernate/procedure/InOutParameterRegistration.java
  8. +3 −4 ...src/main/java/org/hibernate/{StoredProcedureReturn.java → procedure/InParameterRegistration.java}
  9. +38 −0 hibernate-core/src/main/java/org/hibernate/procedure/NamedParametersNotSupportedException.java
  10. +3 −4 ...a/org/hibernate/{StoredProcedureUpdateCountReturn.java → procedure/OutParameterRegistration.java}
  11. +20 −5 hibernate-core/src/main/java/org/hibernate/{StoredProcedureOutputs.java → procedure/Outputs.java}
  12. +46 −0 hibernate-core/src/main/java/org/hibernate/procedure/ParameterBind.java
  13. +37 −0 hibernate-core/src/main/java/org/hibernate/procedure/ParameterMisuseException.java
  14. +100 −0 hibernate-core/src/main/java/org/hibernate/procedure/ParameterRegistration.java
  15. +2 −2 ...rc/main/java/org/hibernate/{StoredProcedureResultSetReturn.java → procedure/ResultSetReturn.java}
  16. +41 −0 hibernate-core/src/main/java/org/hibernate/procedure/Return.java
  17. +38 −0 hibernate-core/src/main/java/org/hibernate/procedure/UpdateCountReturn.java
  18. +267 −0 hibernate-core/src/main/java/org/hibernate/procedure/internal/AbstractParameterRegistrationImpl.java
  19. +389 −0 hibernate-core/src/main/java/org/hibernate/procedure/internal/CallImpl.java
  20. +39 −0 hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedParameterRegistration.java
  21. +27 −25 ...va/org/hibernate/{internal/StoredProcedureOutputsImpl.java → procedure/internal/OutputsImpl.java}
  22. +57 −0 hibernate-core/src/main/java/org/hibernate/procedure/internal/ParameterBindImpl.java
  23. +41 −0 hibernate-core/src/main/java/org/hibernate/procedure/internal/ParameterRegistrationImplementor.java
  24. +33 −0 hibernate-core/src/main/java/org/hibernate/procedure/internal/ParameterStrategy.java
  25. +39 −0 hibernate-core/src/main/java/org/hibernate/procedure/internal/PositionalParameterRegistration.java
  26. +37 −0 hibernate-core/src/main/java/org/hibernate/procedure/package-info.java
  27. +273 −54 hibernate-core/src/test/java/org/hibernate/test/sql/storedproc/StoredProcedureTest.java
  28. +28 −27 hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/StoredProcedureQueryImpl.java
  29. +3 −3 hibernate-entitymanager/src/main/java/org/hibernate/jpa/spi/AbstractEntityManagerImpl.java
@@ -25,6 +25,8 @@
import java.io.Serializable;
+import org.hibernate.procedure.Call;
+
/**
* Contract methods shared between {@link Session} and {@link StatelessSession}
*
@@ -91,17 +93,18 @@
*
* @return The representation of the procedure call.
*/
- public StoredProcedureCall createStoredProcedureCall(String procedureName);
+ public Call createStoredProcedureCall(String procedureName);
/**
- * Creates a call to a stored procedure with specific result set entity mappings
+ * Creates a call to a stored procedure with specific result set entity mappings. Each class named
+ * is considered a "root return".
*
* @param procedureName The name of the procedure.
* @param resultClasses The entity(s) to map the result on to.
*
* @return The representation of the procedure call.
*/
- public StoredProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses);
+ public Call createStoredProcedureCall(String procedureName, Class... resultClasses);
/**
* Creates a call to a stored procedure with specific result set entity mappings
@@ -111,7 +114,7 @@
*
* @return The representation of the procedure call.
*/
- public StoredProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings);
+ public Call createStoredProcedureCall(String procedureName, String... resultSetMappings);
/**
* Create {@link Criteria} instance for the given class (entity or subclasses/implementors)
@@ -1,198 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2012, 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;
-
-import javax.persistence.ParameterMode;
-import javax.persistence.TemporalType;
-import java.util.List;
-
-import org.hibernate.internal.StoredProcedureCallImpl;
-import org.hibernate.type.Type;
-
-/**
- * @author Steve Ebersole
- */
-public interface StoredProcedureCall extends BasicQueryContract, SynchronizeableQuery {
- @Override
- StoredProcedureCall addSynchronizedQuerySpace(String querySpace);
-
- @Override
- StoredProcedureCall addSynchronizedEntityName(String entityName) throws MappingException;
-
- @Override
- StoredProcedureCall addSynchronizedEntityClass(Class entityClass) throws MappingException;
-
- /**
- * Get the name of the stored procedure to be called.
- *
- * @return The procedure name.
- */
- public String getProcedureName();
-
-
- /**
- * Register a positional parameter.
- * All positional parameters must be registered.
- *
- * @param position parameter position
- * @param type type of the parameter
- * @param mode parameter mode
- *
- * @return the same query instance
- */
- StoredProcedureCall registerStoredProcedureParameter(
- int position,
- Class type,
- ParameterMode mode);
-
- /**
- * Register a named parameter.
- * When using parameter names, all parameters must be registered
- * in the order in which they occur in the parameter list of the
- * stored procedure.
- *
- * @param parameterName name of the parameter as registered or
- * <p/>
- * specified in metadata
- * @param type type of the parameter
- * @param mode parameter mode
- *
- * @return the same query instance
- */
- StoredProcedureCall registerStoredProcedureParameter(
- String parameterName,
- Class type,
- ParameterMode mode);
-
- /**
- * Retrieve all registered parameters.
- *
- * @return The (immutable) list of all registered parameters.
- */
- public List<StoredProcedureParameter> getRegisteredParameters();
-
- /**
- * Retrieve parameter registered by name.
- *
- * @param name The name under which the parameter of interest was registered.
- *
- * @return The registered parameter.
- */
- public StoredProcedureParameter getRegisteredParameter(String name);
- public StoredProcedureParameter getRegisteredParameter(int position);
-
- public StoredProcedureOutputs getOutputs();
-
- /**
- * Describes a parameter registered with the stored procedure. Parameters can be either named or positional
- * as the registration mechanism. Named and positional should not be mixed.
- */
- public static interface StoredProcedureParameter<T> {
- /**
- * The name under which this parameter was registered. Can be {@code null} which should indicate that
- * positional registration was used (and therefore {@link #getPosition()} should return non-null.
- *
- * @return The name;
- */
- public String getName();
-
- /**
- * The position at which this parameter was registered. Can be {@code null} which should indicate that
- * named registration was used (and therefore {@link #getName()} should return non-null.
- *
- * @return The name;
- */
- public Integer getPosition();
-
- /**
- * Obtain the Java type of parameter. This is used to guess the Hibernate type (unless {@link #setHibernateType}
- * is called explicitly).
- *
- * @return The parameter Java type.
- */
- public Class<T> getType();
-
- /**
- * Retrieves the parameter "mode" which describes how the parameter is defined in the actual database procedure
- * definition (is it an INPUT parameter? An OUTPUT parameter? etc).
- *
- * @return The parameter mode.
- */
- public ParameterMode getMode();
-
- /**
- * Set the Hibernate mapping type for this parameter.
- *
- * @param type The Hibernate mapping type.
- */
- public void setHibernateType(Type type);
-
- /**
- * Retrieve the binding associated with this parameter. The binding is only relevant for INPUT parameters. Can
- * return {@code null} if nothing has been bound yet. To bind a value to the parameter use one of the
- * {@link #bindValue} methods.
- *
- * @return The parameter binding
- */
- public StoredProcedureParameterBind getParameterBind();
-
- /**
- * Bind a value to the parameter. How this value is bound to the underlying JDBC CallableStatement is
- * totally dependent on the Hibernate type.
- *
- * @param value The value to bind.
- */
- public void bindValue(T value);
-
- /**
- * Bind a value to the parameter, using just a specified portion of the DATE/TIME value. It is illegal to call
- * this form if the parameter is not DATE/TIME type. The Hibernate type is circumvented in this case and
- * an appropriate "precision" Type is used instead.
- *
- * @param value The value to bind
- * @param explicitTemporalType An explicitly supplied TemporalType.
- */
- public void bindValue(T value, TemporalType explicitTemporalType);
- }
-
- /**
- * Describes an input value binding for any IN/INOUT parameters.
- */
- public static interface StoredProcedureParameterBind<T> {
- /**
- * Retrieves the bound value.
- *
- * @return The bound value.
- */
- public T getValue();
-
- /**
- * If {@code <T>} represents a DATE/TIME type value, JPA usually allows specifying the particular parts of
- * the DATE/TIME value to be bound. This value represents the particular part the user requested to be bound.
- *
- * @return The explicitly supplied TemporalType.
- */
- public TemporalType getExplicitTemporalType();
- }
-}
@@ -37,7 +37,7 @@
import org.hibernate.ScrollableResults;
import org.hibernate.SessionException;
import org.hibernate.SharedSessionContract;
-import org.hibernate.StoredProcedureCall;
+import org.hibernate.procedure.Call;
import org.hibernate.cache.spi.CacheKey;
import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
@@ -59,6 +59,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
+import org.hibernate.procedure.internal.CallImpl;
import org.hibernate.type.Type;
/**
@@ -240,27 +241,27 @@ public SQLQuery createSQLQuery(String sql) {
@Override
@SuppressWarnings("UnnecessaryLocalVariable")
- public StoredProcedureCall createStoredProcedureCall(String procedureName) {
+ public Call createStoredProcedureCall(String procedureName) {
errorIfClosed();
- final StoredProcedureCall call = new StoredProcedureCallImpl( this, procedureName );
+ final Call call = new CallImpl( this, procedureName );
// call.setComment( "Dynamic stored procedure call" );
return call;
}
@Override
@SuppressWarnings("UnnecessaryLocalVariable")
- public StoredProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
+ public Call createStoredProcedureCall(String procedureName, Class... resultClasses) {
errorIfClosed();
- final StoredProcedureCall call = new StoredProcedureCallImpl( this, procedureName, resultClasses );
+ final Call call = new CallImpl( this, procedureName, resultClasses );
// call.setComment( "Dynamic stored procedure call" );
return call;
}
@Override
@SuppressWarnings("UnnecessaryLocalVariable")
- public StoredProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
+ public Call createStoredProcedureCall(String procedureName, String... resultSetMappings) {
errorIfClosed();
- final StoredProcedureCall call = new StoredProcedureCallImpl( this, procedureName, resultSetMappings );
+ final Call call = new CallImpl( this, procedureName, resultSetMappings );
// call.setComment( "Dynamic stored procedure call" );
return call;
}
@@ -76,7 +76,7 @@
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionException;
-import org.hibernate.StoredProcedureCall;
+import org.hibernate.procedure.Call;
import org.hibernate.engine.spi.SessionOwner;
import org.hibernate.SharedSessionBuilder;
import org.hibernate.SimpleNaturalIdLoadAccess;
@@ -141,7 +141,6 @@
import org.hibernate.event.spi.SaveOrUpdateEvent;
import org.hibernate.event.spi.SaveOrUpdateEventListener;
import org.hibernate.internal.CriteriaImpl.CriterionEntry;
-import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.jdbc.ReturningWork;
import org.hibernate.jdbc.Work;
import org.hibernate.jdbc.WorkExecutor;
@@ -1743,21 +1742,21 @@ public SQLQuery createSQLQuery(String sql) {
}
@Override
- public StoredProcedureCall createStoredProcedureCall(String procedureName) {
+ public Call createStoredProcedureCall(String procedureName) {
errorIfClosed();
checkTransactionSynchStatus();
return super.createStoredProcedureCall( procedureName );
}
@Override
- public StoredProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
+ public Call createStoredProcedureCall(String procedureName, String... resultSetMappings) {
errorIfClosed();
checkTransactionSynchStatus();
return super.createStoredProcedureCall( procedureName, resultSetMappings );
}
@Override
- public StoredProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
+ public Call createStoredProcedureCall(String procedureName, Class... resultClasses) {
errorIfClosed();
checkTransactionSynchStatus();
return super.createStoredProcedureCall( procedureName, resultClasses );
Oops, something went wrong.

0 comments on commit 5de1677

Please sign in to comment.