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);
}
}
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);
}
}
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;
}
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));
}
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;
}
Aggregations