use of org.teiid.metadata.Procedure in project teiid by teiid.
the class SQLConversionVisitor method visit.
/**
* @see org.teiid.language.visitor.SQLStringVisitor#visit(org.teiid.language.Call)
*/
public void visit(Call obj) {
usingBinding = true;
Procedure p = obj.getMetadataObject();
if (p != null) {
String nativeQuery = p.getProperty(TEIID_NATIVE_QUERY, false);
if (nativeQuery != null) {
this.prepared = !Boolean.valueOf(p.getProperty(TEIID_NON_PREPARED, false));
if (this.prepared) {
this.preparedValues = new ArrayList<Object>();
}
parseNativeQueryParts(nativeQuery, obj.getArguments(), buffer, this);
return;
}
}
if (obj.isTableReference()) {
usingBinding = false;
super.visit(obj);
return;
}
this.prepared = true;
/*
* preparedValues is now a list of procedure params instead of just values
*/
this.preparedValues = obj.getArguments();
buffer.append(generateSqlForStoredProcedure(obj));
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class DdlPlan method setProperty.
public static String setProperty(final VDBMetaData vdb, final AbstractMetadataRecord record, final String key, final String value) {
TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
String result = record.setProperty(key, value);
// $NON-NLS-1$
metadata.addToMetadataCache(record, "transformation/matview", null);
if (record instanceof Table) {
((Table) record).setLastModified(System.currentTimeMillis());
} else if (record instanceof Procedure) {
((Procedure) record).setLastModified(System.currentTimeMillis());
}
return result;
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestUpdateValidator method example1.
public static TransformationMetadata example1(boolean allUpdatable) {
MetadataStore metadataStore = new MetadataStore();
// Create models
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
// Create physical groups
// $NON-NLS-1$
Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
// $NON-NLS-1$
Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
// $NON-NLS-1$
Table pm1g3 = RealMetadataFactory.createPhysicalGroup("g3", pm1);
// Create physical elements
List<Column> pm1g1e = RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
if (!allUpdatable) {
pm1g1e.get(0).setUpdatable(false);
}
KeyRecord pk = RealMetadataFactory.createKey(Type.Primary, "pk", pm1g1, pm1g1e.subList(0, 1));
List<Column> pm1g2e = RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
RealMetadataFactory.createKey(Type.Primary, "pk", pm1g2, pm1g1e.subList(1, 2));
RealMetadataFactory.createForeignKey("fk", pm1g2, pm1g2e.subList(0, 1), pk);
List<Column> pm1g3e = RealMetadataFactory.createElements(pm1g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
pm1g3e.get(0).setNullType(NullType.No_Nulls);
pm1g3e.get(0).setDefaultValue(null);
pm1g3e.get(1).setNullType(NullType.No_Nulls);
pm1g3e.get(1).setAutoIncremented(true);
pm1g3e.get(1).setDefaultValue(null);
pm1g3e.get(2).setNullType(NullType.No_Nulls);
// $NON-NLS-1$
pm1g3e.get(2).setDefaultValue("xyz");
RealMetadataFactory.createKey(Type.Primary, "pk", pm1g3, pm1g3e.subList(0, 1));
// Create virtual groups
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g1n1 = new QueryNode("SELECT e1 as a, e2 FROM pm1.g1 WHERE e3 > 5");
// $NON-NLS-1$
Table vm1g1 = RealMetadataFactory.createUpdatableVirtualGroup("g1", vm1, vm1g1n1);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g2n1 = new QueryNode("SELECT e1, e2, e3, e4 FROM pm1.g2 WHERE e3 > 5");
// $NON-NLS-1$
Table vm1g2 = RealMetadataFactory.createUpdatableVirtualGroup("g2", vm1, vm1g2n1);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g3n1 = new QueryNode("SELECT e1, e3 FROM pm1.g3");
// $NON-NLS-1$
Table vm1g3 = RealMetadataFactory.createUpdatableVirtualGroup("g3", vm1, vm1g3n1);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g4n1 = new QueryNode("SELECT e1, e2 FROM pm1.g3");
// $NON-NLS-1$
Table vm1g4 = RealMetadataFactory.createUpdatableVirtualGroup("g4", vm1, vm1g4n1);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g5n1 = new QueryNode("SELECT e2, e3 FROM pm1.g3");
// $NON-NLS-1$
Table vm1g5 = RealMetadataFactory.createVirtualGroup("g5", vm1, vm1g5n1);
// Create virtual elements
RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "a", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
RealMetadataFactory.createElements(vm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
RealMetadataFactory.createElements(vm1g3, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
RealMetadataFactory.createElements(vm1g4, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "e1", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.BOOLEAN });
RealMetadataFactory.createElements(vm1g5, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN });
// Stored queries
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("rs1", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode sq1n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN SELECT e1, e2 FROM pm1.g1; END");
// $NON-NLS-1$
Procedure sq1 = RealMetadataFactory.createVirtualProcedure("sq1", pm1, Collections.EMPTY_LIST, sq1n1);
sq1.setResultSet(rs1);
// Create the facade from the store
return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestValidator method helpCreateCase4237VirtualProcedureMetadata.
/**
* Create fake metadata for this case. Need a physical stored procedure and
* a virtual stored procedure which calls the physical one.
* @return
*/
private TransformationMetadata helpCreateCase4237VirtualProcedureMetadata() {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema physicalModel = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ColumnSet<Procedure> resultSet = RealMetadataFactory.createResultSet("pm1.rs", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
// $NON-NLS-1$
ProcedureParameter inParam = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$ //$NON-NLS-2$
Procedure storedProcedure = RealMetadataFactory.createStoredProcedure("sp", physicalModel, Arrays.asList(inParam));
storedProcedure.setResultSet(resultSet);
// $NON-NLS-1$
Schema virtualModel = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ColumnSet<Procedure> virtualResultSet = RealMetadataFactory.createResultSet("vm1.rs", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
// $NON-NLS-1$
ProcedureParameter virtualInParam = RealMetadataFactory.createParameter("in1", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode queryNode = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN EXEC pm1.sp(vm1.sp.in1); END");
// $NON-NLS-1$
Procedure virtualStoredProcedure = RealMetadataFactory.createVirtualProcedure("sp", virtualModel, Arrays.asList(virtualInParam), queryNode);
virtualStoredProcedure.setResultSet(virtualResultSet);
return RealMetadataFactory.createTransformationMetadata(metadataStore, "case4237");
}
use of org.teiid.metadata.Procedure in project teiid by teiid.
the class TestDynamicImportedMetaData method testDDLMetadata.
@Test
public void testDDLMetadata() throws Exception {
String ddl = "CREATE FOREIGN PROCEDURE getTextFiles(IN pathAndPattern varchar) RETURNS (file clob, filpath string) OPTIONS(UUID 'uuid')";
MetadataFactory mf = createMetadataFactory("MarketData", new Properties());
QueryParser.getQueryParser().parseDDL(mf, ddl);
MetadataStore ms = mf.asMetadataStore();
String ddl2 = "CREATE VIEW stock (symbol string, price bigdecimal) OPTIONS (UUID 'uuid')" + "AS select stock.* from (call MarketData.getTextFiles('*.txt')) f, " + "TEXTTABLE(f.file COLUMNS symbol string, price bigdecimal HEADER) stock;";
MetadataFactory m2 = createMetadataFactory("portfolio", new Properties());
QueryParser.getQueryParser().parseDDL(m2, ddl2);
m2.getSchema().setPhysical(false);
m2.mergeInto(ms);
server.deployVDB("test", ms);
// $NON-NLS-1$
Connection conn = server.createConnection("jdbc:teiid:test");
Properties props = new Properties();
props.setProperty("importer.importProcedures", Boolean.TRUE.toString());
MetadataStore store = getMetadata(props, conn).asMetadataStore();
Procedure p = store.getSchema("test").getProcedure("test.MarketData.getTextFiles");
assertNotNull(p);
ProcedureParameter pp = p.getParameters().get(0);
assertEquals("pathAndPattern", pp.getName());
assertEquals("\"pathAndPattern\"", pp.getNameInSource());
assertEquals(ProcedureParameter.Type.In, pp.getType());
// assertEquals("string", pp.getDatatype().getName());
Table t = store.getSchema("test").getTable("test.portfolio.stock");
assertNotNull(t);
List<Column> columns = t.getColumns();
assertEquals(2, columns.size());
assertEquals("symbol", columns.get(0).getName());
assertEquals("price", columns.get(1).getName());
}
Aggregations