use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class CassandraSQLVisitor method visit.
@Override
public void visit(Literal obj) {
if (obj.getValue() == null) {
super.visit(obj);
return;
}
if (obj.getValue() instanceof Date) {
buffer.append(((Date) obj.getValue()).getTime());
return;
}
// cassandra directly parses uuids
if (obj.getValue() instanceof UUID) {
buffer.append(obj.getValue());
return;
}
// TODO: only supported with Cassandra 2 or later
/*if (obj.isBindEligible()
|| obj.getType() == TypeFacility.RUNTIME_TYPES.OBJECT
|| type == TypeFacility.RUNTIME_TYPES.VARBINARY) {
if (values == null) {
values = new ArrayList<Object>();
}
buffer.append('?');
if (type == TypeFacility.RUNTIME_TYPES.VARBINARY) {
values.add(ByteBuffer.wrap(((BinaryType)obj.getValue()).getBytesDirect()));
} else {
values.add(obj.getValue());
}
return;
}*/
Class<?> type = obj.getType();
if (type == TypeFacility.RUNTIME_TYPES.VARBINARY) {
// $NON-NLS-1$
buffer.append("0x").append(obj.getValue());
return;
}
if (type == TypeFacility.RUNTIME_TYPES.BLOB) {
// $NON-NLS-1$
buffer.append("0x");
Blob b = (Blob) obj.getValue();
InputStream binaryStream = null;
try {
if (b.length() > Integer.MAX_VALUE) {
// $NON-NLS-1$
throw new AssertionError("Blob is too large");
}
binaryStream = b.getBinaryStream();
PropertiesUtils.toHex(buffer, binaryStream);
} catch (SQLException e) {
throw new TeiidRuntimeException(e);
} catch (IOException e) {
throw new TeiidRuntimeException(e);
} finally {
if (binaryStream != null) {
try {
binaryStream.close();
} catch (IOException e) {
}
}
}
return;
}
if (!Number.class.isAssignableFrom(type) && type != TypeFacility.RUNTIME_TYPES.BOOLEAN && type != TypeFacility.RUNTIME_TYPES.VARBINARY) {
// just handle as strings things like timestamp
type = TypeFacility.RUNTIME_TYPES.STRING;
}
super.appendLiteral(obj, type);
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class VDBMetaData method clone.
@Override
public VDBMetaData clone() {
try {
VDBMetaData clone = (VDBMetaData) super.clone();
clone.models = new LinkedHashMap<String, ModelMetaData>(this.models);
clone.attachments = new CopyOnWriteLinkedHashMap<Class<?>, Object>();
clone.attachments.putAll(attachments);
clone.dataPolicies = new LinkedHashMap<String, DataPolicyMetadata>(dataPolicies);
clone.visibilityOverrides = new HashMap<String, Boolean>(visibilityOverrides);
return clone;
} catch (CloneNotSupportedException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class MetadataFactory method createFunctionFromMethod.
public static FunctionMethod createFunctionFromMethod(String name, Method method) {
Class<?> returnTypeClass = method.getReturnType();
AggregateAttributes aa = null;
// handle user defined aggregates
if ((method.getModifiers() & Modifier.STATIC) == 0 && UserDefinedAggregate.class.isAssignableFrom(method.getDeclaringClass())) {
aa = new AggregateAttributes();
Method m;
try {
// $NON-NLS-1$
m = method.getDeclaringClass().getMethod("getResult", CommandContext.class);
} catch (NoSuchMethodException e) {
throw new TeiidRuntimeException(e);
} catch (SecurityException e) {
throw new TeiidRuntimeException(e);
}
returnTypeClass = m.getReturnType();
}
if (returnTypeClass.isPrimitive()) {
returnTypeClass = TypeFacility.convertPrimitiveToObject(returnTypeClass);
}
String returnType = DataTypeManager.getDataTypeName(returnTypeClass);
Class<?>[] params = method.getParameterTypes();
String[] paramTypes = new String[params.length];
boolean nullOnNull = false;
for (int i = 0; i < params.length; i++) {
Class<?> clazz = params[i];
if (clazz.isPrimitive()) {
nullOnNull = true;
clazz = TypeFacility.convertPrimitiveToObject(clazz);
}
if (method.isVarArgs() && i == params.length - 1) {
paramTypes[i] = DataTypeManager.getDataTypeName(clazz.getComponentType());
} else {
paramTypes[i] = DataTypeManager.getDataTypeName(clazz);
}
}
if (params.length > 0 && CommandContext.class.isAssignableFrom(params[0])) {
paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length);
}
FunctionMethod func = FunctionMethod.createFunctionMethod(name, null, null, returnType, paramTypes);
func.setAggregateAttributes(aa);
func.setInvocationMethod(method.getName());
func.setPushdown(PushDown.CAN_PUSHDOWN);
func.setMethod(method);
func.setInvocationClass(method.getDeclaringClass().getName());
func.setNullOnNull(nullOnNull);
if (method.isVarArgs()) {
func.setVarArgs(method.isVarArgs());
}
return func;
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class FullyQualifiedName method append.
public FullyQualifiedName append(String name, String value) {
Assertion.isNotNull(name);
Assertion.isNotNull(value);
if (builder.length() > 0) {
builder.append(SEPARATOR);
}
try {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
builder.append(URLEncoder.encode(name, "UTF-8")).append("=").append(URLEncoder.encode(value, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new TeiidRuntimeException(e);
}
return this;
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class ArrayImpl method compareTo.
public int compareTo(ArrayImpl o, boolean noNulls, Comparator<Object> comparator) {
if (zeroBased != o.zeroBased) {
// $NON-NLS-1$
throw new TeiidRuntimeException("Incompatible types");
}
try {
checkValues();
o.checkValues();
} catch (SQLException e) {
throw new TeiidRuntimeException(e);
}
Object[] values2 = o.values;
return compare(noNulls, comparator, values, values2);
}
Aggregations