use of org.teiid.metadata.Column in project teiid by teiid.
the class LanguageBridgeFactory method translate.
public With translate(List<WithQueryCommand> with) {
if (with == null || with.isEmpty()) {
return null;
}
With result = new With();
ArrayList<WithItem> items = new ArrayList<WithItem>(with.size());
for (WithQueryCommand withQueryCommand : with) {
WithItem item = new WithItem();
GroupSymbol group = withQueryCommand.getGroupSymbol();
if (withQueryCommand.getCommand() != null && excludeWithName != null && excludeWithName.equalsIgnoreCase(group.getName())) {
group = RulePlaceAccess.recontextSymbol(withQueryCommand.getGroupSymbol(), commandContext.getGroups());
group.setDefinition(null);
if (remappedGroups == null) {
remappedGroups = new IdentityHashMap<Object, GroupSymbol>();
}
this.remappedGroups.put(group.getMetadataID(), group);
}
item.setTable(translate(group));
if (withQueryCommand.getColumns() != null) {
List<ColumnReference> translatedElements = new ArrayList<ColumnReference>(withQueryCommand.getColumns().size());
for (ElementSymbol es : withQueryCommand.getColumns()) {
ColumnReference cr = translate(es);
translatedElements.add(cr);
if (withQueryCommand.getCommand() == null) {
// we want to convey the metadata to the source layer if possible
Object mid = es.getMetadataID();
if (mid instanceof TempMetadataID) {
TempMetadataID tid = (TempMetadataID) mid;
mid = tid.getOriginalMetadataID();
}
if (mid instanceof Column) {
cr.setMetadataObject((Column) mid);
}
}
}
item.setColumns(translatedElements);
}
if (withQueryCommand.getCommand() != null) {
item.setSubquery(translate(withQueryCommand.getCommand()));
} else {
item.setDependentValues(new TupleBufferList(withQueryCommand.getTupleBuffer()));
}
item.setRecusive(withQueryCommand.isRecursive());
items.add(item);
}
result.setItems(items);
return result;
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class TestOrderByRewrite method helpCheckElements.
private void helpCheckElements(OrderBy langObj, String[] elementNames, String[] elementIDs) {
List<ElementSymbol> elements = new ArrayList<ElementSymbol>();
for (Iterator<Expression> i = langObj.getSortKeys().iterator(); i.hasNext(); ) {
ElementCollectorVisitor.getElements(i.next(), elements);
}
// $NON-NLS-1$
assertEquals("Wrong number of elements: ", elementNames.length, elements.size());
for (int i = 0; i < elements.size(); i++) {
ElementSymbol symbol = elements.get(i);
// $NON-NLS-1$
assertEquals("Element name does not match: ", elementNames[i].toUpperCase(), symbol.getName().toUpperCase());
Column elementID = (Column) symbol.getMetadataID();
// $NON-NLS-1$ //$NON-NLS-2$
assertNotNull("ElementSymbol " + symbol + " was not resolved and has no metadataID", elementID);
// $NON-NLS-1$
assertEquals("ElementID name does not match: ", elementIDs[i].toUpperCase(), elementID.getFullName().toUpperCase());
}
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class LDAPQueryExecution method getRow.
/**
* Create a row using the searchResult and add it to the supplied batch.
* @param batch the supplied batch
* @param result the search result
* @throws InvalidNameException
*/
// GHH 20080326 - added fetching of DN of result, for directories that
// do not include it as an attribute
private List<?> getRow(SearchResult result) throws TranslatorException, InvalidNameException {
Attributes attrs = result.getAttributes();
ArrayList<Column> attributeList = searchDetails.getElementList();
final List<Object> row = new ArrayList<Object>(attributeList.size());
for (int i = 0; i < attributeList.size(); i++) {
Column col = attributeList.get(i);
// GHH 20080326 - added resultDN parameter to call
Object val = getValue(col, result, attrs, i == unwrapPos);
row.add(val);
}
if (unwrapPos > -1) {
Object toUnwrap = row.get(unwrapPos);
if (toUnwrap == null) {
// missing value
return row;
}
if (toUnwrap instanceof ArrayImpl) {
final Object[] val = ((ArrayImpl) toUnwrap).getValues();
if (val.length == 0) {
// empty value
row.set(unwrapPos, null);
} else {
unwrapIterator = new Iterator<List<Object>>() {
int i = 0;
@Override
public boolean hasNext() {
return i < val.length;
}
@Override
public List<Object> next() {
List<Object> newRow = new ArrayList<Object>(row);
newRow.set(unwrapPos, val[i++]);
return newRow;
}
@Override
public void remove() {
}
};
if (unwrapIterator.hasNext()) {
return unwrapIterator.next();
}
}
}
}
return row;
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class LDAPSearchDetails method printDetailsToLog.
/*
public LdapSortKey[] getNetscapeSortKeys() {
return netscapeKeys;
}
private void createNetscapeKeys() {
if(keys != null) {
netscapeKeys = new LdapSortKey[keys.length];
for(int i=0; i<keys.length; i++) {
LdapSortKey nKey = new LdapSortKey(keys[i].getAttributeID(),
keys[i].isAscending());
netscapeKeys[i] = nKey;
}
} else {
// set it null
netscapeKeys = null;
}
}
*/
/**
* Print Method for Logging - (Detail level logging)
*/
public void printDetailsToLog() {
// Log Search Scope
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Search context: " + contextName);
if (searchScope == SearchControls.SUBTREE_SCOPE) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Search scope = SUBTREE_SCOPE");
} else if (searchScope == SearchControls.OBJECT_SCOPE) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Search scope = OBJECT_SCOPE");
} else if (searchScope == SearchControls.ONELEVEL_SCOPE) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Search scope = ONELEVEL_SCOPE");
}
// Log Search Attributes
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Search attributes: ");
Iterator itr = this.elementList.iterator();
int i = 0;
while (itr.hasNext()) {
Column attr = (Column) itr.next();
String attrName = attr.getSourceName();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Attribute [" + i + "]: " + attrName + " (" + attr.toString() + ")");
i++;
}
// Log Context Filter
if (contextFilter != null && (!contextFilter.equals(""))) {
// $NON-NLS-1$
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Where clause was translated into Ldap search filter: " + contextFilter);
}
// Log Sort Keys
if (keys != null) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Sort keys: ");
for (int j = 0; j < keys.length; j++) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "\tName: " + keys[j].getAttributeID());
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "\tOrder: ");
if (keys[j].isAscending()) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "ASC");
} else {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "DESC");
}
}
}
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class JPAMetadataProcessor method addColumn.
private Column addColumn(MetadataFactory mf, String name, String type, Table entityTable) throws TranslatorException {
if (!columnExists(name, entityTable)) {
Column c = mf.addColumn(name, type, entityTable);
c.setUpdatable(true);
return c;
}
return entityTable.getColumnByName(name);
}
Aggregations