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