本文整理汇总了Java中javax.persistence.ParameterMode.REF_CURSOR属性的典型用法代码示例。如果您正苦于以下问题:Java ParameterMode.REF_CURSOR属性的具体用法?Java ParameterMode.REF_CURSOR怎么用?Java ParameterMode.REF_CURSOR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.persistence.ParameterMode
的用法示例。
在下文中一共展示了ParameterMode.REF_CURSOR属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AbstractParameterRegistrationImpl
private AbstractParameterRegistrationImpl(
ProcedureCallImpl procedureCall,
Integer position,
String name,
ParameterMode mode,
Class<T> type,
Type hibernateType) {
this.procedureCall = procedureCall;
this.position = position;
this.name = name;
this.mode = mode;
this.type = type;
if ( mode == ParameterMode.REF_CURSOR ) {
return;
}
setHibernateType( hibernateType );
}
示例2: extract
@Override
@SuppressWarnings("unchecked")
public T extract(CallableStatement statement) {
if ( mode == ParameterMode.IN ) {
throw new ParameterMisuseException( "IN parameter not valid for output extraction" );
}
else if ( mode == ParameterMode.REF_CURSOR ) {
throw new ParameterMisuseException( "REF_CURSOR parameters should be accessed via results" );
}
try {
if ( ProcedureParameterExtractionAware.class.isInstance( hibernateType ) ) {
return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( statement, startIndex, session() );
}
else {
return (T) statement.getObject( startIndex );
}
}
catch (SQLException e) {
throw procedureCall.getSession().getFactory().getSQLExceptionHelper().convert(
e,
"Unable to extract OUT/INOUT parameter value"
);
}
}
示例3: registerParameters
@Override
public void registerParameters(
String procedureName,
CallableStatement statement,
ParameterStrategy parameterStrategy,
List<ParameterRegistrationImplementor<?>> parameterRegistrations,
SessionImplementor session) {
// prepare parameters
int i = 1;
try {
for ( ParameterRegistrationImplementor parameter : parameterRegistrations ) {
if ( parameter.getMode() == ParameterMode.REF_CURSOR ) {
statement.registerOutParameter( i, Types.OTHER );
i++;
}
else {
parameter.prepare( statement, i );
i += parameter.getSqlTypes().length;
}
}
}
catch (SQLException e) {
throw session.getFactory().getSQLExceptionHelper().convert(
e,
"Error registering CallableStatement parameters",
procedureName
);
}
}
示例4: renderCallableStatement
@Override
public String renderCallableStatement(
String procedureName,
ParameterStrategy parameterStrategy,
List<ParameterRegistrationImplementor<?>> parameterRegistrations,
SessionImplementor session) {
final StringBuilder buffer = new StringBuilder().append( "{call " )
.append( procedureName )
.append( "(" );
String sep = "";
for ( ParameterRegistrationImplementor parameter : parameterRegistrations ) {
if ( parameter == null ) {
throw new QueryException( "Parameter registrations had gaps" );
}
if ( parameter.getMode() == ParameterMode.REF_CURSOR ) {
verifyRefCursorSupport( session.getFactory().getDialect() );
buffer.append( sep ).append( "?" );
sep = ",";
}
else {
for ( int i = 0; i < parameter.getSqlTypes().length; i++ ) {
buffer.append( sep ).append( "?" );
sep = ",";
}
}
}
return buffer.append( ")}" ).toString();
}
示例5: registerParameters
@Override
public void registerParameters(
String procedureName,
CallableStatement statement,
ParameterStrategy parameterStrategy,
List<ParameterRegistrationImplementor<?>> parameterRegistrations,
SessionImplementor session) {
// prepare parameters
int i = 1;
try {
for ( ParameterRegistrationImplementor parameter : parameterRegistrations ) {
parameter.prepare( statement, i );
if ( parameter.getMode() == ParameterMode.REF_CURSOR ) {
i++;
}
else {
i += parameter.getSqlTypes().length;
}
}
}
catch (SQLException e) {
throw session.getFactory().getSQLExceptionHelper().convert(
e,
"Error registering CallableStatement parameters",
procedureName
);
}
}
示例6: collectRefCursorParameters
/**
* Collects any parameter registrations which indicate a REF_CURSOR parameter type/mode.
*
* @return The collected REF_CURSOR type parameters.
*/
public ParameterRegistrationImplementor[] collectRefCursorParameters() {
final List<ParameterRegistrationImplementor> refCursorParams = new ArrayList<ParameterRegistrationImplementor>();
for ( ParameterRegistrationImplementor param : registeredParameters ) {
if ( param.getMode() == ParameterMode.REF_CURSOR ) {
refCursorParams.add( param );
}
}
return refCursorParams.toArray( new ParameterRegistrationImplementor[refCursorParams.size()] );
}
示例7: getSqlTypes
public int[] getSqlTypes() {
if ( mode == ParameterMode.REF_CURSOR ) {
// we could use the Types#REF_CURSOR added in Java 8, but that would require requiring Java 8...
throw new IllegalStateException( "REF_CURSOR parameters do not have a SQL/JDBC type" );
}
return sqlTypes;
}
示例8: renderCallableStatement
@Override
public String renderCallableStatement(
String procedureName,
ParameterStrategy parameterStrategy,
List<ParameterRegistrationImplementor<?>> parameterRegistrations,
SessionImplementor session) {
// if there are any parameters, see if the first is REF_CURSOR
final boolean firstParamIsRefCursor = ! parameterRegistrations.isEmpty()
&& parameterRegistrations.get( 0 ).getMode() == ParameterMode.REF_CURSOR;
if ( firstParamIsRefCursor ) {
// validate that the parameter strategy is positional (cannot mix, and REF_CURSOR is inherently positional)
if ( parameterStrategy == ParameterStrategy.NAMED ) {
throw new HibernateException( "Cannot mix named parameters and REF_CURSOR parameter on PostgreSQL" );
}
}
final StringBuilder buffer;
if ( firstParamIsRefCursor ) {
buffer = new StringBuilder().append( "{? = call " );
}
else {
buffer = new StringBuilder().append( "{call " );
}
buffer.append( procedureName ).append( "(" );
String sep = "";
// skip the first registration if it was a REF_CURSOR
final int startIndex = firstParamIsRefCursor ? 1 : 0;
for ( int i = startIndex; i < parameterRegistrations.size(); i++ ) {
final ParameterRegistrationImplementor parameter = parameterRegistrations.get( i );
// any additional REF_CURSOR parameter registrations are an error
if ( parameter.getMode() == ParameterMode.REF_CURSOR ) {
throw new HibernateException( "PostgreSQL supports only one REF_CURSOR parameter, but multiple were registered" );
}
for ( int ignored : parameter.getSqlTypes() ) {
buffer.append( sep ).append( "?" );
sep = ",";
}
}
return buffer.append( ")}" ).toString();
}
示例9: buildOutputs
private ProcedureOutputsImpl buildOutputs() {
// todo : going to need a very specialized Loader for this.
// or, might be a good time to look at splitting Loader up into:
// 1) building statement objects
// 2) executing statement objects
// 3) processing result sets
// for now assume there are no resultClasses nor mappings defined..
// TOTAL PROOF-OF-CONCEPT!!!!!!
// todo : how to identify calls which should be in the form `{? = call procName...}` ??? (note leading param marker)
// more than likely this will need to be a method on the native API. I can see this as a trigger to
// both: (1) add the `? = ` part and also (2) register a REFCURSOR parameter for DBs (Oracle, PGSQL) that
// need it.
final String call = session().getFactory().getDialect().getCallableStatementSupport().renderCallableStatement(
procedureName,
parameterStrategy,
registeredParameters,
session()
);
try {
final CallableStatement statement = (CallableStatement) getSession().getTransactionCoordinator()
.getJdbcCoordinator()
.getStatementPreparer()
.prepareStatement( call, true );
// prepare parameters
int i = 1;
for ( ParameterRegistrationImplementor parameter : registeredParameters ) {
parameter.prepare( statement, i );
if ( parameter.getMode() == ParameterMode.REF_CURSOR ) {
i++;
}
else {
i += parameter.getSqlTypes().length;
}
}
return new ProcedureOutputsImpl( this, statement );
}
catch (SQLException e) {
throw getSession().getFactory().getSQLExceptionHelper().convert(
e,
"Error preparing CallableStatement",
getProcedureName()
);
}
}