Search in sources :

Example 21 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestProcedure method testProcedure1.

public void testProcedure1() throws Exception {
    // $NON-NLS-1$
    Procedure proc = getProcedure("ConnectorMetadata.TestProc1", 2, CONNECTOR_METADATA_UTILITY);
    // $NON-NLS-1$
    assertEquals("Procedure name in source", proc.getNameInSource());
    // $NON-NLS-1$
    String[] nameInSource = new String[] { "Param name in source", null, null, null };
    ProcedureParameter.Type[] direction = new ProcedureParameter.Type[] { ProcedureParameter.Type.In, ProcedureParameter.Type.Out, ProcedureParameter.Type.InOut, ProcedureParameter.Type.ReturnValue };
    int[] index = new int[] { 1, 2, 3, 4 };
    Class<?>[] type = new Class[] { Integer.class, Long.class, Short.class, java.sql.Date.class };
    checkParams(proc, nameInSource, direction, index, type);
}
Also used : Procedure(org.teiid.metadata.Procedure)

Example 22 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class DefaultAuthorizationValidator method isAccessible.

@Override
public boolean isAccessible(AbstractMetadataRecord record, CommandContext commandContext) {
    if (policyDecider == null || !policyDecider.validateCommand(commandContext) || // TODO - schemas cannot be hidden - unless we traverse them and find that nothing is accessible
    record instanceof Schema) {
        return true;
    }
    AbstractMetadataRecord parent = record;
    while (parent.getParent() != null) {
        parent = parent.getParent();
        if (parent instanceof Procedure) {
            // don't check procedure params/rs columns
            return true;
        }
    }
    if (!(parent instanceof Schema) || (CoreConstants.SYSTEM_MODEL.equalsIgnoreCase(parent.getName()) || CoreConstants.ODBC_MODEL.equalsIgnoreCase(parent.getName()))) {
        // access is always allowed to system tables / procedures or unrooted objects
        return true;
    }
    PermissionType action = PermissionType.READ;
    if (record instanceof FunctionMethod || record instanceof Procedure) {
        action = PermissionType.EXECUTE;
    }
    // cache permission check
    Boolean result = commandContext.isAccessible(record);
    if (result != null) {
        return result;
    }
    HashSet<String> resources = new HashSet<String>(2);
    resources.add(record.getFullName());
    result = this.policyDecider.getInaccessibleResources(action, resources, Context.METADATA, commandContext).isEmpty();
    commandContext.setAccessible(record, result);
    return result;
}
Also used : PermissionType(org.teiid.adminapi.DataPolicy.PermissionType) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) FunctionMethod(org.teiid.metadata.FunctionMethod) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) HashSet(java.util.HashSet)

Example 23 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class LanguageBridgeFactory method translate.

/* Execute */
Call translate(StoredProcedure sp) {
    Procedure proc = null;
    if (sp.getProcedureID() != null) {
        try {
            proc = this.metadataFactory.getProcedure(sp.getGroup().getName());
        } catch (TranslatorException e) {
            throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30486, e);
        }
    }
    Class<?> returnType = null;
    List<Argument> translatedParameters = new ArrayList<Argument>();
    for (SPParameter param : sp.getParameters()) {
        Direction direction = Direction.IN;
        switch(param.getParameterType()) {
            case ParameterInfo.IN:
                direction = Direction.IN;
                break;
            case ParameterInfo.INOUT:
                direction = Direction.INOUT;
                break;
            case ParameterInfo.OUT:
                direction = Direction.OUT;
                break;
            case ParameterInfo.RESULT_SET:
                // already part of the metadata
                continue;
            case ParameterInfo.RETURN_VALUE:
                returnType = param.getClassType();
                continue;
        }
        if (param.isUsingDefault() && BaseColumn.OMIT_DEFAULT.equalsIgnoreCase(metadataFactory.getMetadata().getExtensionProperty(param.getMetadataID(), BaseColumn.DEFAULT_HANDLING, false))) {
            continue;
        }
        ProcedureParameter metadataParam = metadataFactory.getParameter(param);
        // we can assume for now that all arguments will be literals, which may be multivalued
        org.teiid.language.Expression value = null;
        if (direction != Direction.OUT) {
            if (param.isVarArg()) {
                ArrayImpl av = (ArrayImpl) ((Constant) param.getExpression()).getValue();
                if (av != null) {
                    for (Object obj : av.getValues()) {
                        Argument arg = new Argument(direction, new Literal(obj, param.getClassType().getComponentType()), param.getClassType().getComponentType(), metadataParam);
                        translatedParameters.add(arg);
                    }
                }
                break;
            }
            value = translate(param.getExpression());
        }
        Argument arg = new Argument(direction, value, param.getClassType(), metadataParam);
        translatedParameters.add(arg);
    }
    Call call = new Call(removeSchemaName(sp.getProcedureName()), translatedParameters, proc);
    call.setReturnType(returnType);
    return call;
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) ArrayImpl(org.teiid.core.types.ArrayImpl) org.teiid.language(org.teiid.language) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Direction(org.teiid.language.Argument.Direction) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException)

Example 24 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestProcessor method testInsertTempTableCreation1.

@Test
public void testInsertTempTableCreation1() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select 2 as var1 into #temp; select #temp.var1 from #temp; END");
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs = RealMetadataFactory.createResultSet("rs", new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    Procedure vp = RealMetadataFactory.createVirtualProcedure("vp", v1, null, n1);
    vp.setResultSet(rs);
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // $NON-NLS-1$
    ProcessorPlan plan = helpGetPlan("exec v1.vp()", metadata);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }), Arrays.asList(new Object[] { new Integer(2) }) };
    helpProcess(plan, new FakeDataManager(), expected);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) BigInteger(java.math.BigInteger) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 25 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestProcessor method testInsertTempTableCreation.

/*
     *  Prior to case 3994 testInsertTempTableCreation1 worked, but testInsertTempTableCreation did not.
     *  Now they should both pass
     * 
     */
@Test
public void testInsertTempTableCreation() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN insert into #temp (var1) values (1); select #temp.var1 from #temp; END");
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnSet<Procedure> rs = RealMetadataFactory.createResultSet("rs", new String[] { "var1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    Procedure vp = RealMetadataFactory.createVirtualProcedure("vp", v1, null, n1);
    vp.setResultSet(rs);
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "foo");
    // $NON-NLS-1$
    ProcessorPlan plan = helpGetPlan("exec v1.vp()", metadata);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1) }) };
    helpProcess(plan, new FakeDataManager(), expected);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) BigInteger(java.math.BigInteger) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

Procedure (org.teiid.metadata.Procedure)82 ProcedureParameter (org.teiid.metadata.ProcedureParameter)36 Test (org.junit.Test)35 MetadataFactory (org.teiid.metadata.MetadataFactory)30 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)27 Schema (org.teiid.metadata.Schema)16 Column (org.teiid.metadata.Column)14 MetadataStore (org.teiid.metadata.MetadataStore)11 Properties (java.util.Properties)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 Table (org.teiid.metadata.Table)9 QueryNode (org.teiid.query.mapping.relational.QueryNode)8 List (java.util.List)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)5 TranslatorException (org.teiid.translator.TranslatorException)5 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)5 ArrayList (java.util.ArrayList)4 Call (org.teiid.language.Call)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3