Java 类org.hibernate.engine.TypedValue 实例源码

项目:cacheonix-core    文件:InExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
    ArrayList list = new ArrayList();
    Type type = criteriaQuery.getTypeUsingProjection(criteria, propertyName);
    if ( type.isComponentType() ) {
        AbstractComponentType actype = (AbstractComponentType) type;
        Type[] types = actype.getSubtypes();
        for ( int i=0; i<types.length; i++ ) {
            for ( int j=0; j<values.length; j++ ) {
                Object subval = values[j]==null ? 
                    null : 
                    actype.getPropertyValues( values[j], EntityMode.POJO )[i];
                list.add( new TypedValue( types[i], subval, EntityMode.POJO ) );
            }
        }
    }
    else {
        for ( int j=0; j<values.length; j++ ) {
            list.add( new TypedValue( type, values[j], EntityMode.POJO ) );
        }
    }
    return (TypedValue[]) list.toArray( new TypedValue[ list.size() ] );
}
项目:cacheonix-core    文件:AbstractQueryImpl.java   
/**
 * Warning: adds new parameters to the argument by side-effect, as well as
 * mutating the query string!
 */
private String expandParameterList(String query, String name, TypedValue typedList, Map namedParamsCopy) {
    Collection vals = (Collection) typedList.getValue();
    Type type = typedList.getType();
    if ( vals.size() == 1 ) {
        // short-circuit for performance...
        namedParamsCopy.put( name, new TypedValue( type, vals.iterator().next(), session.getEntityMode() ) );
        return query;
    }

    StringBuffer list = new StringBuffer( 16 );
    Iterator iter = vals.iterator();
    int i = 0;
    boolean isJpaPositionalParam = parameterMetadata.getNamedParameterDescriptor( name ).isJpaStyle();
    while ( iter.hasNext() ) {
        String alias = ( isJpaPositionalParam ? 'x' + name : name ) + i++ + '_';
        namedParamsCopy.put( alias, new TypedValue( type, iter.next(), session.getEntityMode() ) );
        list.append( ParserHelper.HQL_VARIABLE_PREFIX ).append( alias );
        if ( iter.hasNext() ) {
            list.append( ", " );
        }
    }
    String paramPrefix = isJpaPositionalParam ? "?" : ParserHelper.HQL_VARIABLE_PREFIX;
    return StringHelper.replace( query, paramPrefix + name, list.toString(), true );
}
项目:Equella    文件:ConfigurationServiceImpl.java   
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException
{
    List<TypedValue> values = new ArrayList<TypedValue>();
    for( Criterion crit : criterion )
    {
        values.addAll(Arrays.asList(crit.getTypedValues(criteria, criteriaQuery)));
    }
    return values.toArray(new TypedValue[values.size()]);
}
项目:cacheonix-core    文件:Printer.java   
public String toString(Map namedTypedValues) throws HibernateException {
    Map result = new HashMap();
    Iterator iter = namedTypedValues.entrySet().iterator();
    while ( iter.hasNext() ) {
        Map.Entry me = (Map.Entry) iter.next();
        TypedValue tv = (TypedValue) me.getValue();
        result.put( me.getKey(), tv.getType().toLoggableString( tv.getValue(), factory ) );
    }
    return result.toString();
}
项目:cacheonix-core    文件:Example.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {

    EntityPersister meta = criteriaQuery.getFactory()
            .getEntityPersister( criteriaQuery.getEntityName(criteria) );
    String[] propertyNames = meta.getPropertyNames();
    Type[] propertyTypes = meta.getPropertyTypes();
     //TODO: get all properties, not just the fetched ones!
    Object[] values = meta.getPropertyValues( entity, getEntityMode(criteria, criteriaQuery) );
    List list = new ArrayList();
    for (int i=0; i<propertyNames.length; i++) {
        Object value = values[i];
        Type type = propertyTypes[i];
        String name = propertyNames[i];

        boolean isPropertyIncluded = i!=meta.getVersionProperty() &&
            isPropertyIncluded(value, name, type);

        if (isPropertyIncluded) {
            if ( propertyTypes[i].isComponentType() ) {
                addComponentTypedValues(name, value, (AbstractComponentType) type, list, criteria, criteriaQuery);
            }
            else {
                addPropertyTypedValue(value, type, list);
            }
        }
    }
    return (TypedValue[]) list.toArray(TYPED_VALUES);
}
项目:cacheonix-core    文件:Example.java   
protected void addPropertyTypedValue(Object value, Type type, List list) {
    if ( value!=null ) {
        if ( value instanceof String ) {
            String string = (String) value;
            if (isIgnoreCaseEnabled) string = string.toLowerCase();
            if (isLikeEnabled) string = matchMode.toMatchString(string);
            value = string;
        }
        list.add( new TypedValue(type, value, null) );
    }
}
项目:cacheonix-core    文件:BetweenExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
    return new TypedValue[] {
            criteriaQuery.getTypedValue(criteria, propertyName, lo),
            criteriaQuery.getTypedValue(criteria, propertyName, hi)
    };
}
项目:cacheonix-core    文件:SimpleSubqueryExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
    TypedValue[] superTv = super.getTypedValues(criteria, criteriaQuery);
    TypedValue[] result = new TypedValue[superTv.length+1];
    System.arraycopy(superTv, 0, result, 1, superTv.length);
    result[0] = new TypedValue( getTypes()[0], value, EntityMode.POJO );
    return result;
}
项目:cacheonix-core    文件:SubqueryExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
    Type[] types = params.getPositionalParameterTypes();
    Object[] values = params.getPositionalParameterValues();
    TypedValue[] tv = new TypedValue[types.length];
    for ( int i=0; i<types.length; i++ ) {
        tv[i] = new TypedValue( types[i], values[i], EntityMode.POJO );
    }
    return tv;
}
项目:cacheonix-core    文件:LogicalExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {

    TypedValue[] lhstv = lhs.getTypedValues(criteria, criteriaQuery);
    TypedValue[] rhstv = rhs.getTypedValues(criteria, criteriaQuery);
    TypedValue[] result = new TypedValue[ lhstv.length + rhstv.length ];
    System.arraycopy(lhstv, 0, result, 0, lhstv.length);
    System.arraycopy(rhstv, 0, result, lhstv.length, rhstv.length);
    return result;
}
项目:cacheonix-core    文件:LikeExpression.java   
public TypedValue[] getTypedValues(
        Criteria criteria,
        CriteriaQuery criteriaQuery) throws HibernateException {
    return new TypedValue[] {
            criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() )
    };
}
项目:cacheonix-core    文件:SQLCriterion.java   
protected SQLCriterion(String sql, Object[] values, Type[] types) {
    this.sql = sql;
    typedValues = new TypedValue[values.length];
    for ( int i=0; i<typedValues.length; i++ ) {
        typedValues[i] = new TypedValue( types[i], values[i], EntityMode.POJO );
    }
}
项目:cacheonix-core    文件:Junction.java   
public TypedValue[] getTypedValues(Criteria crit, CriteriaQuery criteriaQuery)
throws HibernateException {
    ArrayList typedValues = new ArrayList();
    Iterator iter = criteria.iterator();
    while ( iter.hasNext() ) {
        TypedValue[] subvalues = ( (Criterion) iter.next() ).getTypedValues(crit, criteriaQuery);
        for ( int i=0; i<subvalues.length; i++ ) {
            typedValues.add( subvalues[i] );
        }
    }
    return (TypedValue[]) typedValues.toArray( new TypedValue[ typedValues.size() ] );
}
项目:cacheonix-core    文件:CriteriaQueryTranslator.java   
public TypedValue getTypedIdentifierValue(Criteria subcriteria, Object value) {
    final Loadable loadable = ( Loadable ) getPropertyMapping( getEntityName( subcriteria ) );
    return new TypedValue(
            loadable.getIdentifierType(),
            value,
            EntityMode.POJO
    );
}
项目:cacheonix-core    文件:CriteriaQueryTranslator.java   
/**
 * Get the a typed value for the given property value.
 */
public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value)
        throws HibernateException {
    // Detect discriminator values...
    if ( value instanceof Class ) {
        Class entityClass = ( Class ) value;
        Queryable q = SessionFactoryHelper.findQueryableUsingImports( sessionFactory, entityClass.getName() );
        if ( q != null ) {
            Type type = q.getDiscriminatorType();
            String stringValue = q.getDiscriminatorSQLValue();
            // Convert the string value into the proper type.
            if ( type instanceof NullableType ) {
                NullableType nullableType = ( NullableType ) type;
                value = nullableType.fromStringValue( stringValue );
            }
            else {
                throw new QueryException( "Unsupported discriminator type " + type );
            }
            return new TypedValue(
                    type,
                    value,
                    EntityMode.POJO
            );
        }
    }
    // Otherwise, this is an ordinary value.
    return new TypedValue(
            getTypeUsingProjection( subcriteria, propertyName ),
            value,
            EntityMode.POJO
    );
}
项目:cacheonix-core    文件:Loader.java   
/**
 * 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 SessionImplementor session) throws SQLException, HibernateException {
    if ( namedParams != null ) {
        // assumes that types are all of span 1
        Iterator iter = namedParams.entrySet().iterator();
        int result = 0;
        while ( iter.hasNext() ) {
            Map.Entry e = ( Map.Entry ) iter.next();
            String name = ( String ) e.getKey();
            TypedValue typedval = ( TypedValue ) e.getValue();
            int[] locs = getNamedParameterLocs( name );
            for ( int i = 0; i < locs.length; i++ ) {
                if ( log.isDebugEnabled() ) {
                    log.debug(
                            "bindNamedParameters() " +
                            typedval.getValue() + " -> " + name +
                            " [" + ( locs[i] + startIndex ) + "]"
                        );
                }
                typedval.getType().nullSafeSet( statement, typedval.getValue(), locs[i] + startIndex, session );
            }
            result += locs.length;
        }
        return result;
    }
    else {
        return 0;
    }
}
项目:cacheonix-core    文件:NativeSQLQueryPlan.java   
/**
 * Bind named parameters to the <tt>PreparedStatement</tt>. This has an
 * empty implementation on this superclass and should be implemented by
 * subclasses (queries) which allow named parameters.
 */
private int bindNamedParameters(final PreparedStatement ps,
        final Map namedParams, final int start,
        final SessionImplementor session) throws SQLException,
        HibernateException {

    if ( namedParams != null ) {
        // assumes that types are all of span 1
        Iterator iter = namedParams.entrySet().iterator();
        int result = 0;
        while ( iter.hasNext() ) {
            Map.Entry e = (Map.Entry) iter.next();
            String name = (String) e.getKey();
            TypedValue typedval = (TypedValue) e.getValue();
            int[] locs = getNamedParameterLocs( name );
            for (int i = 0; i < locs.length; i++) {
                if ( log.isDebugEnabled() ) {
                    log.debug( "bindNamedParameters() "
                            + typedval.getValue() + " -> " + name + " ["
                            + (locs[i] + start ) + "]" );
                }
                typedval.getType().nullSafeSet( ps, typedval.getValue(),
                        locs[i] + start, session );
            }
            result += locs.length;
        }
        return result;
    }
    else {
        return 0;
    }
}
项目:cacheonix-core    文件:FilterKey.java   
public FilterKey(String name, Map params, Map types, EntityMode entityMode) {
    filterName = name;
    Iterator iter = params.entrySet().iterator();
    while ( iter.hasNext() ) {
        Map.Entry me = (Map.Entry) iter.next();
        Type type = (Type) types.get( me.getKey() );
        filterParameters.put( me.getKey(), new TypedValue( type, me.getValue(), entityMode ) );
    }
}
项目:cacheonix-core    文件:AbstractPersistentCollection.java   
/**
 * Given a collection of entity instances that used to
 * belong to the collection, and a collection of instances
 * that currently belong, return a collection of orphans
 */
protected static Collection getOrphans(
        Collection oldElements, 
        Collection currentElements, 
        String entityName, 
        SessionImplementor session)
throws HibernateException {

    // short-circuit(s)
    if ( currentElements.size()==0 ) return oldElements; // no new elements, the old list contains only Orphans
    if ( oldElements.size()==0) return oldElements; // no old elements, so no Orphans neither

    Type idType = session.getFactory().getEntityPersister(entityName).getIdentifierType();

    // create the collection holding the Orphans
    Collection res = new ArrayList();

    // collect EntityIdentifier(s) of the *current* elements - add them into a HashSet for fast access
    java.util.Set currentIds = new HashSet();
    for ( Iterator it=currentElements.iterator(); it.hasNext(); ) {
        Object current = it.next();
        if ( current!=null && ForeignKeys.isNotTransient(entityName, current, null, session) ) {
            Serializable currentId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, current, session);
            currentIds.add( new TypedValue( idType, currentId, session.getEntityMode() ) );
        }
    }

    // iterate over the *old* list
    for ( Iterator it=oldElements.iterator(); it.hasNext(); ) {
        Object old = it.next();
        Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, old, session);
        if ( !currentIds.contains( new TypedValue( idType, oldId, session.getEntityMode() ) ) ) {
            res.add(old);
        }
    }

    return res;
}
项目:cacheonix-core    文件:AbstractQueryImpl.java   
public Query setParameter(String name, Object val, Type type) {
    if ( !parameterMetadata.getNamedParameterNames().contains( name ) ) {
        throw new IllegalArgumentException("Parameter " + name + " does not exist as a named parameter in [" + getQueryString() + "]");
    }
    else {
         namedParameters.put( name, new TypedValue( type, val, session.getEntityMode() ) );
         return this;
    }
}
项目:cacheonix-core    文件:AbstractQueryImpl.java   
public Query setParameterList(String name, Collection vals, Type type) throws HibernateException {
    if ( !parameterMetadata.getNamedParameterNames().contains( name ) ) {
        throw new IllegalArgumentException("Parameter " + name + " does not exist as a named parameter in [" + getQueryString() + "]");
    }
    namedParameterLists.put( name, new TypedValue( type, vals, session.getEntityMode() ) );
    return this;
}
项目:cacheonix-core    文件:AbstractQueryImpl.java   
/**
 * Warning: adds new parameters to the argument by side-effect, as well as
 * mutating the query string!
 */
protected String expandParameterLists(Map namedParamsCopy) {
    String query = this.queryString;
    Iterator iter = namedParameterLists.entrySet().iterator();
    while ( iter.hasNext() ) {
        Map.Entry me = (Map.Entry) iter.next();
        query = expandParameterList( query, (String) me.getKey(), (TypedValue) me.getValue(), namedParamsCopy );
    }
    return query;
}
项目:cacheonix-core    文件:NotNullExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
    return NO_VALUES;
}
项目:cacheonix-core    文件:IdentifierEqExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
    return new TypedValue[] { criteriaQuery.getTypedIdentifierValue(criteria, value) };
}
项目:cacheonix-core    文件:NullExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
    return NO_VALUES;
}
项目:cacheonix-core    文件:AbstractEmptinessExpression.java   
public final TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
        throws HibernateException {
    return NO_VALUES;
}
项目:cacheonix-core    文件:IlikeExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
    return new TypedValue[] { criteriaQuery.getTypedValue( criteria, propertyName, value.toString().toLowerCase() ) };
}
项目:cacheonix-core    文件:SizeExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
    return new TypedValue[] { 
        new TypedValue( Hibernate.INTEGER, new Integer(size), EntityMode.POJO ) 
    };
}
项目:cacheonix-core    文件:NaturalIdentifier.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    return conjunction.getTypedValues(criteria, criteriaQuery);
}
项目:cacheonix-core    文件:SimpleExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
    Object icvalue = ignoreCase ? value.toString().toLowerCase() : value;
    return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, icvalue) };
}
项目:cacheonix-core    文件:PropertyExpression.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
    return NO_TYPED_VALUES;
}
项目:cacheonix-core    文件:NotExpression.java   
public TypedValue[] getTypedValues(
    Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
    return criterion.getTypedValues(criteria, criteriaQuery);
}
项目:cacheonix-core    文件:SQLCriterion.java   
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
    return typedValues;
}
项目:eurocarbdb    文件:SubstructureQueryCriterion.java   
/** Irrelevant; not used. */
public TypedValue[] getTypedValues( Criteria c, CriteriaQuery q )
{
    return new TypedValue[0];
}
项目:gisgraphy    文件:DistanceRestriction.java   
public TypedValue[] getTypedValues(Criteria criteria,
    CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] { criteriaQuery.getTypedValue(criteria,
    GisFeature.LOCATION_COLUMN_NAME, point) };

   }
项目:gisgraphy    文件:IntersectsRestriction.java   
public TypedValue[] getTypedValues(Criteria criteria,
    CriteriaQuery criteriaQuery) throws HibernateException {
return new TypedValue[] { criteriaQuery.getTypedValue(criteria,
    GisFeature.LOCATION_COLUMN_NAME, polygon) };

   }
项目:gisgraphy    文件:FulltextRestriction.java   
public TypedValue[] getTypedValues(Criteria criteria,
    CriteriaQuery criteriaQuery) throws HibernateException {
return  new TypedValue[] { new TypedValue( Hibernate.STRING, StringHelper.normalize(searchedText), EntityMode.POJO )};

   }
项目:gisgraphy    文件:PartialWordSearchRestriction.java   
public TypedValue[] getTypedValues(Criteria criteria,
    CriteriaQuery criteriaQuery) throws HibernateException {
return  new TypedValue[] { new TypedValue( Hibernate.STRING, StringHelper.transformStringForPartialWordSearch(searchedText,StringHelper.WHITESPACE_CHAR_DELIMITER), EntityMode.POJO )};

   }
项目:cacheonix-core    文件:NamedParameterSpecification.java   
/**
 * 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.
 */
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position)
        throws SQLException {
    TypedValue typedValue = ( TypedValue ) qp.getNamedParameters().get( name );
    typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
    return typedValue.getType().getColumnSpan( session.getFactory() );
}
项目:cacheonix-core    文件:Criterion.java   
/**
 * Return typed values for all parameters in the rendered SQL fragment
 * @param criteria TODO
 * @param criteriaQuery 
 * @return TypedValue[]
 * @throws HibernateException
 */
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException;