X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fapi%2FWriteOperations.java;h=b054d43f7bd0f14f9e8f19ef2122d9ca4510b4e1;hb=94fb90ab450470ee1b3225d737cd394f034ea932;hp=2bc0be80625a18e8aa1bfe404c89c0e740b31ca6;hpb=a10c289bba4f28edb60fd555ee6d0f69cadd5c5f;p=mdsal.git diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/WriteOperations.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/WriteOperations.java index 2bc0be8062..b054d43f7b 100644 --- a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/WriteOperations.java +++ b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/WriteOperations.java @@ -7,8 +7,10 @@ */ package org.opendaylight.mdsal.binding.api; +import com.google.common.util.concurrent.FluentFuture; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.TransactionDatastoreMismatchException; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -22,83 +24,120 @@ public interface WriteOperations { * whole subtree will be replaced by the specified data. * *

- * This method does not automatically create missing parent nodes. It is equivalent to invoking - * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)} - * with createMissingParents set to false. - * - *

- * If you need to make sure that a parent object exists but you do not want modify - * its pre-existing state by using put, consider using {@link #merge} instead. + * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using + * put, consider using {@link #merge} instead. * * @param store the logical data store which should be modified * @param path the data object path * @param data the data object to be written to the specified path * @throws IllegalStateException if the transaction has already been submitted - * @throws NullPointerException if any of the arguments is null + * @throws NullPointerException if any of the arguments is {@code null} + * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store */ void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier path, @NonNull T data); /** * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole - * subtree will be replaced by the specified data. + * subtree will be replaced by the specified data. Unlike + * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create + * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}. * *

* If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using * put, consider using {@link #merge} instead. * *

- * Note: Using createMissingParents with value true, may introduce garbage in data store, or recreate - * nodes, which were deleted by previous transaction. + * WARNING: Using this method may introduce garbage in data store, or recreate nodes, which were deleted by + * a previous transaction. It also has a significantly higher cost than + * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} and should only be used when + * absolutely necessary. * * @param store the logical data store which should be modified * @param path the data object path * @param data the data object to be written to the specified path - * @param createMissingParents if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically - * created using a merge operation. * @throws IllegalStateException if the transaction has already been submitted - * @throws NullPointerException if any of the arguments is null + * @throws NullPointerException if any of the arguments is {@code null} + * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store + * @deprecated Use of this method is a manifestation of bad lifecycle management: it attempts to create data tree + * parent nodes which may have semantic meaning without assigning responsibility. The datastore handles + * all the cases which do not attach semantics, such as {@code container}s without {@code presence}, + * {@code augmentation} and {@code list} encapsulation. + * This method does not work in the general case, where there are: + *

+ * Based on this analysis, all users of this method need to be migrated to have a proper lifecycle + * relationship with entities responsible for managing such semantic items which are created by this + * method. */ - void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier path, - @NonNull T data, boolean createMissingParents); + @Deprecated(since = "11.0.3") + void mergeParentStructurePut(@NonNull LogicalDatastoreType store, + @NonNull InstanceIdentifier path, @NonNull T data); /** * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly * overwritten will be preserved. This means that if you store a container, its child lists will be merged. * *

- * This method does not automatically create missing parent nodes. It is equivalent to invoking - * {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)} - * with createMissingParents set to false. - * - *

* If you require an explicit replace operation, use {@link #put} instead. + * * @param store the logical data store which should be modified * @param path the data object path * @param data the data object to be merged to the specified path * @throws IllegalStateException if the transaction has already been submitted - * @throws NullPointerException if any of the arguments is null + * @throws NullPointerException if any of the arguments is {@code null} + * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store */ void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier path, @NonNull T data); /** * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly - * overwritten will be preserved. This means that if you store a container, its child lists will be merged. + * overwritten will be preserved. This means that if you store a container, its child lists will be merged. Unlike + * {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create + * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}. * *

* If you require an explicit replace operation, use {@link #put} instead. * + *

+ * WARNING: Using this method may introduce garbage in data store, or recreate nodes, which were deleted by + * a previous transaction. It is not necessary in most scenarios and has a significantly higher cost + * than {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}. It should only be used + * when absolutely necessary. + * * @param store the logical data store which should be modified * @param path the data object path * @param data the data object to be merged to the specified path - * @param createMissingParents if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically - * created using a merge operation. * @throws IllegalStateException if the transaction has already been submitted - * @throws NullPointerException if any of the arguments is null + * @throws NullPointerException if any of the arguments is {@code null} + * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store + * @deprecated Use of this method is a manifestation of bad lifecycle management: it attempts to create data tree + * parent nodes which may have semantic meaning without assigning responsibility. The datastore handles + * all the cases which do not attach semantics, such as {@code container}s without {@code presence}, + * {@code augmentation} and {@code list} encapsulation. + * This method does not work in the general case, where there are: + *

    + *
  • {@code container} parents with {@code presence}, as these form a {@code mandatory} enforcement + * boundary. We cannot infer the mandatory nodes from {@code path} and hence we may end up wanting + * to create an invalid structure
  • + *
  • {@code list} parents with {@code unique} encompassing other leaves than {@code key}. While we + * can re-create the key {@code leaf} items, we have no way of constructing of {@code unique} + * requirements.
  • + *
+ * Based on this analysis, all users of this method need to be migrated to have a proper lifecycle + * relationship with entities responsible for managing such semantic items which are created by this + * method. */ - void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier path, - @NonNull T data, boolean createMissingParents); + @Deprecated(since = "11.0.3") + void mergeParentStructureMerge(@NonNull LogicalDatastoreType store, + @NonNull InstanceIdentifier path, @NonNull T data); /** * Removes a piece of data from specified path. This operation does not fail if the specified path does not exist. @@ -106,16 +145,15 @@ public interface WriteOperations { * @param store Logical data store which should be modified * @param path Data object path * @throws IllegalStateException if the transaction was committed or canceled. + * @throws NullPointerException if any of the arguments is {@code null} + * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store */ void delete(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier path); /** - * Flag value indicating that missing parents should be created. - */ - boolean CREATE_MISSING_PARENTS = true; - - /** - * Flag value indicating that missing parents should cause an error. + * Return a {@link FluentFuture} which completes. + * + * @return A future which completes when the requested operations complete. */ - boolean FAIL_ON_MISSING_PARENTS = false; + @NonNull FluentFuture completionFuture(); }