use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class N1QLUpdateVisitor method appendClauses.
private void appendClauses(List<CBColumnData> rowCache, List<Condition> otherConditions, List<SetClause> setClauses) {
String useKey = this.getUsesKeyString(rowCache);
boolean isTyped = false;
if (useKey != null) {
buffer.append(SPACE).append(useKey);
}
if (setClauses != null) {
buffer.append(SPACE).append(SET).append(SPACE);
for (SetClause clause : setClauses) {
ColumnReference col = clause.getSymbol();
if (isPKColumn(col)) {
throw new TeiidRuntimeException(CouchbasePlugin.Event.TEIID29025, CouchbasePlugin.Util.gs(CouchbasePlugin.Event.TEIID29025, typedValue));
}
CBColumn column = formCBColumn(col);
CBColumnData cacheData = new CBColumnData(col.getType(), column);
Object value = clause.getValue();
if (clause.getValue() instanceof Literal) {
value = ((Literal) clause.getValue()).getValue();
}
if (typedName != null && typedName.equals(nameInSource(cacheData.getCBColumn().getLeafName())) && (value == null || !typedValue.equals(getValueString(cacheData.getColumnType(), value)))) {
throw new TeiidRuntimeException(CouchbasePlugin.Event.TEIID29022, CouchbasePlugin.Util.gs(CouchbasePlugin.Event.TEIID29022, typedValue));
}
}
append(setClauses);
}
boolean hasPredicate = false;
for (CBColumnData columnData : rowCache) {
if (typedName != null && typedName.equals(nameInSource(columnData.getCBColumn().getLeafName()))) {
if (typedValue.equals(getValueString(columnData.getColumnType(), columnData.getValue()))) {
isTyped = true;
}
// else no rows affected
}
if (columnData.getCBColumn().isPK()) {
continue;
}
if (!hasPredicate) {
buffer.append(SPACE).append(WHERE);
hasPredicate = true;
} else {
buffer.append(SPACE).append(AND);
}
buffer.append(SPACE).append(columnData.getCBColumn().getNameInSource()).append(SPACE);
buffer.append(Tokens.EQ).append(SPACE);
buffer.append(getValueString(columnData.getColumnType(), columnData.getValue()));
}
boolean hasTypedValue = !isTyped && typedName != null && typedValue != null;
if (!otherConditions.isEmpty()) {
if (!hasPredicate) {
buffer.append(SPACE).append(WHERE);
hasPredicate = true;
} else {
buffer.append(SPACE).append(AND);
}
buffer.append(SPACE);
if (hasTypedValue) {
buffer.append(LPAREN);
append(LanguageUtil.combineCriteria(otherConditions));
buffer.append(RPAREN);
} else {
append(LanguageUtil.combineCriteria(otherConditions));
}
}
if (hasTypedValue) {
if (hasPredicate) {
buffer.append(SPACE).append(AND);
} else {
buffer.append(SPACE).append(WHERE);
}
buffer.append(SPACE).append(keyspace).append(SOURCE_SEPARATOR).append(typedName).append(SPACE).append(EQ).append(SPACE).append(typedValue);
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class N1QLUpdateVisitor method visit.
@Override
public void visit(Update obj) {
visit(obj.getTable());
buffer.append(UPDATE).append(SPACE).append(this.keyspace);
Condition where = obj.getWhere();
List<CBColumnData> whereRowCache = new ArrayList<N1QLUpdateVisitor.CBColumnData>();
List<Condition> conditions = findEqualityPredicates(where, whereRowCache);
if (isArrayTable) {
if (whereRowCache.size() < (dimension + 1)) {
throw new TeiidRuntimeException(CouchbasePlugin.Event.TEIID29019, CouchbasePlugin.Util.gs(CouchbasePlugin.Event.TEIID29019, obj));
}
List<CBColumnData> rowCache = new ArrayList<N1QLUpdateVisitor.CBColumnData>();
for (SetClause clause : obj.getChanges()) {
ColumnReference col = clause.getSymbol();
if (isPKColumn(col)) {
throw new TeiidRuntimeException(CouchbasePlugin.Event.TEIID29025, CouchbasePlugin.Util.gs(CouchbasePlugin.Event.TEIID29025, typedValue));
}
CBColumn column = formCBColumn(col);
CBColumnData cacheData = new CBColumnData(col.getType(), column);
Object value = clause.getValue();
if (value instanceof Literal) {
value = ((Literal) value).getValue();
}
if (typedName != null && typedName.equals(nameInSource(cacheData.getCBColumn().getLeafName()))) {
if (!typedValue.equals(getValueString(cacheData.getColumnType(), value))) {
throw new TeiidRuntimeException(CouchbasePlugin.Event.TEIID29022, CouchbasePlugin.Util.gs(CouchbasePlugin.Event.TEIID29022, typedValue));
}
continue;
}
cacheData.setValue(value);
rowCache.add(cacheData);
}
List<CBColumnData> setList = new ArrayList<>(rowCache.size());
for (int i = 0; i < rowCache.size(); i++) {
if (rowCache.get(i).getCBColumn().isPK() || rowCache.get(i).getCBColumn().isIdx()) {
throw new TeiidRuntimeException(CouchbasePlugin.Event.TEIID29018, CouchbasePlugin.Util.gs(CouchbasePlugin.Event.TEIID29018, obj));
}
setList.add(rowCache.get(i));
}
buffer.append(SPACE);
appendDocumentID(obj, whereRowCache);
buffer.append(SPACE);
List<CBColumnData> idxList = new ArrayList<>(dimension);
List<CBColumnData> equalityWhereList = new ArrayList<>(whereRowCache.size());
for (CBColumnData columnData : whereRowCache) {
if (columnData.getCBColumn().isIdx()) {
idxList.add(columnData);
} else if (columnData.getCBColumn().isPK()) {
continue;
} else {
equalityWhereList.add(columnData);
}
}
this.setAttrArray = buildNestedArrayIdx(setAttr, dimension, idxList, obj) + LSBRACE + idxList.get(idxList.size() - 1).getValue() + RSBRACE;
buffer.append(SET);
boolean comma = false;
for (CBColumnData columnData : setList) {
if (comma) {
buffer.append(COMMA).append(SPACE);
} else {
buffer.append(SPACE);
comma = true;
}
String setRef = buildNestedAttrRef(setAttrArray, columnData.getCBColumn());
buffer.append(setRef).append(SPACE).append(EQ).append(SPACE).append(getValueString(columnData.getColumnType(), columnData.getValue()));
}
boolean hasPredicate = false;
for (CBColumnData columnData : equalityWhereList) {
if (!hasPredicate) {
buffer.append(SPACE).append(WHERE);
hasPredicate = true;
} else {
buffer.append(SPACE).append(AND);
}
String whereRef = buildNestedAttrRef(setAttrArray, columnData.getCBColumn());
buffer.append(SPACE).append(whereRef).append(SPACE).append(EQ).append(SPACE).append(getValueString(columnData.getColumnType(), columnData.getValue()));
}
for (Condition condition : conditions) {
if (!hasPredicate) {
buffer.append(SPACE).append(WHERE).append(SPACE);
hasPredicate = true;
} else {
buffer.append(SPACE).append(AND).append(SPACE);
}
append(condition);
}
} else {
appendClauses(whereRowCache, conditions, obj.getChanges());
}
appendRetuning();
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class AccumuloDataTypeManager method deserialize.
public static Object deserialize(final byte[] value, final Class<?> expectedType) {
if (value == null || Arrays.equals(value, EMPTY_BYTES)) {
return null;
}
try {
if (expectedType.isAssignableFrom(Clob.class)) {
return new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
}, -1);
} else if (expectedType.isAssignableFrom(Blob.class)) {
return new BlobType(new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
}));
} else if (expectedType.isAssignableFrom(SQLXML.class)) {
return new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return ObjectConverterUtil.convertToInputStream(value);
}
});
} else if (expectedType.isAssignableFrom(BinaryType.class)) {
return new BinaryType(value);
} else if (expectedType.isAssignableFrom(GeometryType.class)) {
GeometryType result = new GeometryType(Arrays.copyOf(value, value.length - 4));
int srid = (((value[value.length - 4] & 0xff) << 24) + ((value[value.length - 3] & 0xff) << 16) + ((value[value.length - 2] & 0xff) << 8) + ((value[value.length - 1] & 0xff) << 0));
result.setSrid(srid);
return result;
} else if (expectedType.isAssignableFrom(byte[].class)) {
return value;
} else if (expectedType.isAssignableFrom(String.class) || expectedType.isAssignableFrom(Boolean.class) || expectedType.isAssignableFrom(Boolean.class) || expectedType.isAssignableFrom(Byte.class) || expectedType.isAssignableFrom(Short.class) || expectedType.isAssignableFrom(Character.class) || expectedType.isAssignableFrom(Integer.class) || expectedType.isAssignableFrom(Long.class) || expectedType.isAssignableFrom(BigInteger.class) || expectedType.isAssignableFrom(BigDecimal.class) || expectedType.isAssignableFrom(Float.class) || expectedType.isAssignableFrom(Double.class) || expectedType.isAssignableFrom(Date.class) || expectedType.isAssignableFrom(Time.class) || expectedType.isAssignableFrom(Timestamp.class)) {
return DataTypeManager.transformValue(new String(value, UTF_8), expectedType);
} else {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(value));
Object obj = ois.readObject();
ois.close();
return obj;
}
} catch (ClassNotFoundException e) {
throw new TeiidRuntimeException(e);
} catch (IOException e) {
throw new TeiidRuntimeException(e);
} catch (TransformationException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class LocalClient method getVDBInternal.
private VDBMetaData getVDBInternal() throws SQLException, TeiidProcessingException {
if (this.vdb == null) {
LocalServerConnection lsc = (LocalServerConnection) getConnection().getServerConnection();
vdb = lsc.getWorkContext().getVDB();
if (vdb == null) {
throw new TeiidRuntimeException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16001, this.vdbName, this.vdbVersion));
}
this.vdb = vdb;
}
if (vdb.getStatus() != Status.ACTIVE) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID31099, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31099, vdb, vdb.getStatus()));
}
return this.vdb;
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(Literal expr) {
try {
Object value = null;
if (expr.getText() != null && !expr.getText().equalsIgnoreCase("null")) {
String type = expr.getType().getFullQualifiedName().getFullQualifiedNameAsString();
value = ODataTypeManager.parseLiteral(type, expr.getText());
}
if (this.prepared) {
if (value == null) {
this.stack.add(new Constant(value));
} else {
Function ref = new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { new Reference(this.params.size()), new Constant(DataTypeManager.getDataTypeName(value.getClass())) });
stack.add(ref);
this.params.add(new SQLParameter(value, JDBCSQLTypeInfo.getSQLTypeFromClass(value.getClass().getName())));
}
} else {
this.stack.add(new Constant(value));
}
} catch (TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
Aggregations