Search in sources :

Example 16 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class BlobType method compareTo.

@Override
public int compareTo(BlobType o) {
    try {
        InputStream is1 = this.getBinaryStream();
        InputStream is2 = o.getBinaryStream();
        long len1 = this.length();
        long len2 = o.length();
        long n = Math.min(len1, len2);
        for (long i = 0; i < n; i++) {
            int b1 = is1.read();
            int b2 = is2.read();
            if (b1 != b2) {
                return b1 - b2;
            }
        }
        return Long.signum(len1 - len2);
    } catch (SQLException e) {
        throw new TeiidRuntimeException(CorePlugin.Event.TEIID10048, e);
    } catch (IOException e) {
        throw new TeiidRuntimeException(CorePlugin.Event.TEIID10049, e);
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException)

Example 17 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class ODataEntitySchemaBuilder method buildMetadata.

static EdmDataServices buildMetadata(Schema schema) {
    try {
        List<EdmSchema.Builder> edmSchemas = new ArrayList<EdmSchema.Builder>();
        buildEntityTypes(schema, edmSchemas, true);
        buildFunctionImports(schema, edmSchemas, true);
        buildAssosiationSets(schema, edmSchemas, true);
        return EdmDataServices.newBuilder().addSchemas(edmSchemas).build();
    } catch (Exception e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : Builder(org.odata4j.edm.EdmSchema.Builder) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 18 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TestOptimizer method getPlan.

public static ProcessorPlan getPlan(Command command, QueryMetadataInterface md, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, boolean shouldSucceed, CommandContext cc) {
    ProcessorPlan plan = null;
    if (analysisRecord == null) {
        analysisRecord = new AnalysisRecord(false, DEBUG);
    }
    Exception exception = null;
    try {
        // do planning
        plan = QueryOptimizer.optimizePlan(command, md, null, capFinder, analysisRecord, cc);
    } catch (QueryPlannerException e) {
        exception = e;
    } catch (TeiidComponentException e) {
        exception = e;
    } catch (Throwable e) {
        throw new TeiidRuntimeException(e);
    } finally {
        if (DEBUG) {
            System.out.println(analysisRecord.getDebugLog());
        }
    }
    if (!shouldSucceed) {
        // $NON-NLS-1$
        assertNotNull("Expected exception but did not get one.", exception);
        return null;
    }
    if (plan == null) {
        throw new TeiidRuntimeException(exception);
    }
    // $NON-NLS-1$
    assertNotNull("Output elements are null", plan.getOutputElements());
    // $NON-NLS-1$
    if (DEBUG)
        System.out.println("\n" + plan);
    return plan;
}
Also used : AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Example 19 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TestFunctionTree method testLoadErrors.

@Test
public void testLoadErrors() {
    FunctionMethod method = new FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "dummy", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    PushDown.CAN_PUSHDOWN, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    null, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "noMethod", new ArrayList<FunctionParameter>(0), new FunctionParameter("output", DataTypeManager.DefaultDataTypes.STRING), false, // $NON-NLS-1$
    Determinism.DETERMINISTIC);
    // allowed, since we're not validating the class
    new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method))));
    // should fail, no class
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
        assertEquals("TEIID31123 Could not load non-FOREIGN UDF \"dummy\", since both invocation class and invocation method are required.", e.getMessage());
    }
    method.setInvocationClass("nonexistantClass");
    // should fail, no class
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationClass(TestFunctionTree.class.getName());
    // should fail, no method
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("testLoadErrors");
    // should fail, not void
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("x");
    // should fail, not public
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("z");
    // should fail, not static
    try {
        new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
        fail();
    } catch (TeiidRuntimeException e) {
    }
    method.setInvocationMethod("y");
    // valid!
    new FunctionLibrary(RealMetadataFactory.SFM.getSystemFunctions(), new FunctionTree("foo", new UDFSource(Arrays.asList(method)), true));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) FunctionParameter(org.teiid.metadata.FunctionParameter) Test(org.junit.Test)

Example 20 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class PropertiesUtils method resolveNestedProperties.

/**
 * The specialty of nested properties is, in a given property file
 * there can be values with pattern like "${...}"
 * <code>
 *  key1=value1
 *  key2=${key1}/value2
 * </code>
 * where the value of the <code>key2</code> should resolve to <code>value1/value2</code>
 * also if the property in the pattern <code>${..}</code> is not found in the loaded
 * properties, an exception is thrown. Multiple nesting is OK, however recursive nested is not supported.
 * @param original - Original properties to be resolved
 * @return resolved properties object.
 * @since 4.4
 */
public static Properties resolveNestedProperties(Properties original) {
    for (Enumeration e = original.propertyNames(); e.hasMoreElements(); ) {
        String key = (String) e.nextElement();
        String value = original.getProperty(key);
        // no nesting allowed on these.
        if (value == null) {
            continue;
        }
        boolean matched = true;
        boolean modified = false;
        while (matched) {
            // now match the pattern, then extract and find the value
            // $NON-NLS-1$
            int start = value.indexOf("${");
            int end = start;
            if (start != -1) {
                end = value.indexOf('}', start);
            }
            matched = ((start != -1) && (end != -1));
            if (matched) {
                String nestedkey = value.substring(start + 2, end);
                String nestedvalue = original.getProperty(nestedkey);
                // for the nestedkey that doesnt contain ${..} in the value
                if (key.equals(nestedkey)) {
                    matched = false;
                } else {
                    // this will handle case where we did not resolve, mark it blank
                    if (nestedvalue == null) {
                        throw new TeiidRuntimeException(CorePlugin.Event.TEIID10042, CorePlugin.Util.gs(CorePlugin.Event.TEIID10042, nestedkey));
                    }
                    value = value.substring(0, start) + nestedvalue + value.substring(end + 1);
                    modified = true;
                }
            }
        }
        if (modified) {
            original.setProperty(key, value);
        }
    }
    return original;
}
Also used : Enumeration(java.util.Enumeration) 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