Search in sources :

Example 11 with AbstractMetadataRecord

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;
}
Also used : AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) Cachable(org.teiid.cache.Cachable)

Example 12 with AbstractMetadataRecord

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;
}
Also used : TempMetadataID(org.teiid.query.metadata.TempMetadataID) ArrayList(java.util.ArrayList) List(java.util.List) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 13 with AbstractMetadataRecord

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();
}
Also used : AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 14 with AbstractMetadataRecord

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);
    }
}
Also used : Table(org.teiid.metadata.Table) SQLStringVisitor(org.teiid.language.visitor.SQLStringVisitor) Select(org.teiid.language.Select) DocumentFilter(org.teiid.infinispan.api.DocumentFilter) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 15 with AbstractMetadataRecord

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);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) AuthorizationValidator(org.teiid.dqp.internal.process.AuthorizationValidator) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Command(org.teiid.query.sql.lang.Command) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Aggregations

AbstractMetadataRecord (org.teiid.metadata.AbstractMetadataRecord)16 NamedTable (org.teiid.language.NamedTable)3 SQLStringVisitor (org.teiid.language.visitor.SQLStringVisitor)3 Column (org.teiid.metadata.Column)3 List (java.util.List)2 Properties (java.util.Properties)2 DocumentFilter (org.teiid.infinispan.api.DocumentFilter)2 ColumnReference (org.teiid.language.ColumnReference)2 Select (org.teiid.language.Select)2 Table (org.teiid.metadata.Table)2 SObject (com.sforce.soap.partner.sobject.SObject)1 XmlObject (com.sforce.ws.bind.XmlObject)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 Test (org.junit.Test)1 PermissionType (org.teiid.adminapi.DataPolicy.PermissionType)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)1 Cachable (org.teiid.cache.Cachable)1