Search in sources :

Example 36 with FunctionMethod

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);
            }
        }
    }
}
Also used : AccessibleByteArrayOutputStream(org.teiid.core.util.AccessibleByteArrayOutputStream) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) WrappedConnection(org.teiid.resource.spi.WrappedConnection) ObjectOutputStream(java.io.ObjectOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FunctionMethod(org.teiid.metadata.FunctionMethod) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) ObjectInputStream(java.io.ObjectInputStream)

Example 37 with FunctionMethod

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;
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) LinkedList(java.util.LinkedList) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 38 with FunctionMethod

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);
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 39 with FunctionMethod

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)));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Example 40 with FunctionMethod

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"))));
}
Also used : FunctionMethod(org.teiid.metadata.FunctionMethod) FunctionParameter(org.teiid.metadata.FunctionParameter)

Aggregations

FunctionMethod (org.teiid.metadata.FunctionMethod)63 FunctionParameter (org.teiid.metadata.FunctionParameter)31 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)9 Schema (org.teiid.metadata.Schema)6 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)6 IOException (java.io.IOException)5 MetadataStore (org.teiid.metadata.MetadataStore)5 List (java.util.List)4 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)4 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)3 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)3 AggregateAttributes (org.teiid.metadata.AggregateAttributes)3 Procedure (org.teiid.metadata.Procedure)3 UDFSource (org.teiid.query.function.UDFSource)3