| /******************************************************************************** |
| * Copyright (c) 2015-2019 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| ********************************************************************************/ |
| |
| package org.eclipse.mdm.api.atfxadapter.transaction; |
| |
| import java.io.IOException; |
| import java.util.Collection; |
| |
| import org.asam.ods.AoException; |
| import org.asam.ods.ApplElemAccess; |
| import org.eclipse.mdm.api.base.ServiceNotProvidedException; |
| import org.eclipse.mdm.api.base.adapter.EntityType; |
| import org.eclipse.mdm.api.base.model.Entity; |
| import org.eclipse.mdm.api.base.query.DataAccessException; |
| import org.eclipse.mdm.api.base.query.QueryService; |
| import org.eclipse.mdm.api.odsadapter.query.ODSEntityType; |
| import org.eclipse.mdm.api.odsadapter.query.ODSModelManager; |
| |
| /** |
| * A base implementation for execution statements (CREATE, UPDATE, DELETE). |
| * |
| * @see org.eclipse.mdm.api.odsadapter.transaction.BaseStatement |
| */ |
| abstract class BaseStatement { |
| |
| private final ATFXTransaction transaction; |
| private final ODSEntityType entityType; |
| |
| /** |
| * Constructor. |
| * |
| * @param transaction The owning {@link ATFXTransaction}. |
| * @param entityType The associated {@link EntityType}. |
| */ |
| protected BaseStatement(ATFXTransaction transaction, EntityType entityType) { |
| this.transaction = transaction; |
| this.entityType = (ODSEntityType) entityType; |
| } |
| |
| /** |
| * Executes this statement for given {@link Entity}s. |
| * |
| * @param entities The processed {@code Entity}s. |
| * @throws AoException Thrown if the execution fails. |
| * @throws DataAccessException Thrown if the execution fails. |
| * @throws IOException Thrown if a file transfer operation fails. |
| */ |
| public abstract void execute(Collection<Entity> entities) throws AoException, DataAccessException, IOException; |
| |
| /** |
| * Returns the {@link ATFXTransaction}. |
| * |
| * @return The {@code ODSTransaction} is returned. |
| */ |
| protected ATFXTransaction getTransaction() { |
| return transaction; |
| } |
| |
| /** |
| * Returns the {@link ODSModelManager}. |
| * |
| * @return The {@code ODSModelManager} is returned. |
| */ |
| protected ODSModelManager getModelManager() { |
| return transaction.getModelManager(); |
| } |
| |
| /** |
| * Returns the {@link QueryService}. |
| * |
| * @return The {@code QueryService} is returned. |
| */ |
| protected QueryService getQueryService() { |
| return transaction.getContext().getQueryService() |
| .orElseThrow(() -> new ServiceNotProvidedException(QueryService.class)); |
| } |
| |
| /** |
| * Returns the {@link ApplElemAccess}. |
| * |
| * @return The {@code ApplElemAccess} is returned. |
| * @throws AoException Thrown in case of errors. |
| */ |
| protected ApplElemAccess getApplElemAccess() throws AoException { |
| return transaction.getContext().getODSModelManager().getApplElemAccess(); |
| } |
| |
| /** |
| * Returns the associated {@link EntityType}. |
| * |
| * @return The associated {@code EntityType} is returned. |
| */ |
| protected ODSEntityType getEntityType() { |
| return entityType; |
| } |
| |
| } |