org.hibernate.engine.spi.TypedValue Java Examples

The following examples show how to use org.hibernate.engine.spi.TypedValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveSubselectOneToManyLoader.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected final CompletionStage<Void> reactiveLoadCollectionSubselect(
		final SharedSessionContractImplementor session,
		final Serializable[] ids,
		final Object[] parameterValues,
		final Type[] parameterTypes,
		final Map<String, TypedValue> namedParameters,
		final Type type) throws HibernateException {

	QueryParameters parameters = new QueryParameters(parameterTypes, parameterValues, namedParameters, ids);
	return doReactiveQueryAndInitializeNonLazyCollections( (SessionImplementor) session, parameters, true )
			.handle( (list, err) -> {
				CompletionStages.logSqlException( err,
						() -> "could not load collection by subselect: " +
								collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ),
						getSQLString()
				);
				return CompletionStages.returnNullorRethrow(err);
			} );
}
 
Example #2
Source File: Hibernate1.java    From ysoserial with MIT License 6 votes vote down vote up
static Object makeHibernate45Caller ( Object tpl, Object getters ) throws NoSuchMethodException, InstantiationException, IllegalAccessException,
        InvocationTargetException, NoSuchFieldException, Exception, ClassNotFoundException {
    PojoComponentTuplizer tup = Reflections.createWithoutConstructor(PojoComponentTuplizer.class);
    Reflections.getField(AbstractComponentTuplizer.class, "getters").set(tup, getters);

    ComponentType t = Reflections.createWithConstructor(ComponentType.class, AbstractType.class, new Class[0], new Object[0]);
    Reflections.setFieldValue(t, "componentTuplizer", tup);
    Reflections.setFieldValue(t, "propertySpan", 1);
    Reflections.setFieldValue(t, "propertyTypes", new Type[] {
        t
    });

    TypedValue v1 = new TypedValue(t, null);
    Reflections.setFieldValue(v1, "value", tpl);
    Reflections.setFieldValue(v1, "type", t);

    TypedValue v2 = new TypedValue(t, null);
    Reflections.setFieldValue(v2, "value", tpl);
    Reflections.setFieldValue(v2, "type", t);

    return Gadgets.makeMap(v1, v2);
}
 
Example #3
Source File: Example.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected void addComponentTypedValues(
		String path, 
		Object component, 
		CompositeType type,
		List<TypedValue> list,
		Criteria criteria, 
		CriteriaQuery criteriaQuery) {
	if ( component != null ) {
		final String[] propertyNames = type.getPropertyNames();
		final Type[] subtypes = type.getSubtypes();
		final Object[] values = type.getPropertyValues( component, getEntityMode( criteria, criteriaQuery ) );
		for ( int i=0; i<propertyNames.length; i++ ) {
			final Object value = values[i];
			final Type subtype = subtypes[i];
			final String subpath = StringHelper.qualify( path, propertyNames[i] );
			if ( isPropertyIncluded( value, subpath, subtype ) ) {
				if ( subtype.isComponentType() ) {
					addComponentTypedValues( subpath, value, (CompositeType) subtype, list, criteria, criteriaQuery );
				}
				else {
					addPropertyTypedValue( value, subtype, list );
				}
			}
		}
	}
}
 
Example #4
Source File: Hibernate1.java    From ysoserial-modified with MIT License 6 votes vote down vote up
static Object makeCaller ( Object tpl, Object getters ) throws NoSuchMethodException, InstantiationException, IllegalAccessException,
        InvocationTargetException, NoSuchFieldException, Exception, ClassNotFoundException {
    PojoComponentTuplizer tup = Reflections.createWithoutConstructor(PojoComponentTuplizer.class);
    Reflections.getField(AbstractComponentTuplizer.class, "getters").set(tup, getters);

    ComponentType t = Reflections.createWithConstructor(ComponentType.class, AbstractType.class, new Class[0], new Object[0]);
    Reflections.setFieldValue(t, "componentTuplizer", tup);
    Reflections.setFieldValue(t, "propertySpan", 1);
    Reflections.setFieldValue(t, "propertyTypes", new Type[] {
        t
    });

    TypedValue v1 = new TypedValue(t, null);
    Reflections.setFieldValue(v1, "value", tpl);
    Reflections.setFieldValue(v1, "type", t);

    TypedValue v2 = new TypedValue(t, null);
    Reflections.setFieldValue(v2, "value", tpl);
    Reflections.setFieldValue(v2, "type", t);

    return Gadgets.makeMap(v1, v2);
}
 
Example #5
Source File: Loader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called by subclasses that batch initialize collections
 */
protected final void loadCollectionSubselect(
		final SharedSessionContractImplementor session,
		final Serializable[] ids,
		final Object[] parameterValues,
		final Type[] parameterTypes,
		final Map<String, TypedValue> namedParameters,
		final Type type) throws HibernateException {
	final Type[] idTypes = new Type[ids.length];
	Arrays.fill( idTypes, type );
	try {
		doQueryAndInitializeNonLazyCollections(
				session,
				new QueryParameters( parameterTypes, parameterValues, namedParameters, ids ),
				true
		);
	}
	catch (SQLException sqle) {
		throw factory.getJdbcServices().getSqlExceptionHelper().convert(
				sqle,
				"could not load collection by subselect: " +
						MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ),
				getSQLString()
		);
	}
}
 
Example #6
Source File: SQLCriterion.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected SQLCriterion(String sql, Object[] values, Type[] types) {
	this.sql = sql;
	this.typedValues = new TypedValue[values.length];
	for ( int i=0; i<typedValues.length; i++ ) {
		typedValues[i] = new TypedValue( types[i], values[i] );
	}
}
 
Example #7
Source File: Example.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
	final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(
			criteriaQuery.getEntityName( criteria )
	);
	final String[] propertyNames = meta.getPropertyNames();
	final Type[] propertyTypes = meta.getPropertyTypes();

	final Object[] values = meta.getPropertyValues( exampleEntity );
	final List<TypedValue> list = new ArrayList<TypedValue>();
	for ( int i=0; i<propertyNames.length; i++ ) {
		final Object value = values[i];
		final Type type = propertyTypes[i];
		final String name = propertyNames[i];

		final boolean isVersionProperty = i == meta.getVersionProperty();

		if ( ! isVersionProperty && isPropertyIncluded( value, name, type ) ) {
			if ( propertyTypes[i].isComponentType() ) {
				addComponentTypedValues( name, value, (CompositeType) type, list, criteria, criteriaQuery );
			}
			else {
				addPropertyTypedValue( value, type, list );
			}
		}
	}

	return list.toArray( new TypedValue[ list.size() ] );
}
 
Example #8
Source File: Junction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria crit, CriteriaQuery criteriaQuery) throws HibernateException {
	final ArrayList<TypedValue> typedValues = new ArrayList<TypedValue>();
	for ( Criterion condition : conditions ) {
		final TypedValue[] subValues = condition.getTypedValues( crit, criteriaQuery );
		Collections.addAll( typedValues, subValues );
	}
	return typedValues.toArray( new TypedValue[ typedValues.size() ] );
}
 
Example #9
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the a typed value for the given property value.
 */
@Override
public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value) throws HibernateException {
	// Detect discriminator values...
	if ( value instanceof Class ) {
		final Class entityClass = (Class) value;
		final Queryable q = SessionFactoryHelper.findQueryableUsingImports( sessionFactory, entityClass.getName() );
		if ( q != null ) {
			final Type type = q.getDiscriminatorType();
			String stringValue = q.getDiscriminatorSQLValue();
			if ( stringValue != null
					&& stringValue.length() > 2
					&& stringValue.startsWith( "'" )
					&& stringValue.endsWith( "'" ) ) {
				// remove the single quotes
				stringValue = stringValue.substring( 1, stringValue.length() - 1 );
			}

			// Convert the string value into the proper type.
			if ( type instanceof StringRepresentableType ) {
				final StringRepresentableType nullableType = (StringRepresentableType) type;
				value = nullableType.fromStringValue( stringValue );
			}
			else {
				throw new QueryException( "Unsupported discriminator type " + type );
			}
			return new TypedValue( type, value );
		}
	}
	// Otherwise, this is an ordinary value.
	return new TypedValue( getTypeUsingProjection( subcriteria, propertyName ), value );
}
 
Example #10
Source File: NamedParamBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int bind(
		PreparedStatement statement,
		QueryParameters qp,
		SharedSessionContractImplementor session,
		int position) throws SQLException {
	final TypedValue typedValue = qp.getNamedParameters().get( name );
	typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
	return typedValue.getType().getColumnSpan( session.getFactory() );
}
 
Example #11
Source File: PositionalParamBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int bind(
		PreparedStatement statement,
		QueryParameters qp,
		SharedSessionContractImplementor session,
		int position) throws SQLException {
	final TypedValue typedValue = qp.getNamedParameters().get( Integer.toString( label ) );
	typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
	return typedValue.getType().getColumnSpan( session.getFactory() );
}
 
Example #12
Source File: Loader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Bind named parameters to the JDBC prepared statement.
 * <p/>
 * This is a generic implementation, the problem being that in the
 * general case we do not know enough information about the named
 * parameters to perform this in a complete manner here.  Thus this
 * is generally overridden on subclasses allowing named parameters to
 * apply the specific behavior.  The most usual limitation here is that
 * we need to assume the type span is always one...
 *
 * @param statement The JDBC prepared statement
 * @param namedParams A map of parameter names to values
 * @param startIndex The position from which to start binding parameter values.
 * @param session The originating session.
 *
 * @return The number of JDBC bind positions actually bound during this method execution.
 *
 * @throws SQLException Indicates problems performing the binding.
 * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
 */
protected int bindNamedParameters(
		final PreparedStatement statement,
		final Map<String, TypedValue> namedParams,
		final int startIndex,
		final SharedSessionContractImplementor session) throws SQLException, HibernateException {
	int result = 0;
	if ( CollectionHelper.isEmpty( namedParams ) ) {
		return result;
	}

	for ( String name : namedParams.keySet() ) {
		TypedValue typedValue = namedParams.get( name );
		int columnSpan = typedValue.getType().getColumnSpan( getFactory() );
		int[] locs = getNamedParameterLocs( name );
		for ( int loc : locs ) {
			if ( DEBUG_ENABLED ) {
				LOG.debugf(
						"bindNamedParameters() %s -> %s [%s]",
						typedValue.getValue(),
						name,
						loc + startIndex
				);
			}
			int start = loc * columnSpan + startIndex;
			typedValue.getType().nullSafeSet( statement, typedValue.getValue(), start, session );
		}
		result += locs.length;
	}
	return result;
}
 
Example #13
Source File: AbstractLoadPlanBasedLoader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Bind named parameters to the JDBC prepared statement.
 * <p/>
 * This is a generic implementation, the problem being that in the
 * general case we do not know enough information about the named
 * parameters to perform this in a complete manner here.  Thus this
 * is generally overridden on subclasses allowing named parameters to
 * apply the specific behavior.  The most usual limitation here is that
 * we need to assume the type span is always one...
 *
 * @param statement The JDBC prepared statement
 * @param namedParams A map of parameter names to values
 * @param startIndex The position from which to start binding parameter values.
 * @param session The originating session.
 * @return The number of JDBC bind positions actually bound during this method execution.
 * @throws SQLException Indicates problems performing the binding.
 * @throws org.hibernate.HibernateException Indicates problems delegating binding to the types.
 */
protected int bindNamedParameters(
		final PreparedStatement statement,
		final Map namedParams,
		final int startIndex,
		final SharedSessionContractImplementor session) throws SQLException, HibernateException {
	if ( namedParams != null ) {
		// assumes that types are all of span 1
		final Iterator itr = namedParams.entrySet().iterator();
		final boolean debugEnabled = log.isDebugEnabled();
		int result = 0;
		while ( itr.hasNext() ) {
			final Map.Entry e = (Map.Entry) itr.next();
			final String name = (String) e.getKey();
			final TypedValue typedval = (TypedValue) e.getValue();
			final int[] locs = getNamedParameterLocs( name );
			for ( int loc : locs ) {
				if ( debugEnabled ) {
					log.debugf(
							"bindNamedParameters() %s -> %s [%s]",
							typedval.getValue(),
							name,
							loc + startIndex
					);
				}
				typedval.getType().nullSafeSet( statement, typedval.getValue(), loc + startIndex, session );
			}
			result += locs.length;
		}
		return result;
	}
	else {
		return 0;
	}
}
 
Example #14
Source File: QueryParameterBindingsImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated (since 5.2) expect a different approach to org.hibernate.engine.spi.QueryParameters in 6.0
 */
@Deprecated
public Map<String, TypedValue> collectNamedParameterBindings() {
	final Map<String, TypedValue> collectedBindings = new HashMap<>();

	for ( Map.Entry<QueryParameter, QueryParameterBinding> entry : parameterBindingMap.entrySet() ) {
		final String key;
		if ( entry.getKey().getPosition() != null ) {
			key = Integer.toString( entry.getKey().getPosition() );
		}
		else {
			key = entry.getKey().getName();
		}

		Type bindType = entry.getValue().getBindType();
		if ( bindType == null ) {
			log.debugf( "Binding for parameter [%s] did not define type", key );
			bindType = SerializableType.INSTANCE;
		}

		collectedBindings.put(
				key,
				new TypedValue( bindType, entry.getValue().getBindValue() )
		);
	}

	return collectedBindings;
}
 
Example #15
Source File: ParameterBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static int bindNamedParameters(
		final PreparedStatement ps,
		final Map namedParams,
		final int start,
		final NamedParameterSource source,
		final SessionImplementor session) throws SQLException, HibernateException {
	if ( namedParams != null ) {
		final boolean debugEnabled = LOG.isDebugEnabled();
		// assumes that types are all of span 1
		final Iterator iter = namedParams.entrySet().iterator();
		int result = 0;
		while ( iter.hasNext() ) {
			final Map.Entry e = (Map.Entry) iter.next();
			final String name = (String) e.getKey();
			final TypedValue typedVal = (TypedValue) e.getValue();
			final int[] locations = source.getNamedParameterLocations( name );
			for ( int location : locations ) {
				if ( debugEnabled ) {
					LOG.debugf(
							"bindNamedParameters() %s -> %s [%s]",
							typedVal.getValue(),
							name,
							location + start
					);
				}
				typedVal.getType().nullSafeSet( ps, typedVal.getValue(), location + start, session );
			}
			result += locations.length;
		}
		return result;
	}
	return 0;
}
 
Example #16
Source File: NamedParameterSpecification.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Bind the appropriate value into the given statement at the specified position.
 *
 * @param statement The statement into which the value should be bound.
 * @param qp The defined values for the current query execution.
 * @param session The session against which the current execution is occuring.
 * @param position The position from which to start binding value(s).
 *
 * @return The number of sql bind positions "eaten" by this bind operation.
 */
@Override
public int bind(
		PreparedStatement statement,
		QueryParameters qp,
		SharedSessionContractImplementor session,
		int position) throws SQLException {
	TypedValue typedValue = qp.getNamedParameters().get( name );
	typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
	return typedValue.getType().getColumnSpan( session.getFactory() );
}
 
Example #17
Source File: EntityPrinter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String toString(Map<String, TypedValue> namedTypedValues) throws HibernateException {
	Map<String, String> result = new HashMap<String, String>();
	for ( Map.Entry<String, TypedValue> entry : namedTypedValues.entrySet() ) {
		result.put(
				entry.getKey(), entry.getValue().getType().toLoggableString(
						entry.getValue().getValue(),
						factory
				)
		);
	}
	return result.toString();
}
 
Example #18
Source File: FilterKey.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
FilterKey(String name, Map<String,?> params, Map<String,Type> types) {
	filterName = name;
	for ( Map.Entry<String, ?> paramEntry : params.entrySet() ) {
		final Type type = types.get( paramEntry.getKey() );
		filterParameters.put( paramEntry.getKey(), new TypedValue( type, paramEntry.getValue() ) );
	}
}
 
Example #19
Source File: NamedParameterInformationImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int bind(
		PreparedStatement statement,
		QueryParameters qp,
		SharedSessionContractImplementor session,
		int position) throws SQLException {
	final TypedValue typedValue = qp.getNamedParameters().get( name );
	typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
	return typedValue.getType().getColumnSpan( session.getFactory() );
}
 
Example #20
Source File: PositionalParameterInformationImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int bind(
		PreparedStatement statement,
		QueryParameters qp,
		SharedSessionContractImplementor session,
		int position) throws SQLException {
	final TypedValue typedValue = qp.getNamedParameters().get( Integer.toString( label ) );
	typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
	return typedValue.getType().getColumnSpan( session.getFactory() );
}
 
Example #21
Source File: Example.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void addPropertyTypedValue(Object value, Type type, List<TypedValue> list) {
	if ( value != null ) {
		if ( value instanceof String ) {
			String string = (String) value;
			if ( isIgnoreCaseEnabled ) {
				string = string.toLowerCase(Locale.ROOT);
			}
			if ( isLikeEnabled ) {
				string = matchMode.toMatchString( string );
			}
			value = string;
		}
		list.add( new TypedValue( type, value ) );
	}
}
 
Example #22
Source File: LogicalExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
	final TypedValue[] lhsTypedValues = lhs.getTypedValues( criteria, criteriaQuery );
	final TypedValue[] rhsTypedValues = rhs.getTypedValues( criteria, criteriaQuery );

	final TypedValue[] result = new TypedValue[ lhsTypedValues.length + rhsTypedValues.length ];
	System.arraycopy( lhsTypedValues, 0, result, 0, lhsTypedValues.length );
	System.arraycopy( rhsTypedValues, 0, result, lhsTypedValues.length, rhsTypedValues.length );
	return result;
}
 
Example #23
Source File: BetweenExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
	return new TypedValue[] {
			criteriaQuery.getTypedValue( criteria, propertyName, low),
			criteriaQuery.getTypedValue( criteria, propertyName, high)
	};
}
 
Example #24
Source File: SubqueryExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
	//the following two lines were added to ensure that this.params is not null, which
	//can happen with two-deep nested subqueries
	final SessionFactoryImplementor factory = criteriaQuery.getFactory();
	createAndSetInnerQuery( criteriaQuery, factory );

	final Type[] ppTypes = params.getPositionalParameterTypes();
	final Object[] ppValues = params.getPositionalParameterValues();
	final TypedValue[] tv = new TypedValue[ppTypes.length];
	for ( int i=0; i<ppTypes.length; i++ ) {
		tv[i] = new TypedValue( ppTypes[i], ppValues[i] );
	}
	return tv;
}
 
Example #25
Source File: SimpleSubqueryExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
	final TypedValue[] subQueryTypedValues = super.getTypedValues( criteria, criteriaQuery );
	final TypedValue[] result = new TypedValue[subQueryTypedValues.length+1];
	System.arraycopy( subQueryTypedValues, 0, result, 1, subQueryTypedValues.length );
	result[0] = new TypedValue( getTypes()[0], value );
	return result;
}
 
Example #26
Source File: IlikeExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
	return new TypedValue[] {
			criteriaQuery.getTypedValue(
					criteria,
					propertyName,
					value.toString().toLowerCase(Locale.ROOT)
			)
	};
}
 
Example #27
Source File: AbstractProducedQuery.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
protected Map<String, TypedValue> getNamedParameterMap() {
	return getQueryParameterBindings().collectNamedParameterBindings();
}
 
Example #28
Source File: RlikeExpression.java    From gorm-hibernate5 with Apache License 2.0 4 votes vote down vote up
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, value.toString()) };
}
 
Example #29
Source File: NotNullExpression.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
	return NO_VALUES;
}
 
Example #30
Source File: IdentifierEqExpression.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
	return new TypedValue[] { criteriaQuery.getTypedIdentifierValue( criteria, value ) };
}