use of org.teiid.metadata.FunctionMethod in project teiid by teiid.
the class NativeMetadataRepository method getMetadata.
private void getMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory) throws TranslatorException {
Object connection = null;
try {
connection = executionFactory.getConnection(connectionFactory, null);
} catch (Throwable e) {
// if security pass through is enabled the connection creation may fail at the startup
if (executionFactory.isSourceRequiredForMetadata()) {
throw new TranslatorException(QueryPlugin.Event.TEIID31178, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31178, factory.getName()));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception getting connection for metadata, but no connection is required");
}
Object unwrapped = null;
if (connection instanceof WrappedConnection) {
try {
unwrapped = ((WrappedConnection) connection).unwrap();
} catch (ResourceException e) {
if (executionFactory.isSourceRequiredForMetadata()) {
throw new TranslatorException(QueryPlugin.Event.TEIID30477, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, factory.getName()));
}
connection = null;
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Could not unwrap exception to get metadata, but no connection is required");
}
}
try {
executionFactory.getMetadata(factory, (unwrapped == null) ? connection : unwrapped);
} finally {
executionFactory.closeConnection(connection, connectionFactory);
}
if (PropertiesUtils.getBooleanProperty(factory.getModelProperties(), IMPORT_PUSHDOWN_FUNCTIONS, false)) {
// $NON-NLS-1$
List<FunctionMethod> functions = executionFactory.getPushDownFunctions();
// create a copy and add to the schema
if (!functions.isEmpty()) {
try {
AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(functions);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.getBuffer(), 0, baos.getCount()));
functions = (List<FunctionMethod>) ois.readObject();
for (FunctionMethod functionMethod : functions) {
factory.addFunction(functionMethod);
functionMethod.setProperty(FunctionMethod.SYSTEM_NAME, functionMethod.getName());
}
} catch (IOException e) {
throw new TeiidRuntimeException(e);
} catch (ClassNotFoundException e) {
throw new TeiidRuntimeException(e);
}
}
}
}
use of org.teiid.metadata.FunctionMethod in project teiid by teiid.
the class FunctionMetadataReader method parseScalarFunction.
private static FunctionMethod parseScalarFunction(XMLStreamReader reader) throws XMLStreamException {
FunctionMethod function = new FunctionMethod();
if (reader.getAttributeCount() > 0) {
for (int i = 0; i < reader.getAttributeCount(); i++) {
String attrName = reader.getAttributeLocalName(i);
String attrValue = reader.getAttributeValue(i);
if (Element.NAME.getLocalName().equals(attrName)) {
function.setName(attrValue);
} else if (Element.CATEGORY.getLocalName().equals(attrName)) {
function.setCategory(attrValue);
} else if (Element.INVOCATION_CLASS.getLocalName().equals(attrName)) {
function.setInvocationClass(attrValue);
// TODO: set class loader
// function.setClassloader();
} else if (Element.INVOCATION_METHOD.getLocalName().equals(attrName)) {
function.setInvocationMethod(attrValue);
} else if (Element.PUSHDOWN.getLocalName().equals(attrName)) {
function.setPushDown(attrValue);
} else if (Element.DETERMINISTIC.getLocalName().equals(attrName)) {
function.setDeterministicBoolean(Boolean.parseBoolean(attrValue));
}
}
}
LinkedList<FunctionParameter> inputs = new LinkedList<FunctionParameter>();
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
switch(Element.forName(reader.getLocalName())) {
case INPUT_PARAMTERS:
inputs.addLast(parseParameter(reader));
break;
case RETURN_PARAMETER:
function.setOutputParameter(parseParameter(reader));
break;
}
}
function.setInputParameters(inputs);
return function;
}
use of org.teiid.metadata.FunctionMethod in project teiid by teiid.
the class SystemSource method addConstantDateFunction.
/**
* Date functions a marked as command deterministic, since we prefer pre-evaluation rather than row-by-row
* evaluation.
*/
private void addConstantDateFunction(String name, String description, String methodName, String returnType, Determinism determinism) {
FunctionMethod method = new FunctionMethod(name, description, DATETIME, FUNCTION_CLASS, methodName, new FunctionParameter[] {}, // $NON-NLS-1$
new FunctionParameter("result", returnType, description));
method.setDeterminism(determinism);
functions.add(method);
}
use of org.teiid.metadata.FunctionMethod in project teiid by teiid.
the class SystemSource method addTimeFunction.
private void addTimeFunction(String name, String methodName, String timeDesc, String timestampDesc, String returnType) {
functions.add(new FunctionMethod(name, timeDesc, DATETIME, FUNCTION_CLASS, methodName, new FunctionParameter[] { // $NON-NLS-1$
new FunctionParameter("time", DataTypeManager.DefaultDataTypes.TIME, timeDesc) }, // $NON-NLS-1$
new FunctionParameter("result", returnType, timeDesc)));
functions.add(new FunctionMethod(name, timestampDesc, DATETIME, FUNCTION_CLASS, methodName, new FunctionParameter[] { // $NON-NLS-1$
new FunctionParameter("timestamp", DataTypeManager.DefaultDataTypes.TIMESTAMP, timestampDesc) }, // $NON-NLS-1$
new FunctionParameter("result", returnType, timestampDesc)));
}
use of org.teiid.metadata.FunctionMethod in project teiid by teiid.
the class SystemSource method addLocateFunction.
private void addLocateFunction() {
FunctionMethod func = new // $NON-NLS-1$ //$NON-NLS-2$
FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
SourceSystemFunctions.LOCATE, // $NON-NLS-1$ //$NON-NLS-2$
QueryPlugin.Util.getString("SystemSource.Locate_desc"), // $NON-NLS-1$ //$NON-NLS-2$
STRING, // $NON-NLS-1$ //$NON-NLS-2$
FUNCTION_CLASS, // $NON-NLS-1$ //$NON-NLS-2$
"locate", new FunctionParameter[] { // $NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("substring", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.Locate_arg1")), // $NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("string", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.Locate_arg2")), // $NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("index", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.Locate_arg3")) }, // $NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.Locate_result")));
func.setNullOnNull(false);
functions.add(func);
functions.add(new // $NON-NLS-1$ //$NON-NLS-2$
FunctionMethod(// $NON-NLS-1$ //$NON-NLS-2$
SourceSystemFunctions.LOCATE, // $NON-NLS-1$ //$NON-NLS-2$
QueryPlugin.Util.getString("SystemSource.Locate2_desc"), // $NON-NLS-1$ //$NON-NLS-2$
STRING, // $NON-NLS-1$ //$NON-NLS-2$
FUNCTION_CLASS, // $NON-NLS-1$ //$NON-NLS-2$
"locate", new FunctionParameter[] { // $NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("substring", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.Locate2_arg1")), // $NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("string", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.Locate2_arg2")) }, // $NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER, QueryPlugin.Util.getString("SystemSource.Locate2_result"))));
}
Aggregations