2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.translate.spi.write;
19 import com.google.common.annotations.Beta;
20 import io.fd.honeycomb.translate.write.WriteContext;
21 import io.fd.honeycomb.translate.write.WriteFailedException;
22 import javax.annotation.Nonnull;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 * CompositeChildWriter SPI to customize its behavior.
29 * @param <D> Specific DataObject derived type (Identifiable), that is handled by this customizer.
32 public interface WriterCustomizer<D extends DataObject> {
35 * Handle write operation. C from CRUD.
37 * @param id Identifier(from root) of data being written
38 * @param dataAfter New data to be written
39 * @param writeContext Write context can be used to store any useful information and then utilized by other customizers
41 * @throws WriteFailedException if write was unsuccessful
43 void writeCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
44 @Nonnull final D dataAfter,
45 @Nonnull final WriteContext writeContext) throws WriteFailedException;
48 * Handle update operation. U from CRUD.
49 * By default, updates will be broken into delete + create.
50 * Override this if there is a direct support for updates on lower level.
52 * @param id Identifier(from root) of data being written
53 * @param dataBefore Old data
54 * @param dataAfter New, updated data
55 * @param writeContext Write context can be used to store any useful information and then utilized by other customizers
57 * @throws WriteFailedException if update was unsuccessful
59 default void updateCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
60 @Nonnull final D dataBefore,
61 @Nonnull final D dataAfter,
62 @Nonnull final WriteContext writeContext) throws WriteFailedException {
63 throw new UnsupportedOperationException(
64 "Default implementation of updateCurrentAttributes should not be invoked." +
65 "Either override this method or do not invoke it directly");
69 * Handle delete operation. D from CRUD.
71 * @param id Identifier(from root) of data being written
72 * @param dataBefore Old data being deleted
73 * @param writeContext Write context can be used to store any useful information and then utilized by other customizers
75 * @throws WriteFailedException if delete was unsuccessful
77 void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
78 @Nonnull final D dataBefore,
79 @Nonnull final WriteContext writeContext) throws WriteFailedException;