@@ -0,0 +1,3287 @@
+/*%0A * Copyright 2015, TeamDev Ltd. All rights reserved.%0A *%0A * Redistribution and use in source and/or binary forms, with or without%0A * modification, must retain the above copyright notice and the following%0A * disclaimer.%0A *%0A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS%0A * %22AS IS%22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT%0A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR%0A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT%0A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,%0A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT%0A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,%0A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY%0A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT%0A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE%0A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A */%0A%0Apackage org.spine3.server.storage.datastore.newapi;%0A%0Aimport com.google.cloud.datastore.*;%0Aimport com.google.common.collect.Lists;%0A%0Aimport java.util.List;%0A%0Aimport static com.google.common.base.Preconditions.checkState;%0A%0A/**%0A * @author Dmytro Dashenkov%0A */%0Apublic class DatastoreWrapper %7B%0A%0A    private static final String ACTIVE_TRANSACTION_CONDITION_MESSAGE = %22Transaction should be active.%22;%0A    private static final String NOT_ACTIVE_TRANSACTION_CONDITION_MESSAGE = %22Transaction should NOT be active.%22;%0A    private final Datastore datastore;%0A    private Transaction activeTransaction;%0A    private DatastoreReaderWriter actor;%0A%0A    /*package*/ DatastoreWrapper(Datastore datastore) %7B%0A        this.datastore = datastore;%0A        this.actor = this.datastore;%0A    %7D%0A%0A    void create(Entity entity) %7B%0A        actor.put(entity);%0A    %7D%0A%0A    void update(Entity entity) %7B%0A        actor.update(entity);%0A    %7D%0A%0A    void createOrUpdate(Entity entity) %7B%0A        try %7B%0A            create(entity);%0A        %7D catch (DatastoreException ignored) %7B%0A            update(entity);%0A        %7D%0A    %7D%0A%0A    Entity read(Key key) %7B%0A        return datastore.get(key);%0A    %7D%0A%0A    // TODO:18-10-16:dmytro.dashenkov: Check datastore#fetch usage.%0A    List%3CEntity%3E read(Iterable%3CKey%3E keys) %7B%0A        return Lists.newArrayList(datastore.get(keys));%0A    %7D%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    List%3CEntity%3E read(Query query) %7B%0A        final QueryResults results = actor.run(query);%0A        return Lists.newArrayList(results);%0A    %7D%0A%0A    void delete(Key... keys) %7B%0A        actor.delete(keys);%0A    %7D%0A%0A    void startTransaction() %7B%0A        checkState(!isTransactionActive(), NOT_ACTIVE_TRANSACTION_CONDITION_MESSAGE);%0A        activeTransaction = datastore.newTransaction();%0A        actor = activeTransaction;%0A    %7D%0A%0A    void commitTransaction() %7B%0A        checkState(isTransactionActive(), ACTIVE_TRANSACTION_CONDITION_MESSAGE);%0A        activeTransaction.commit();%0A        actor = datastore;%0A    %7D%0A%0A    void rollbackTransaction() %7B%0A        checkState(isTransactionActive(), ACTIVE_TRANSACTION_CONDITION_MESSAGE);%0A        activeTransaction.rollback();%0A        actor = datastore;%0A    %7D%0A%0A    private boolean isTransactionActive() %7B%0A        return activeTransaction != null && activeTransaction.active();%0A    %7D%0A%7D%0A

Add DatastoreWrapper for new API.