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() ); } }
private static boolean joinsAreEqual( Join join, Join other ) { List<String> fromColumns = join.getFromColumns(); List<String> otherFromColumns = other.getFromColumns(); if ( fromColumns == null ) { if ( otherFromColumns != null ) } else if ( !fromColumns.equals( otherFromColumns ) ) return false; String fromTable = join.getFromTable(); String otherFromTable = other.getFromTable(); if ( fromTable == null ) { if ( otherFromTable != null ) } else if ( !fromTable.equals( otherFromTable ) ) return false; List<String> toColumns = join.getToColumns(); List<String> otherToColumns = other.getToColumns(); if ( toColumns == null ) { if ( otherToColumns != null ) } else if ( !toColumns.equals( otherToColumns ) ) return false; String toTable = join.getToTable(); String otherToTable = other.getToTable(); if ( toTable == null ) { if ( otherToTable != null )
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 String getTableAlias( List<Join> joins, AliasedRIMType type ) { if ( joins != null ) { return joins.get( joins.size() - 1 ).getToTableAlias(); } return getTableAlias( type ); }
private void map( FeatureMapping mapping, List<MappableStep> remaining ) throws UnmappableException { // followJoins( mapping.getJoinedTable() ); if ( remaining.size() < 2 ) { throw new UnmappableException( "Not enough steps." ); } MappableStep ftStep = remaining.get( 0 ); if ( !( ftStep instanceof ElementStep ) ) { throw new UnmappableException( "Must provide a feature type name." ); } QName ftName = ( (ElementStep) ftStep ).getNodeName(); FeatureTypeMapping ftMapping = schema.getFtMapping( ftName ); if ( ftMapping == null ) { throw new UnmappableException( "Feature type '" + ftName + " is not mapped to a table." ); } String fromTable = currentTable; String fromTableAlias = currentTableAlias; // TODO what do do with Href mappings here? Needs proper reference resolving code for mapping here... String fromColumn = mapping.getJoinedTable().get( 0 ).getFromColumns().get( 0 ).toString(); String toTable = ftMapping.getFtTable().toString(); String toTableAlias = aliasManager.generateNew(); String toColumn = ftMapping.getFidMapping().getColumn(); Join appliedJoin = new Join( fromTable, fromTableAlias, Collections.singletonList( fromColumn ), toTable, toTableAlias, Collections.singletonList( toColumn ) ); joins.add( appliedJoin ); currentTable = toTable; currentTableAlias = toTableAlias; map( ftMapping.getMappings(), remaining.subList( 1, remaining.size() ) ); }
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; }
for ( Join join : mappedPropName.getJoins() ) { sql.append( " LEFT OUTER JOIN " ); sql.append( join.getToTable() ); sql.append( ' ' ); sql.append( join.getToTableAlias() ); sql.append( " ON " ); sql.append( join.getSQLJoinCondition() );
String toTableAlias = aliasManager.generateNew(); String toColumn = fk_main; joins.add( new Join( fromTable, fromTableAlias, fromColumn, toTable, toTableAlias, toColumn ) ); tableAlias = toTableAlias;
sql.append( " FULL OUTER JOIN " ); sql.append( additionalJoin.getToTable() ); sql.append( ' ' ); sql.append( additionalJoin.getToTableAlias() ); sql.append( " ON " ); sql.append( additionalJoin.getSQLJoinCondition() ); first = false;
String toTable = SlotMapper.getTable( childType ).name(); String toAlias = "X" + aliasNo++; Join join = new Join( fromTable, fromAlias, "internalId", toTable, toAlias, "fk_registrypackage" ); joins = Collections.singletonList( join ); additionalJoins.add( join );
for ( Join join : mappedPropName.getJoins() ) { sql.append( " LEFT OUTER JOIN " ); sql.append( join.getToTable() ); sql.append( ' ' ); sql.append( join.getToTableAlias() ); sql.append( " ON " ); sql.append( join.getSQLJoinCondition() );
idSelect.append( " FULL OUTER JOIN " ); idSelect.append( additionalJoin.getToTable() ); idSelect.append( ' ' ); idSelect.append( additionalJoin.getToTableAlias() ); idSelect.append( " ON " ); idSelect.append( additionalJoin.getSQLJoinCondition() ); first = false;
for ( Join join : mappedPropName.getJoins() ) { sql.append( " LEFT OUTER JOIN " ); sql.append( join.getToTable() ); sql.append( ' ' ); sql.append( join.getToTableAlias() ); sql.append( " ON " ); sql.append( join.getSQLJoinCondition() );