@Override protected SQLOperation toProtoSQL( SpatialOperator op ) throws UnmappableException, FilterEvaluationException { throw new UnmappableException( "Spatial operators are currently not mappable in h2." ); }
/** * Creates a new {@link TableAliasManager} instance. */ public TableAliasManager() { rootTableAlias = generateNew(); }
protected SQLExpression toProtoSQL( Expression expr, boolean assertNotMultiValued ) throws UnmappableException, FilterEvaluationException { SQLExpression sql = toProtoSQL( expr ); if ( assertNotMultiValued ) { assertNotMultiValued( sql ); } return sql; }
protected void getPSBody( AbstractWhereBuilder builder, StringBuilder getDatasetIDs ) { String rootTableAlias = builder.getAliasManager().getRootTableAlias(); getDatasetIDs.append( " FROM " ); getDatasetIDs.append( mainTable ); getDatasetIDs.append( " " ); getDatasetIDs.append( rootTableAlias ); for ( PropertyNameMapping mappedPropName : builder.getMappedPropertyNames() ) { for ( Join join : mappedPropName.getJoins() ) { getDatasetIDs.append( " LEFT OUTER JOIN " ); getDatasetIDs.append( join.getToTable() ); getDatasetIDs.append( ' ' ); getDatasetIDs.append( join.getToTableAlias() ); getDatasetIDs.append( " ON " ); getDatasetIDs.append( join.getSQLJoinCondition() ); } } if ( builder.getWhere() != null ) { getDatasetIDs.append( " WHERE " ); getDatasetIDs.append( builder.getWhere().getSQL() ); } }
throws FilterEvaluationException, UnmappableException { SQLExpression sql = null; PropertyNameMapping propMapping = mapper.getSpatialMapping( propName, aliasManager ); if ( propMapping != null ) { propNameMappingList.add( propMapping ); + ( (ConstantPropertyNameMapping) propMapping ).getValue(), pt ); PrimitiveParticleConverter converter = new DefaultPrimitiveConverter( pt, null, false ); sql = new SQLArgument( value, converter ); } else { sql = new SQLColumn( propMapping.getTableAlias(), propMapping.getColumn(), propMapping.getConverter() ); throw new UnmappableException( "Unable to map property '" + propName + "' to database column." );
throws UnmappableException, FilterEvaluationException { SQLExpression sql = null; PropertyNameMapping propMapping = mapper.getMapping( propName, aliasManager ); if ( propMapping != null ) { propNameMappingList.add( propMapping ); + ( (ConstantPropertyNameMapping) propMapping ).getValue(), pt ); PrimitiveParticleConverter converter = new DefaultPrimitiveConverter( pt, null, false ); sql = new SQLArgument( value, converter ); } else { sql = new SQLColumn( propMapping.getTableAlias(), propMapping.getColumn(), propMapping.getConverter() ); throw new UnmappableException( "Unable to map property '" + propName + "' to database column." );
protected StringBuilder getPreparedStatementDatasetIDs( AbstractWhereBuilder builder ) { StringBuilder getDatasetIDs = new StringBuilder( 300 ); String rootTableAlias = builder.getAliasManager().getRootTableAlias(); getDatasetIDs.append( "SELECT DISTINCT " ); getDatasetIDs.append( rootTableAlias ); getDatasetIDs.append( '.' ); getDatasetIDs.append( idColumn ); // for SELECT DISTINCT, all ORDER BY columns have to be SELECTed as well if ( builder.getOrderBy() != null ) { // hack to transform the ORDER BY column list in select list String orderColList = builder.getOrderBy().getSQL().toString(); int i = 1; while ( orderColList.contains( " ASC" ) || orderColList.contains( "DESC" ) ) { orderColList = orderColList.replaceFirst( " ASC| DESC", " AS crit" + ( i++ ) ); } getDatasetIDs.append( ',' ); getDatasetIDs.append( orderColList ); } return getDatasetIDs; }
public static String repairAliasesInWhereClause( AbstractWhereBuilder builder, List<Join> usedJoins, List<Join> redundantJoins ) { String whereClause = builder.getWhere().getSQL().toString(); for ( Join redundantJoin : redundantJoins ) { Join usedJoin = getEquivalentJoin( redundantJoin, usedJoins ); String usedAlias = usedJoin.getToTableAlias(); String redundantAlias = redundantJoin.getToTableAlias(); whereClause = whereClause.replace( redundantAlias, usedAlias ); } return whereClause; }
private void map( GeometryMapping mapping, List<MappableStep> remaining ) throws UnmappableException { GeometryMapping geomMapping = mapping; MappingExpression me = geomMapping.getMapping(); if ( !( me instanceof DBField ) ) { throw new UnmappableException( "Mappings to non-DBField geometries is currently not supported." ); } ParticleConverter<?> converter = null; if ( fs != null ) { converter = fs.getConverter( geomMapping ); } propMapping = new PropertyNameMapping( converter, joins, ( (DBField) me ).getColumn(), currentTableAlias ); }
/** * Ensures that the given {@link SQLExpression} is not an {@link SQLExpression} that is multi-valued. * * @param expr * SQL expression, must not be <code>null</code> * @throws UnmappableException */ protected void assertNotMultiValued( SQLExpression expr ) throws UnmappableException { if ( expr.isMultiValued() ) { String msg = "Cannot apply filter as it refers to a column that stores multiple values in concatenated form.'"; throw new UnmappableException( msg ); } } }
@Override public PropertyNameMapping getMapping( ValueReference propName, TableAliasManager aliasManager ) throws FilterEvaluationException, UnmappableException { GeometryStorageParams geometryParams = new GeometryStorageParams( blobMapping.getCRS(), undefinedSrid, CoordinateDimension.DIM_2 ); GeometryMapping bboxMapping = new GeometryMapping( null, false, new DBField( blobMapping.getBBoxColumn() ), GeometryType.GEOMETRY, geometryParams, null ); return new PropertyNameMapping( getGeometryConverter( bboxMapping ), null, blobMapping.getBBoxColumn(), aliasManager.getRootTableAlias() ); }
private void followJoins( List<TableJoin> joinedTables ) { if ( joinedTables != null ) { for ( TableJoin joinedTable : joinedTables ) { String fromTable = currentTable; String fromTableAlias = currentTableAlias; String toTable = joinedTable.getToTable().toString(); String toTableAlias = aliasManager.generateNew(); List<String> fromColumns = new ArrayList<String>( joinedTable.getFromColumns().size() ); for ( SQLIdentifier fromColumn : joinedTable.getFromColumns() ) { fromColumns.add( fromColumn.toString() ); } List<String> toColumns = new ArrayList<String>( joinedTable.getToColumns().size() ); for ( SQLIdentifier toColumn : joinedTable.getToColumns() ) { toColumns.add( toColumn.toString() ); } Join appliedJoin = new Join( fromTable, fromTableAlias, fromColumns, toTable, toTableAlias, toColumns ); joins.add( appliedJoin ); currentTable = toTable; currentTableAlias = toTableAlias; } } } }
private void map( PrimitiveMapping mapping, List<MappableStep> remaining ) throws UnmappableException { final PrimitiveMapping primMapping = mapping; final MappingExpression me = primMapping.getMapping(); ParticleConverter<?> converter = null; if ( fs != null ) { converter = fs.getConverter( primMapping ); } if ( !( me instanceof DBField ) ) { final String qualifiedExpr = me.toString().replace( "$0", currentTableAlias ); propMapping = new PropertyNameMapping( converter, joins, qualifiedExpr, null ); return; } propMapping = new PropertyNameMapping( converter, joins, ( (DBField) me ).getColumn(), currentTableAlias ); }
private String getTableAlias( List<Join> joins, AliasedRIMType type ) { if ( joins != null ) { return joins.get( joins.size() - 1 ).getToTableAlias(); } return getTableAlias( type ); }
private void inferType( SQLExpression expr1, SQLExpression expr2, SQLExpression expr3 ) { PrimitiveType pt1 = expr1.getPrimitiveType(); PrimitiveType pt2 = expr2.getPrimitiveType(); PrimitiveType pt3 = expr3.getPrimitiveType(); if ( pt1 != null ) { inferType( expr1, expr2 ); inferType( expr1, expr3 ); } else if ( pt2 != null ) { inferType( expr2, expr1 ); inferType( expr2, expr3 ); } else if ( pt3 != null ) { inferType( expr3, expr1 ); inferType( expr3, expr2 ); } }
@Override protected void primitiveMappingSnippet( StringBuffer sql, PrimitiveMapping mapping ) { MappingExpression me = mapping.getMapping(); if ( me instanceof DBField ) { DBField dbField = (DBField) me; sql.append( ",\n " ); sql.append( dbField.getColumn() ); sql.append( " " ); sql.append( getDBType( mapping.getType().getBaseType() ) ); } }
/** * Translates the given {@link Operator} into an {@link SQLExpression}. * * @param op * operator to be translated, must not be <code>null</code> * @return corresponding SQL expression, never <code>null</code> * @throws UnmappableException * if translation is not possible (usually due to unmappable property names) * @throws FilterEvaluationException * if the filter contains invalid {@link ValueReference}s */ protected SQLExpression toProtoSQL( Operator op ) throws UnmappableException, FilterEvaluationException { SQLExpression sql = null; switch ( op.getType() ) { case COMPARISON: { sql = toProtoSQL( (ComparisonOperator) op ); break; } case LOGICAL: { sql = toProtoSQL( (LogicalOperator) op ); break; } case SPATIAL: { sql = toProtoSQL( (SpatialOperator) op ); break; } } return sql; }
@Override protected void primitiveMappingSnippet( StringBuffer sql, PrimitiveMapping mapping ) { MappingExpression me = mapping.getMapping(); if ( me instanceof DBField ) { DBField dbField = (DBField) me; sql.append( ",\n " ); sql.append( dbField.getColumn() ); sql.append( " " ); sql.append( getDBType( mapping.getType().getBaseType() ) ); } }
protected boolean appendParamsFromFunction( Function function, List<SQLExpression> params ) throws UnmappableException, FilterEvaluationException { boolean isConstant = true; for ( Expression param : function.getParameters() ) { SQLExpression sqlParam = toProtoSQL( param ); if ( !( sqlParam instanceof SQLArgument ) ) { isConstant = false; } params.add( sqlParam ); } return isConstant; }
@Override protected void primitiveMappingSnippet( StringBuffer sql, PrimitiveMapping mapping ) { MappingExpression me = mapping.getMapping(); if ( me instanceof DBField ) { DBField dbField = (DBField) me; sql.append( ",\n " ); sql.append( dbField.getColumn() ); sql.append( " " ); sql.append( getDBType( mapping.getType().getBaseType() ) ); } }