Search in sources :

Example 86 with TeiidRuntimeException

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);
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) UUID(java.util.UUID) Date(java.util.Date)

Example 87 with TeiidRuntimeException

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);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 88 with TeiidRuntimeException

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;
}
Also used : CommandContext(org.teiid.CommandContext) UserDefinedAggregate(org.teiid.UserDefinedAggregate) Method(java.lang.reflect.Method) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 89 with TeiidRuntimeException

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;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 90 with TeiidRuntimeException

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);
}
Also used : SQLException(java.sql.SQLException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4