@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final String entityName =criteriaQuery.getEntityName( criteria, propertyName ); final String role = entityName + '.' + criteriaQuery.getPropertyName( propertyName ); final QueryableCollection cp = (QueryableCollection) criteriaQuery.getFactory().getCollectionPersister( role ); final String[] fk = cp.getKeyColumnNames(); final String[] pk = ( (Loadable) cp.getOwnerEntityPersister() ).getIdentifierColumnNames(); final ConditionFragment subQueryRestriction = new ConditionFragment() .setTableAlias( criteriaQuery.getSQLAlias( criteria, propertyName ) ) .setCondition( pk, fk ); return String.format( Locale.ROOT, "? %s (select count(*) from %s where %s)", op, cp.getTableName(), subQueryRestriction.toFragmentString() ); }
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { return new TypedValue[] { criteriaQuery.getTypedValue( criteria, propertyName, value ) }; }
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, propertyName ); final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName ); final SessionFactoryImplementor factory = criteriaQuery.getFactory(); final int[] sqlTypes = type.sqlTypes( factory );
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final SessionFactoryImplementor factory = criteriaQuery.getFactory(); final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName ); final Dialect dialect = factory.getDialect(); if ( dialect instanceof SpatialDialect ) { final SpatialDialect seDialect = (SpatialDialect) dialect; return seDialect.getSpatialFilterExpression( columns[0] ); } else { throw new IllegalStateException( "Dialect must be spatially enabled dialect" ); } }
@Override public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { return new Type[] { getFunction( criteriaQuery ).getReturnType( criteriaQuery.getType( criteria, getPropertyName() ), criteriaQuery.getFactory() ) }; }
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) { final Dialect dialect = criteriaQuery.getFactory().getDialect(); final String[] columns = criteriaQuery.findColumns( propertyName, criteria ); if ( columns.length != 1 ) { throw new HibernateException( "ilike may only be used with single-column properties" ); } if ( dialect instanceof PostgreSQLDialect || dialect instanceof PostgreSQL81Dialect) { return columns[0] + " ilike ?"; } else { return dialect.getLowercaseFunction() + '(' + columns[0] + ") like ?"; } }
private EntityMode getEntityMode(Criteria criteria, CriteriaQuery criteriaQuery) { final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister( criteriaQuery.getEntityName( criteria ) ); final EntityMode result = meta.getEntityMode(); if ( ! meta.getEntityMetamodel().getTuplizer().isInstance( exampleEntity ) ) { throw new ClassCastException( exampleEntity.getClass().getName() ); } return result; }
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final String[] columns = criteriaQuery.findColumns( propertyName, criteria ); final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName ); final StringBuilder fragment = new StringBuilder(); if ( columns.length > 1 ) { fragment.append( '(' ); } final SessionFactoryImplementor factory = criteriaQuery.getFactory(); final int[] sqlTypes = type.sqlTypes( factory ); for ( int i = 0; i < columns.length; i++ ) { final boolean lower = ignoreCase && (sqlTypes[i] == Types.VARCHAR || sqlTypes[i] == Types.CHAR || sqlTypes[i] == Types.NVARCHAR || sqlTypes[i] == Types.NCHAR); if ( lower ) { fragment.append( factory.getDialect().getLowercaseFunction() ).append( '(' ); } fragment.append( columns[i] ); if ( lower ) { fragment.append( ')' ); } fragment.append( getOp() ).append( "?" ); if ( i < columns.length - 1 ) { fragment.append( " and " ); } } if ( columns.length > 1 ) { fragment.append( ')' ); } return fragment.toString(); }
@Override public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final Type countFunctionReturnType = getFunction( criteriaQuery ).getReturnType( null, criteriaQuery.getFactory() ); return new Type[] { countFunctionReturnType }; }
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName ); final StringBuilder sql = new StringBuilder( "SDO_RELATE(" ); sql.append( columns[0] ).append( "," ).append( "?" ); if ( param != null && !param.isEmpty() ) { sql.append( "," ).append( param.toQuotedString() ); } sql.append( ") = 'TRUE'" ); return sql.toString(); } };
@Override public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) { final ArrayList<TypedValue> list = new ArrayList<TypedValue>(); final Type type = criteriaQuery.getTypeUsingProjection( criteria, propertyName ); if ( type.isComponentType() ) { final CompositeType compositeType = (CompositeType) type; final Type[] subTypes = compositeType.getSubtypes(); for ( Object value : values ) { for ( int i = 0; i < subTypes.length; i++ ) { final Object subValue = value == null ? null : compositeType.getPropertyValues( value, EntityMode.POJO )[i]; list.add( new TypedValue( subTypes[i], subValue ) ); } } } else { for ( Object value : values ) { list.add( criteriaQuery.getTypedValue( criteria, propertyName, value ) ); } } return list.toArray( new TypedValue[ list.size() ] ); }
@Override protected String toLeftSqlString(Criteria criteria, CriteriaQuery criteriaQuery) { return criteriaQuery.getColumn( criteria, propertyName ); }
public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { Dialect dialect = criteriaQuery.getFactory().getDialect(); SQLFunction function = (SQLFunction) dialect.getFunctions().get(this.aggregate); //TODO: throw an exception if function is not registered //create function argument array List functionArgs = new ArrayList(1); functionArgs.add(criteriaQuery.getColumn(criteria, propertyName)); return new StringBuffer() .append(function.render(functionArgs, criteriaQuery.getFactory())) .append(" as y").append(loc).append('_') .toString(); }
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { return new Type[] { criteriaQuery.getType( criteria, propertyName ) }; }
@Override public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) { return StringHelper.replace( sql, "{alias}", criteriaQuery.getSQLAlias( criteria ) ); }
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final String[] columns = criteriaQuery.findColumns( propertyName, criteria ); String result = String.join( " and ", StringHelper.suffix( columns, " is null" ) ); if ( columns.length > 1 ) { result = '(' + result + ')'; } return result; }
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() ] ); }
@Override public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { final String functionFragment = getFunction( criteriaQuery ).render( criteriaQuery.getType( criteria, getPropertyName() ), buildFunctionParameterList( criteria, criteriaQuery ), criteriaQuery.getFactory() ); return functionFragment + " as y" + loc + '_'; }
@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() ] ); }
@Override public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { final SessionFactoryImplementor factory = criteriaQuery.getFactory(); final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName ); final Dialect dialect = factory.getDialect(); if ( dialect instanceof SpatialDialect ) { final SpatialDialect seDialect = (SpatialDialect) dialect; return seDialect.getSpatialRelateSQL( columns[0], spatialRelation ); } else { throw new IllegalStateException( "Dialect must be spatially enabled dialect" ); } }