Search in sources :

Example 81 with TeiidException

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

the class TranslatorUtil method injectProperties.

private static void injectProperties(ExecutionFactory ef, final VDBTranslatorMetaData data) throws InvocationTargetException, IllegalAccessException, TeiidException {
    Map<Method, TranslatorProperty> props = TranslatorUtil.getTranslatorProperties(ef.getClass());
    Map<String, String> p = data.getPropertiesMap();
    TreeMap<String, String> caseInsensitiveProps = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    /*
		VDBTranslatorMetaData parent = data.getParent();
		while (parent != null) {
			for (Map.Entry<String, String> entry : parent.getPropertiesMap().entrySet()) {
				if (!caseInsensitiveProps.containsKey(entry.getKey()) && entry.getValue() != null) {
					caseInsensitiveProps.put(entry.getKey(), entry.getValue());
				}
			}
			parent = parent.getParent();
		}
		*/
    synchronized (p) {
        caseInsensitiveProps.putAll(p);
    }
    caseInsensitiveProps.remove(DEPLOYMENT_NAME);
    for (Method method : props.keySet()) {
        TranslatorProperty tp = props.get(method);
        String propertyName = getPropertyName(method);
        String value = caseInsensitiveProps.remove(propertyName);
        if (value != null) {
            Method setterMethod = getSetter(ef.getClass(), method);
            setterMethod.invoke(ef, convert(value, method.getReturnType()));
        } else if (tp.required()) {
            throw new TeiidException(RuntimePlugin.Event.TEIID40027, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40027, tp.display()));
        }
    }
    caseInsensitiveProps.remove(Translator.EXECUTION_FACTORY_CLASS);
    if (!caseInsensitiveProps.isEmpty()) {
        LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40001, caseInsensitiveProps.keySet(), data.getName()));
    }
}
Also used : Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) TranslatorProperty(org.teiid.translator.TranslatorProperty) TeiidException(org.teiid.core.TeiidException)

Example 82 with TeiidException

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

the class VDBStatusChecker method updateSource.

/**
 * @return true if the datasource is new to the vdb
 * @throws AdminProcessingException
 */
public boolean updateSource(String vdbName, String vdbVersion, SourceMappingMetadata mapping, boolean replace) throws AdminProcessingException {
    String dsName = stripContext(mapping.getConnectionJndiName());
    VDBMetaData vdb = getVDBRepository().getLiveVDB(vdbName, vdbVersion);
    if (vdb == null || vdb.getStatus() == Status.FAILED) {
        return false;
    }
    synchronized (vdb) {
        ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
        ConnectorManager existing = cmr.getConnectorManager(mapping.getName());
        try {
            cmr.createConnectorManager(vdb, cmr.getProvider(), mapping, replace);
        } catch (TeiidException e) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40033, e);
        }
        if (mapping.getConnectionJndiName() != null && (existing == null || !dsName.equals(existing.getConnectionName()))) {
            List<Runnable> runnables = new ArrayList<Runnable>();
            resourceAdded(dsName, runnables, vdb);
            return true;
        }
        return false;
    }
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) TeiidException(org.teiid.core.TeiidException)

Example 83 with TeiidException

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

the class DocumentNode method buildEntityKeyCriteria.

static Criteria buildEntityKeyCriteria(DocumentNode resource, UriInfo uriInfo, MetadataStore store, OData odata, UniqueNameGenerator nameGenerator, URLParseService parseService) throws TeiidException {
    List<Column> pk = getPKColumns(resource.getTable());
    if (resource.getKeyPredicates().size() == 1) {
        if (pk.size() != 1) {
            throw new TeiidException(ODataPlugin.Event.TEIID16015, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16015, resource.getTable().getFullName()));
        }
        Column column = pk.get(0);
        ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(resource, false, uriInfo, store, odata, nameGenerator, null, parseService);
        UriParameter key = resource.getKeyPredicates().get(0);
        org.apache.olingo.server.api.uri.queryoption.expression.Expression expr = getKeyPredicateExpression(key, odata, column);
        return new CompareCriteria(new ElementSymbol(column.getName(), resource.getGroupSymbol()), CompareCriteria.EQ, visitor.getExpression(expr));
    }
    // complex (multi-keyed)
    List<Criteria> critList = new ArrayList<Criteria>();
    if (pk.size() != resource.getKeyPredicates().size()) {
        throw new TeiidException(ODataPlugin.Event.TEIID16015, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16015, resource.getTable().getFullName()));
    }
    for (UriParameter key : resource.getKeyPredicates()) {
        Column column = findColumn(resource.getTable(), key.getName());
        ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(resource, false, uriInfo, store, odata, nameGenerator, null, parseService);
        org.apache.olingo.server.api.uri.queryoption.expression.Expression expr = getKeyPredicateExpression(key, odata, column);
        critList.add(new CompareCriteria(new ElementSymbol(column.getName(), resource.getGroupSymbol()), CompareCriteria.EQ, visitor.getExpression(expr)));
    }
    return new CompoundCriteria(CompoundCriteria.AND, critList);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList) TeiidException(org.teiid.core.TeiidException) ProjectedColumn(org.teiid.olingo.ProjectedColumn) Column(org.teiid.metadata.Column) UriParameter(org.apache.olingo.server.api.uri.UriParameter)

Example 84 with TeiidException

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

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(UriResourceNavigation info) {
    try {
        DocumentNode navigationResource = DocumentNode.build((EdmEntityType) info.getType(), info.getKeyPredicates(), this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService);
        Query query = new Query();
        query.setSelect(new Select(Arrays.asList(new AggregateSymbol(AggregateSymbol.Type.COUNT.name(), false, null))));
        query.setFrom(new From(Arrays.asList(navigationResource.getFromClause())));
        Criteria criteria = this.ctxQuery.buildJoinCriteria(navigationResource, info.getProperty());
        if (criteria == null) {
            throw new TeiidException(ODataPlugin.Event.TEIID16037, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16037));
        }
        query.setCriteria(criteria);
        this.stack.add(new ScalarSubquery(query));
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 85 with TeiidException

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

the class TeiidServiceHandler method updateEntity.

@Override
public void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
    // TODO: need to match entityETag.
    checkETag(entityETag);
    UpdateResponse updateResponse = null;
    if (merge) {
        try {
            ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            visitor.visit(request.getUriInfo());
            EdmEntityType entityType = request.getEntitySet().getEntityType();
            Update update = visitor.update(entityType, entity, this.prepared);
            updateResponse = getClient().executeUpdate(update, visitor.getParameters());
        } catch (SQLException e) {
            throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
        } catch (TeiidException e) {
            throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
        }
    } else {
        // delete, then insert
        String txn = startTransaction();
        boolean success = false;
        try {
            // build insert first as it could fail to validate
            ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            visitor.visit(request.getUriInfo());
            EdmEntityType entityType = request.getEntitySet().getEntityType();
            List<UriParameter> keys = request.getKeyPredicates();
            Insert command = visitor.insert(entityType, entity, keys, this.prepared);
            // run delete
            ODataSQLBuilder deleteVisitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
            deleteVisitor.visit(request.getUriInfo());
            Delete delete = deleteVisitor.delete();
            updateResponse = getClient().executeUpdate(delete, deleteVisitor.getParameters());
            // run insert
            updateResponse = getClient().executeUpdate(command, visitor.getParameters());
            commit(txn);
            success = true;
        } catch (SQLException e) {
            throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
        } catch (TeiidException e) {
            throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
        } finally {
            if (!success) {
                rollback(txn);
            }
        }
    }
    if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
        response.writeUpdatedEntity();
    } else {
        response.writeNotModified();
    }
}
Also used : Delete(org.teiid.query.sql.lang.Delete) SQLException(java.sql.SQLException) EdmEntityType(org.apache.olingo.commons.api.edm.EdmEntityType) Update(org.teiid.query.sql.lang.Update) Insert(org.teiid.query.sql.lang.Insert) ODataApplicationException(org.apache.olingo.server.api.ODataApplicationException) TeiidException(org.teiid.core.TeiidException) UpdateResponse(org.teiid.odata.api.UpdateResponse) UriParameter(org.apache.olingo.server.api.uri.UriParameter)

Aggregations

TeiidException (org.teiid.core.TeiidException)85 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)26 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)13 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 SQLException (java.sql.SQLException)9 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)8 BigInteger (java.math.BigInteger)6 Column (org.teiid.metadata.Column)6 Command (org.teiid.query.sql.lang.Command)6 TranslatorException (org.teiid.translator.TranslatorException)6 IOException (java.io.IOException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 List (java.util.List)4 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)4 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 UpdateResponse (org.teiid.odata.api.UpdateResponse)4 Update (org.teiid.query.sql.lang.Update)4 SocketTimeoutException (java.net.SocketTimeoutException)3