use of org.teiid.metadata.AbstractMetadataRecord in project teiid by teiid.
the class SessionAwareCache method computeTtl.
Long computeTtl(CacheID id, T t, Long ttl) {
if (!(t instanceof Cachable) || type != Type.RESULTSET) {
return ttl;
}
Cachable c = (Cachable) t;
AccessInfo info = c.getAccessInfo();
if (info == null) {
return ttl;
}
Set<Object> objects = info.getObjectsAccessed();
if (objects == null) {
return ttl;
}
long computedTtl = Long.MAX_VALUE;
for (Object o : objects) {
if (!(o instanceof AbstractMetadataRecord)) {
continue;
}
AbstractMetadataRecord amr = (AbstractMetadataRecord) o;
Long l = getDataTtl(amr);
if (l == null || l < 0) {
continue;
}
if (l == 0) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogManager.logDetail(LogConstants.CTX_DQP, "Not adding cache entry", id, "since", amr.getFullName(), "has caching disabled");
}
return Long.valueOf(0);
}
computedTtl = Math.min(l, computedTtl);
}
if (ttl != null) {
ttl = Math.min(ttl, computedTtl);
} else if (computedTtl != Long.MAX_VALUE) {
ttl = computedTtl;
}
return ttl;
}
use of org.teiid.metadata.AbstractMetadataRecord in project teiid by teiid.
the class AccessInfo method initExternalList.
private static List<List<String>> initExternalList(List<List<String>> externalNames, Set<? extends Object> accessed) {
if (externalNames == null) {
externalNames = new ArrayList<List<String>>(accessed.size());
for (Object object : accessed) {
if (object instanceof AbstractMetadataRecord) {
AbstractMetadataRecord t = (AbstractMetadataRecord) object;
externalNames.add(Arrays.asList(t.getParent().getName(), t.getName()));
} else if (object instanceof TempMetadataID) {
TempMetadataID t = (TempMetadataID) object;
externalNames.add(Arrays.asList(t.getID()));
}
}
}
return externalNames;
}
use of org.teiid.metadata.AbstractMetadataRecord in project teiid by teiid.
the class SQLStringVisitor method getElementName.
private String getElementName(ColumnReference obj, boolean qualify) {
String groupName = null;
NamedTable group = obj.getTable();
if (group != null && qualify) {
if (group.getCorrelationName() != null) {
groupName = group.getCorrelationName();
} else {
AbstractMetadataRecord groupID = group.getMetadataObject();
if (groupID != null) {
groupName = getName(groupID);
} else {
groupName = group.getName();
}
}
}
String elemShortName = null;
AbstractMetadataRecord elementID = obj.getMetadataObject();
if (elementID != null) {
elemShortName = getName(elementID);
} else {
elemShortName = obj.getName();
}
// Check whether a subclass wants to replace the element name to use in special circumstances
String replacementElement = replaceElementName(groupName, elemShortName);
if (replacementElement != null) {
// If so, use it as is
return replacementElement;
}
StringBuffer elementName = new StringBuffer(elemShortName.length());
// If not, do normal logic: [group + "."] + element
if (groupName != null) {
elementName.append(groupName);
elementName.append(Tokens.DOT);
}
elementName.append(elemShortName);
return elementName.toString();
}
use of org.teiid.metadata.AbstractMetadataRecord in project teiid by teiid.
the class InfinispanQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
try {
if (useAliasCache) {
useModifiedGroups(this.connection, this.executionContext, this.metadata, this.command);
}
final IckleConversionVisitor visitor = new IckleConversionVisitor(metadata, false);
visitor.append(this.command);
Table table = visitor.getParentTable();
String queryStr = visitor.getQuery();
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "SourceQuery:", queryStr);
DocumentFilter docFilter = null;
if (queryStr.startsWith("FROM ") && ((Select) command).getWhere() != null) {
SQLStringVisitor ssv = new SQLStringVisitor() {
@Override
public String getName(AbstractMetadataRecord object) {
return object.getName();
}
};
ssv.append(((Select) command).getWhere());
docFilter = new ComplexDocumentFilter(visitor.getParentNamedTable(), visitor.getQueryNamedTable(), this.metadata, ssv.toString(), Action.ADD);
}
this.marshaller = MarshallerBuilder.getMarshaller(table, this.metadata, docFilter);
this.connection.registerMarshaller(this.marshaller);
// if the message in defined in different cache than the default, switch it out now.
RemoteCache<Object, Object> cache = getCache(table, connection);
results = new InfinispanResponse(cache, queryStr, this.executionContext.getBatchSize(), visitor.getRowLimit(), visitor.getRowOffset(), visitor.getProjectedDocumentAttributes(), visitor.getDocumentNode());
} finally {
this.connection.unRegisterMarshaller(this.marshaller);
}
}
use of org.teiid.metadata.AbstractMetadataRecord in project teiid by teiid.
the class TestSecurityFunctions method testHasRoleWithService.
@Test
public void testHasRoleWithService() throws Exception {
// $NON-NLS-1$
String sql = "select pm1.g1.e2 from pm1.g1 where true = hasRole('data', pm1.g1.e1)";
// Create expected results
List[] expected = new List[] {};
// Construct data manager with data
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "fooRole", new Integer(0) }) });
CommandContext context = new CommandContext();
context.setAuthoriziationValidator(new AuthorizationValidator() {
@Override
public boolean validate(String[] originalSql, Command command, QueryMetadataInterface metadata, CommandContext commandContext, CommandType commandType) throws QueryValidatorException, TeiidComponentException {
return false;
}
@Override
public boolean hasRole(String roleName, CommandContext commandContext) {
return false;
}
@Override
public boolean isAccessible(AbstractMetadataRecord record, CommandContext commandContext) {
return true;
}
});
Command command = TestProcessor.helpParse(sql);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
// Run query
TestProcessor.helpProcess(plan, context, dataManager, expected);
}
Aggregations