use of org.teiid.query.sql.symbol.Reference in project teiid by teiid.
the class TestCorrelatedReferenceCollectorVisitor method testDeepNesting.
@Test
public void testDeepNesting() throws Exception {
String sql = "select * from bqt1.smalla where exists (select intnum from bqt1.smalla x where smalla.intnum = x.intnum and exists (select intnum from bqt1.smalla where exists (select intnum from bqt1.smalla x where smalla.intnum = x.intnum)))";
Command command = TestResolver.helpResolve(sql, RealMetadataFactory.exampleBQTCached());
command = QueryRewriter.rewrite(command, RealMetadataFactory.exampleBQTCached(), null);
command = ((ExistsCriteria) ((Query) command).getCriteria()).getCommand();
LinkedList<Reference> correlatedReferences = new LinkedList<Reference>();
GroupSymbol gs = new GroupSymbol("bqt1.smalla");
ResolverUtil.resolveGroup(gs, RealMetadataFactory.exampleBQTCached());
CorrelatedReferenceCollectorVisitor.collectReferences(command, Arrays.asList(gs), correlatedReferences, RealMetadataFactory.exampleBQTCached());
assertEquals(1, correlatedReferences.size());
}
use of org.teiid.query.sql.symbol.Reference in project teiid by teiid.
the class ODataSQLBuilder method updateProperty.
public Update updateProperty(EdmProperty edmProperty, Property property, boolean prepared, boolean rawValue) throws TeiidException {
Update update = new Update();
update.setGroup(this.context.getGroupSymbol());
Column column = this.context.getColumnByName(edmProperty.getName());
ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
if (prepared) {
update.addChange(symbol, new Reference(0));
this.params.add(asParam(edmProperty, property.getValue(), rawValue));
} else {
update.addChange(symbol, new Constant(asParam(edmProperty, property.getValue()).getValue()));
}
update.setCriteria(this.context.getCriteria());
return update;
}
use of org.teiid.query.sql.symbol.Reference in project teiid by teiid.
the class ODataSQLBuilder method insert.
public Insert insert(EdmEntityType entityType, Entity entity, List<UriParameter> keys, boolean prepared) throws TeiidException {
Table entityTable = findTable(entityType.getName(), this.metadata);
DocumentNode resource = new DocumentNode(entityTable, new GroupSymbol(entityTable.getFullName()), entityType);
List<Reference> referenceValues = new ArrayList<Reference>();
List<Constant> constantValues = new ArrayList<Constant>();
Insert insert = new Insert();
insert.setGroup(resource.getGroupSymbol());
if (keys != null) {
for (UriParameter key : keys) {
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(key.getName());
Column column = entityTable.getColumnByName(edmProperty.getName());
Object propertyValue = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), key.getText());
Property existing = entity.getProperty(edmProperty.getName());
if (existing == null || (existing.getValue() == null && propertyValue != null) || (existing.getValue() != null && propertyValue == null) || (existing.getValue() != null && !existing.getValue().equals(propertyValue))) {
throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16048, edmProperty.getName()));
}
}
}
int i = 0;
for (Property prop : entity.getProperties()) {
EdmProperty edmProp = (EdmProperty) entityType.getProperty(prop.getName());
Column column = entityTable.getColumnByName(edmProp.getName());
insert.addVariable(new ElementSymbol(column.getName(), resource.getGroupSymbol()));
if (prepared) {
referenceValues.add(new Reference(i++));
this.params.add(asParam(edmProp, prop.getValue()));
} else {
constantValues.add(new Constant(asParam(edmProp, prop.getValue()).getValue()));
}
}
if (prepared) {
insert.setValues(referenceValues);
} else {
insert.setValues(constantValues);
}
return insert;
}
use of org.teiid.query.sql.symbol.Reference in project teiid by teiid.
the class ODataSQLBuilder method updateStreamProperty.
public Update updateStreamProperty(EdmProperty edmProperty, final InputStream content) throws TeiidException {
Update update = new Update();
update.setGroup(this.context.getGroupSymbol());
Column column = this.context.getColumnByName(edmProperty.getName());
ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
update.addChange(symbol, new Reference(0));
Class<?> lobType = DataTypeManager.getDataTypeClass(column.getRuntimeType());
int sqlType = JDBCSQLTypeInfo.getSQLType(column.getRuntimeType());
if (content == null) {
this.params.add(new SQLParameter(null, sqlType));
} else {
Object value = null;
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return content;
}
};
if (lobType.isAssignableFrom(SQLXML.class)) {
value = new SQLXMLImpl(isf);
} else if (lobType.isAssignableFrom(ClobType.class)) {
value = new ClobImpl(isf, -1);
} else if (lobType.isAssignableFrom(BlobType.class)) {
value = new BlobImpl(isf);
} else {
throw new TeiidException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16031, column.getName()));
}
this.params.add(new SQLParameter(value, sqlType));
}
update.setCriteria(this.context.getCriteria());
return update;
}
use of org.teiid.query.sql.symbol.Reference in project teiid by teiid.
the class ReferenceUpdateSQLBuilder method updateReference.
public Update updateReference(URI referenceId, boolean prepared, boolean delete) throws SQLException {
try {
if (referenceId != null) {
UriInfo uriInfo = ODataSQLBuilder.buildUriInfo(referenceId, this.baseURI, this.serviceMetadata, this.odata);
UriResourceEntitySet uriEnitytSet = (UriResourceEntitySet) uriInfo.asUriInfoResource().getUriResourceParts().get(0);
if (this.collection) {
this.updateTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
} else {
this.referenceTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
}
}
} catch (UriParserException e) {
throw new SQLException(e);
} catch (URISyntaxException e) {
throw new SQLException(e);
} catch (UriValidationException e) {
throw new SQLException(e);
}
try {
Update update = new Update();
update.setGroup(this.updateTable.getGroupSymbol());
List<String> columnNames = DocumentNode.getColumnNames(this.updateTable.getFk().getColumns());
for (int i = 0; i < columnNames.size(); i++) {
Column column = this.updateTable.getFk().getColumns().get(i);
String columnName = columnNames.get(i);
ElementSymbol symbol = new ElementSymbol(columnName, this.updateTable.getGroupSymbol());
EdmEntityType entityType = this.updateTable.getEdmEntityType();
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(columnName);
// reference table keys will be null for delete scenario
Object value = null;
if (!delete) {
UriParameter parameter = getParameter(this.updateTable.getFk().getReferenceColumns().get(i), this.referenceTable.getKeyPredicates());
value = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), parameter.getText());
}
if (prepared) {
update.addChange(symbol, new Reference(i++));
this.params.add(ODataSQLBuilder.asParam(edmProperty, value));
} else {
update.addChange(symbol, new Constant(ODataSQLBuilder.asParam(edmProperty, value).getValue()));
}
}
Criteria criteria = DocumentNode.buildEntityKeyCriteria(this.updateTable, null, this.metadata, this.odata, null, null);
update.setCriteria(criteria);
return update;
} catch (TeiidException e) {
throw new SQLException(e);
}
}
Aggregations