use of org.teiid.metadata.Datatype in project teiid by teiid.
the class CouchbaseMetadataProcessor method addColumn.
private void addColumn(String name, String type, Object columnValue, boolean updatable, String nameInSource, Table table, MetadataFactory mf) {
String columnName = name;
String columnType = type;
if (columnType == null && columnValue == null && table.getColumnByName(columnName) == null) {
columnType = TypeFacility.RUNTIME_NAMES.STRING;
} else if (columnType == null && columnValue == null && table.getColumnByName(columnName) != null) {
columnType = table.getColumnByName(columnName).getDatatype().getName();
}
if (DataTypeManager.DefaultDataTypes.NULL.equals(columnType)) {
// how to handle null type?
columnType = DataTypeManager.DefaultDataTypes.STRING;
}
String tableNameInSource = trimWave(table.getNameInSource());
if (table.getProperty(IS_ARRAY_TABLE, false).equals(FALSE_VALUE) && columnName.startsWith(tableNameInSource)) {
columnName = columnName.substring(tableNameInSource.length() + 1);
}
if (table.getColumnByName(columnName) == null) {
Column column = mf.addColumn(columnName, columnType, table);
column.setUpdatable(updatable);
if (nameInSource != null) {
column.setNameInSource(nameInSource);
}
} else {
Column column = table.getColumnByName(columnName);
String existColumnType = column.getDatatype().getName();
if (!existColumnType.equals(columnType) && !existColumnType.equals(OBJECT) && columnValue != null) {
Datatype datatype = mf.getDataTypes().get(OBJECT);
column.setDatatype(datatype, true, 0);
}
}
}
use of org.teiid.metadata.Datatype in project teiid by teiid.
the class IQueryToLdapSearchParser method buildRequest.
public LDAPSearchDetails buildRequest(String query) throws TranslatorException {
ArrayList<String> attributes = new ArrayList<String>();
ArrayList<Column> columns = new ArrayList<Column>();
String contextName = null;
// $NON-NLS-1$
String criteria = "";
String searchScope = this.executionFactory.getSearchDefaultScope().name();
int timeLimit = 0;
long countLimit = -1;
List<String> parts = StringUtil.tokenize(query, ';');
for (String var : parts) {
int index = var.indexOf('=');
if (index == -1) {
throw new TranslatorException(LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12013, var));
}
String key = var.substring(0, index).trim();
String value = var.substring(index + 1).trim();
if (key.equalsIgnoreCase(CONTEXT_NAME)) {
contextName = value;
} else if (key.equalsIgnoreCase(CRITERIA)) {
criteria = value;
} else if (key.equalsIgnoreCase(SEARCH_SCOPE)) {
searchScope = value;
} else if (key.equalsIgnoreCase(TIMEOUT)) {
timeLimit = Integer.parseInt(value);
} else if (key.equalsIgnoreCase(COUNT_LIMIT)) {
countLimit = Long.parseLong(value);
} else if (key.equalsIgnoreCase(ATTRIBUTES)) {
// $NON-NLS-1$
StringTokenizer attrTokens = new StringTokenizer(value, ",");
while (attrTokens.hasMoreElements()) {
String name = attrTokens.nextToken().trim();
attributes.add(name);
Column column = new Column();
column.setName(name);
Datatype type = new Datatype();
type.setName(TypeFacility.RUNTIME_NAMES.OBJECT);
type.setJavaClassName(Object.class.getCanonicalName());
column.setDatatype(type, true);
columns.add(column);
}
} else {
throw new TranslatorException(LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12013, var));
}
}
int searchScopeInt = buildSearchScope(searchScope);
return new LDAPSearchDetails(contextName, searchScopeInt, criteria, null, countLimit, columns, timeLimit);
}
use of org.teiid.metadata.Datatype in project teiid by teiid.
the class TestCreateDrop method testForeignTemp.
@Test
public void testForeignTemp() {
Create create = new Create();
// $NON-NLS-1$
create.setTable(new GroupSymbol("tempTable"));
create.setOn("source");
Table t = new Table();
t.setName("tempTable");
t.setUUID("tid:0");
Column c = new Column();
c.setName("x");
c.setUUID("tid:0");
Datatype string = SystemMetadata.getInstance().getRuntimeTypeMap().get("string");
c.setDatatype(string, true, 0);
t.addColumn(c);
c = new Column();
c.setName("y");
c.setUUID("tid:0");
Datatype decimal = SystemMetadata.getInstance().getRuntimeTypeMap().get("decimal");
c.setDatatype(decimal, true, 0);
t.addColumn(c);
t.setCardinality(10000);
create.setTableMetadata(t);
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("create foreign temporary table tempTable (x string, y decimal) options (cardinality 10000) on source", "CREATE FOREIGN TEMPORARY TABLE tempTable (\n x string,\n y bigdecimal\n) OPTIONS (CARDINALITY 10000) ON 'source'", create);
}
use of org.teiid.metadata.Datatype in project teiid by teiid.
the class SystemMetadata method addAliasType.
private void addAliasType(String alias) {
Class<?> typeClass = DataTypeManager.getDataTypeClass(alias);
String primaryType = DataTypeManager.getDataTypeName(typeClass);
Datatype dt = typeMap.get(primaryType);
Assertion.isNotNull(dt, alias);
typeMap.put(alias, dt);
}
use of org.teiid.metadata.Datatype in project teiid by teiid.
the class AbstractVDBDeployer method loadMetadata.
protected void loadMetadata(VDBMetaData vdb, ConnectorManagerRepository cmr, MetadataStore store, VDBResources vdbResources) throws TranslatorException {
// add the system types
store.addDataTypes(SystemMetadata.getInstance().getRuntimeTypeMap());
// add domains if defined
String value = vdb.getPropertyValue(VDBMetaData.TEIID_DOMAINS);
if (value != null) {
// use a temporary store/db to retrieve the domains
DatabaseStore dbStore = new DatabaseStore() {
@Override
public Map<String, Datatype> getRuntimeTypes() {
return getVDBRepository().getRuntimeTypeMap();
}
};
dbStore.startEditing(true);
// $NON-NLS-1$ //$NON-NLS-2$
dbStore.databaseCreated(new Database("x", "1"));
// $NON-NLS-1$ //$NON-NLS-2$
dbStore.databaseSwitched("x", "1");
dbStore.setMode(Mode.DOMAIN);
QueryParser.getQueryParser().parseDDL(dbStore, new StringReader(value));
dbStore.stopEditing();
// $NON-NLS-1$ //$NON-NLS-2$
store.addDataTypes(dbStore.getDatabase("x", "1").getMetadataStore().getDatatypes());
}
// load metadata from the models
AtomicInteger loadCount = new AtomicInteger();
for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
if (model.getModelType() == Model.Type.PHYSICAL || model.getModelType() == Model.Type.VIRTUAL) {
loadCount.incrementAndGet();
}
}
if (loadCount.get() == 0) {
processVDBDDL(vdb, store, cmr, vdbResources);
getVDBRepository().finishDeployment(vdb.getName(), vdb.getVersion());
return;
}
for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
MetadataRepository metadataRepository = model.getAttachment(MetadataRepository.class);
if (model.getModelType() == Model.Type.PHYSICAL || model.getModelType() == Model.Type.VIRTUAL) {
loadMetadata(vdb, model, cmr, metadataRepository, store, loadCount, vdbResources);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "Model ", model.getName(), "in VDB ", vdb.getName(), " was being loaded from its repository");
} else {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "Model ", model.getName(), "in VDB ", vdb.getName(), " skipped being loaded because of its type ", model.getModelType());
}
}
}
Aggregations