use of org.teiid.metadata.Table in project teiid by teiid.
the class CompositeMetadataStore method findGroup.
public Table findGroup(String fullName) throws QueryMetadataException {
int index = fullName.indexOf(TransformationMetadata.DELIMITER_STRING);
if (index == -1) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID30353, fullName + TransformationMetadata.NOT_EXISTS_MESSAGE);
}
String schemaName = fullName.substring(0, index);
Schema schema = getSchema(schemaName);
if (schema == null) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID30352, fullName + TransformationMetadata.NOT_EXISTS_MESSAGE);
}
Table result = schema.getTables().get(fullName.substring(index + 1));
if (result == null) {
throw new QueryMetadataException(QueryPlugin.Event.TEIID30354, fullName + TransformationMetadata.NOT_EXISTS_MESSAGE);
}
return result;
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestSessionAwareCache method testTtl.
@Test
public void testTtl() {
SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
Cachable result = Mockito.mock(Cachable.class);
// make sure defaults are returned
assertNull(cache.computeTtl(id, result, null));
assertEquals(Long.valueOf(1), cache.computeTtl(id, result, 1l));
AccessInfo ai = new AccessInfo();
Mockito.stub(result.getAccessInfo()).toReturn(ai);
Table t = new Table();
t.setProperty(DataModifiable.DATA_TTL, "2");
ai.addAccessedObject(t);
assertEquals(Long.valueOf(2), cache.computeTtl(id, result, null));
Table t1 = new Table();
Schema s = new Schema();
t1.setParent(s);
s.setProperty(DataModifiable.DATA_TTL, "0");
ai.addAccessedObject(t1);
// ensure that the min and the parent are used
assertEquals(Long.valueOf(0), cache.computeTtl(id, result, null));
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestMetaDataProcessor method examplePrivatePhysicalModel.
public static TransformationMetadata examplePrivatePhysicalModel() {
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$ //$NON-NLS-2$
QueryNode vm1g1n1 = new QueryNode("SELECT * FROM pm1.g1");
// $NON-NLS-1$
Table vm1g1 = RealMetadataFactory.createVirtualGroup("g1", vm1, vm1g1n1);
// $NON-NLS-1$
Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
// Create physical elements
RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$
new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.SHORT });
// Create physical elements
List<Column> pm1g2e = RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$
new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
Column e1 = pm1g2e.get(0);
e1.setPrecision(19);
e1.setLength(21);
e1.setScale(4);
RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$
new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
// Create the facade from the store
return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestODataIntegration method testBasicTypes.
@Test
public void testBasicTypes() throws Exception {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMapping("x3", "x3", null);
MetadataStore ms = RealMetadataFactory.exampleBQTStore();
Schema s = ms.getSchema("BQT1");
KeyRecord pk = new KeyRecord(KeyRecord.Type.Primary);
Table smalla = s.getTable("SmallA");
pk.setName("pk");
pk.addColumn(smalla.getColumnByName("IntKey"));
smalla.setPrimaryKey(pk);
String ddl = DDLStringVisitor.getDDLString(s, EnumSet.allOf(SchemaObjectType.class), "SmallA");
mmd.addSourceMetadata("DDL", ddl);
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
teiid.addTranslator("x3", hc);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.GET(baseURL + "/northwind/m/SmallA?$format=json&$select=TimeValue");
assertEquals(200, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class ODataSQLBuilder method selectWithEntityKey.
// TODO: allow the generated key building.
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException {
Table table = findTable(entityType.getName(), this.metadata);
DocumentNode resource = new DocumentNode(table, new GroupSymbol(table.getFullName()), entityType);
resource.setFromClause(new UnaryFromClause(new GroupSymbol(table.getFullName())));
resource.addAllColumns(false);
this.context = resource;
Query query = this.context.buildQuery();
processExpand(expand, resource, query, 1);
Criteria criteria = null;
KeyRecord pk = ODataSchemaBuilder.getIdentifier(table);
for (Column c : pk.getColumns()) {
Property prop = entity.getProperty(c.getName());
Constant right = null;
if (prop != null) {
right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue(), null));
} else {
Object value = generatedKeys.get(c.getName());
if (value == null) {
throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
}
right = new Constant(value);
}
ElementSymbol left = new ElementSymbol(c.getName(), this.context.getGroupSymbol());
if (criteria == null) {
criteria = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
} else {
CompareCriteria rightCC = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
criteria = new CompoundCriteria(CompoundCriteria.AND, criteria, rightCC);
}
}
query.setCriteria(criteria);
return query;
}
Aggregations