Search in sources :

Example 26 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class FtpManagedConnectionFactory method setCertificate.

public void setCertificate(String certificate) {
    this.certificate = certificate;
    if (this.certificate != null && Files.exists(Paths.get(this.certificate))) {
        try {
            // $NON-NLS-1$
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            InputStream in = Files.newInputStream(Paths.get(this.certificate));
            Certificate cert = certificateFactory.generateCertificate(in);
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(null);
            // $NON-NLS-1$
            keyStore.setCertificateEntry("alias", cert);
            trustManager = TrustManagerUtils.getDefaultTrustManager(keyStore);
        } catch (IOException | GeneralSecurityException e) {
            // $NON-NLS-1$
            throw new TeiidRuntimeException(UTIL.getString("ftp_certificate_path", certificate, e));
        }
    }
}
Also used : InputStream(java.io.InputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CertificateFactory(java.security.cert.CertificateFactory) KeyStore(java.security.KeyStore) Certificate(java.security.cert.Certificate)

Example 27 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class DataTierManagerImpl method getColumns.

private List<ElementSymbol> getColumns(TransformationMetadata tm, String name) {
    GroupSymbol gs = new GroupSymbol(name);
    try {
        ResolverUtil.resolveGroup(gs, tm);
        List<ElementSymbol> columns = ResolverUtil.resolveElementsInGroup(gs, tm);
        return columns;
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 28 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class LanguageBridgeFactory method translate.

/* Execute */
Call translate(StoredProcedure sp) {
    Procedure proc = null;
    if (sp.getProcedureID() != null) {
        try {
            proc = this.metadataFactory.getProcedure(sp.getGroup().getName());
        } catch (TranslatorException e) {
            throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30486, e);
        }
    }
    Class<?> returnType = null;
    List<Argument> translatedParameters = new ArrayList<Argument>();
    for (SPParameter param : sp.getParameters()) {
        Direction direction = Direction.IN;
        switch(param.getParameterType()) {
            case ParameterInfo.IN:
                direction = Direction.IN;
                break;
            case ParameterInfo.INOUT:
                direction = Direction.INOUT;
                break;
            case ParameterInfo.OUT:
                direction = Direction.OUT;
                break;
            case ParameterInfo.RESULT_SET:
                // already part of the metadata
                continue;
            case ParameterInfo.RETURN_VALUE:
                returnType = param.getClassType();
                continue;
        }
        if (param.isUsingDefault() && BaseColumn.OMIT_DEFAULT.equalsIgnoreCase(metadataFactory.getMetadata().getExtensionProperty(param.getMetadataID(), BaseColumn.DEFAULT_HANDLING, false))) {
            continue;
        }
        ProcedureParameter metadataParam = metadataFactory.getParameter(param);
        // we can assume for now that all arguments will be literals, which may be multivalued
        org.teiid.language.Expression value = null;
        if (direction != Direction.OUT) {
            if (param.isVarArg()) {
                ArrayImpl av = (ArrayImpl) ((Constant) param.getExpression()).getValue();
                if (av != null) {
                    for (Object obj : av.getValues()) {
                        Argument arg = new Argument(direction, new Literal(obj, param.getClassType().getComponentType()), param.getClassType().getComponentType(), metadataParam);
                        translatedParameters.add(arg);
                    }
                }
                break;
            }
            value = translate(param.getExpression());
        }
        Argument arg = new Argument(direction, value, param.getClassType(), metadataParam);
        translatedParameters.add(arg);
    }
    Call call = new Call(removeSchemaName(sp.getProcedureName()), translatedParameters, proc);
    call.setReturnType(returnType);
    return call;
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) ArrayImpl(org.teiid.core.types.ArrayImpl) org.teiid.language(org.teiid.language) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Direction(org.teiid.language.Argument.Direction) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException)

Example 29 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class LanguageBridgeFactory method translate.

public NamedTable translate(GroupSymbol symbol) {
    String alias = null;
    String fullGroup = symbol.getOutputName();
    if (symbol.getOutputDefinition() != null) {
        alias = symbol.getOutputName();
        fullGroup = symbol.getOutputDefinition();
        if (remappedGroups != null) {
            GroupSymbol remappedGroup = remappedGroups.get(symbol.getMetadataID());
            if (remappedGroup != null && remappedGroup != symbol) {
                fullGroup = remappedGroup.getName();
            }
        }
    }
    fullGroup = removeSchemaName(fullGroup);
    NamedTable group = new NamedTable(fullGroup, alias, null);
    try {
        group.setMetadataObject(metadataFactory.getGroup(symbol.getMetadataID()));
    } catch (QueryMetadataException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30487, e);
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30488, e);
    }
    return group;
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 30 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class CachedFinder method findCapabilities.

/**
 * Find capabilities used the cache if possible, otherwise do the lookup.
 */
public SourceCapabilities findCapabilities(String modelName) throws TeiidComponentException {
    SourceCapabilities caps = userCache.get(modelName);
    if (caps != null) {
        return caps;
    }
    ModelMetaData model = vdb.getModel(modelName);
    List<String> sourceNames = model.getSourceNames();
    if (sourceNames.isEmpty()) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30499, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30499, modelName));
    }
    TeiidException cause = null;
    for (String sourceName : sourceNames) {
        // TOOD: in multi-source mode it may be necessary to compute minimal capabilities across the sources
        ConnectorManager mgr = this.connectorRepo.getConnectorManager(sourceName);
        if (mgr == null) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30497, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30497, sourceName, modelName, sourceName));
        }
        try {
            caps = mgr.getCapabilities();
            break;
        } catch (TeiidException e) {
            cause = e;
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_DQP, e, "Could not obtain capabilities for" + sourceName);
        }
    }
    if (caps == null) {
        InvalidCaps ic = new InvalidCaps();
        ic.setSourceProperty(Capability.INVALID_EXCEPTION, cause);
        caps = ic;
    }
    userCache.put(modelName, caps);
    return caps;
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TeiidException(org.teiid.core.TeiidException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4