use of org.teiid.language.ColumnReference in project teiid by teiid.
the class JPQLUpdateExecution method handleInsert.
private Object handleInsert(Insert insert) throws TranslatorException {
try {
String entityClassName = insert.getTable().getMetadataObject().getProperty(JPAMetadataProcessor.ENTITYCLASS, false);
Object entity = ReflectionHelper.create(entityClassName, null, this.executionContext.getCommandContext().getVDBClassLoader());
List<ColumnReference> columns = insert.getColumns();
List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
if (columns.size() != values.size()) {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14007));
}
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i).getMetadataObject();
Object value = values.get(i);
// do not add the derived columns
String name = column.getProperty(JPAMetadataProcessor.KEY_ASSOSIATED_WITH_FOREIGN_TABLE, false);
if (name == null) {
if (value instanceof Literal) {
Literal literalValue = (Literal) value;
PropertiesUtils.setBeanProperty(entity, column.getName(), literalValue.getValue());
} else {
PropertiesUtils.setBeanProperty(entity, column.getName(), value);
}
}
}
return entity;
} catch (TeiidException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class CoherenceUpdateExecution method updateChildObject.
private void updateChildObject(Table t) throws TranslatorException {
List<ForeignKey> fks = t.getForeignKeys();
ForeignKey fk = fks.get(0);
Table parentTable = fk.getParent();
// the name of the method to obtain the collection is the nameInSource of the foreginKey
String parentToChildMethod = fk.getNameInSource();
if (parentToChildMethod == null) {
// $NON-NLS-1$
final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noNameInSourceForForeingKey", new Object[] { fk.getName() });
throw new TranslatorException(msg);
}
// there must only be 1 column in the primary key
String parentColName = visitor.getNameFromElement(fk.getPrimaryKey().getColumns().get(0));
List<SetClause> updateList = ((Update) command).getChanges();
Condition criteria = ((Update) command).getWhere();
ColumnReference leftElement;
Expression rightExpr;
String nameLeftElement;
Object valueRightExpr;
// API).
for (int i = 0; i < updateList.size(); i++) {
SetClause setClause = updateList.get(i);
// trust that connector API is right and left side
// will always be an IElement
leftElement = setClause.getSymbol();
// call utility method to get NameInSource/Name for element
nameLeftElement = visitor.getNameFromElement(leftElement.getMetadataObject());
// get right expression - if it is not a literal we
// can't handle that so throw an exception
rightExpr = setClause.getValue();
// if (!(rightExpr instanceof Literal)) {
// final String msg = CoherencePlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError",nameLeftElement); //$NON-NLS-1$
// throw new TranslatorException(msg);
// }
valueRightExpr = ((Literal) rightExpr).getValue();
// add in the modification as a replacement - meaning
// any existing value(s) for this attribute will
// be replaced by the new value. If the attribute
// didn't exist, it will automatically be created
// TODO - since null is a valid attribute
// value, we don't do any special handling of it right
// now. But maybe null should mean to delete an
// attribute?
}
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class ParmHolder method createObject.
public Object createObject(List<ColumnReference> columnList, List<Expression> valueList, CoherenceVisitor visitor, Table t) throws TranslatorException {
if (columnList.size() != valueList.size()) {
throw new TranslatorException("Error: columns.size and values.size are not the same.");
}
// create the new object that will either be added as a top level object or added to the parent container
String tableName = visitor.getNameFromTable(t);
Object newObject = createObjectFromMetadata(tableName);
for (int i = 0; i < columnList.size(); i++) {
final ColumnReference insertElement = columnList.get(i);
if (!insertElement.getMetadataObject().isUpdatable())
continue;
final String elementName = visitor.getNameFromElement(insertElement.getMetadataObject());
final Object value = valueList.get(i);
Object val;
if (value instanceof Literal) {
Literal literalValue = (Literal) value;
val = literalValue.getValue();
// .toString();
if (null != val && val instanceof String) {
// !val.isEmpty()) {
val = stripQutes((String) val);
}
} else {
val = value;
// .toString();
}
setValue(tableName, elementName, newObject, val, insertElement.getType());
}
return newObject;
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class TestOracleConvertModifier method testClobToString.
@Test
public void testClobToString() throws Exception {
assertTrue(TRANSLATOR.supportsConvert(TypeFacility.RUNTIME_CODES.CLOB, TypeFacility.RUNTIME_CODES.STRING));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest(new ColumnReference(null, "x", null, DataTypeManager.DefaultDataClasses.CLOB), "string", "DBMS_LOB.substr(x, 4000)");
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class TestExtractFunctionModifier method test11.
public void test11() throws Exception {
// $NON-NLS-1$
NamedTable group = LANG_FACTORY.createNamedTable("group", null, null);
// $NON-NLS-1$
ColumnReference elem = LANG_FACTORY.createColumnReference("col", group, null, TypeFacility.RUNTIME_TYPES.DATE);
// $NON-NLS-1$ //$NON-NLS-2$
helpTestMod(elem, "EXTRACT(DAY FROM group.col)", "dayofmonth");
}
Aggregations