@Test @SuppressWarnings("unchecked") public void testPutIfNotExists() throws Exception { InstanceIdentifier path = InstanceIdentifier.create(SxpNodeIdentity.class); ReadTransaction readTransaction = mock(ReadTransaction.class); WriteTransaction writeTransaction = mock(WriteTransaction.class); when(transactionChain.newReadOnlyTransaction()).thenReturn(readTransaction); when(transactionChain.newWriteOnlyTransaction()).thenReturn(writeTransaction); when(readTransaction.read(eq(LogicalDatastoreType.CONFIGURATION), eq(path))) .thenReturn(FluentFutures.immediateFluentFuture(Optional.empty())); when(writeTransaction.commit()).thenReturn(FluentFutures.immediateNullFluentFuture()); Assert.assertTrue(access.checkAndPut( path, mock(DataObject.class), LogicalDatastoreType.CONFIGURATION, false)); }
public synchronized <T extends DataObject> boolean putIfNotExists( final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType) { LOG.debug("Put if not exist {}", identifier); if (readSynchronous(identifier, datastoreType) != null) { LOG.warn("Node to be created {} has already exist", identifier); return false; } return putSynchronous(identifier, data, datastoreType); }
DatastoreAccess implements AutoCloseable { public synchronized <T extends DataObject> boolean putIfNotExists( final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType) { LOG.debug("Put if not exist {}", identifier); if (readSynchronous(identifier, datastoreType) != null) { LOG.warn("Node to be created {} has already exist", identifier); return false; } return putSynchronous(identifier, data, datastoreType); } }
DatastoreAccess implements AutoCloseable { public synchronized <T extends DataObject> boolean putIfNotExists( final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType) { LOG.debug("Put if not exist {}", identifier); if (readSynchronous(identifier, datastoreType) != null) { LOG.warn("Node to be created {} has already exist", identifier); return false; } return putSynchronous(identifier, data, datastoreType); } private  DatastoreAccess(final DataBroker dataBroker); }
DatastoreAccess implements AutoCloseable { public synchronized <T extends DataObject> boolean putIfNotExists( final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType) { LOG.debug("Put if not exist {}", identifier); if (readSynchronous(identifier, datastoreType) != null) { LOG.warn("Node to be created {} has already exist", identifier); return false; } return putSynchronous(identifier, data, datastoreType); } private  DatastoreAccess(final DataBroker dataBroker); static DatastoreAccess getInstance(final DataBroker dataBroker); static DatastoreAccess getInstance(final DatastoreAccess datastoreAccess); synchronized FluentFuture<? extends CommitInfo> delete(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized FluentFuture<? extends CommitInfo> merge(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized FluentFuture<? extends CommitInfo> put(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized FluentFuture<java.util.Optional<T>> read(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized boolean mergeSynchronous(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized boolean putSynchronous(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized boolean deleteSynchronous(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized T readSynchronous(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized boolean checkAndPut(
            final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType,
            final boolean isUpdating); synchronized boolean checkAndMerge(
            final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType,
            final boolean isUpdating); synchronized boolean checkAndDelete(
            final InstanceIdentifier<T> identifier, final LogicalDatastoreType datastoreType); synchronized boolean putIfNotExists(
            final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType); synchronized void reinitializeChain(); @Override synchronized void close(); }
DatastoreAccess implements AutoCloseable { public synchronized <T extends DataObject> boolean putIfNotExists( final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType) { LOG.debug("Put if not exist {}", identifier); if (readSynchronous(identifier, datastoreType) != null) { LOG.warn("Node to be created {} has already exist", identifier); return false; } return putSynchronous(identifier, data, datastoreType); } private  DatastoreAccess(final DataBroker dataBroker); static DatastoreAccess getInstance(final DataBroker dataBroker); static DatastoreAccess getInstance(final DatastoreAccess datastoreAccess); synchronized FluentFuture<? extends CommitInfo> delete(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized FluentFuture<? extends CommitInfo> merge(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized FluentFuture<? extends CommitInfo> put(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized FluentFuture<java.util.Optional<T>> read(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized boolean mergeSynchronous(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized boolean putSynchronous(
            final InstanceIdentifier<T> path, final T data, final LogicalDatastoreType logicalDatastoreType); synchronized boolean deleteSynchronous(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized T readSynchronous(
            final InstanceIdentifier<T> path, final LogicalDatastoreType logicalDatastoreType); synchronized boolean checkAndPut(
            final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType,
            final boolean isUpdating); synchronized boolean checkAndMerge(
            final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType,
            final boolean isUpdating); synchronized boolean checkAndDelete(
            final InstanceIdentifier<T> identifier, final LogicalDatastoreType datastoreType); synchronized boolean putIfNotExists(
            final InstanceIdentifier<T> identifier, final T data, final LogicalDatastoreType datastoreType); synchronized void reinitializeChain(); @Override synchronized void close();  }