All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zuunr.restbed.repository.sqlserver.ReactiveSqlServerRepository Maven / Gradle / Ivy

There is a newer version: 1.0.0.M7-59f711a
Show newest version
/*
 * Copyright 2018 Zuunr AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zuunr.restbed.repository.sqlserver;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.zuunr.json.JsonObjectSupport;
import com.zuunr.restbed.core.exchange.Collection;
import com.zuunr.restbed.core.exchange.Exchange;
import com.zuunr.restbed.repository.ReactiveRepository;
import com.zuunr.restbed.repository.sqlserver.impl.DeleteItem;
import com.zuunr.restbed.repository.sqlserver.impl.GetCollection;
import com.zuunr.restbed.repository.sqlserver.impl.GetItem;
import com.zuunr.restbed.repository.sqlserver.impl.SaveItem;
import com.zuunr.restbed.repository.sqlserver.impl.UpdateItem;

import reactor.core.publisher.Mono;

/**
 * SQLServer implementation of {@link ReactiveRepository}.
 * 
 * @see ReactiveRepository
 */
public abstract class ReactiveSqlServerRepository implements ReactiveRepository {

    private final Logger logger = LoggerFactory.getLogger(ReactiveSqlServerRepository.class);

    private @Autowired SaveItem saveItem;
    private @Autowired GetItem getItem;
    private @Autowired UpdateItem updateItem;
    private @Autowired DeleteItem deleteItem;
    private @Autowired GetCollection getCollection;

    @Override
    public Mono> saveItem(Mono> exchange, Class resourceClass) {
        if (logger.isDebugEnabled()) {
            logger.debug("Calling save item with exchange for resource: {}", resourceClass.getName());
        }

        return exchange.flatMap(o -> saveItem.saveItem(o, resourceClass));
    }

    @Override
    public Mono> getItem(Mono> exchange, Class resourceClass) {
        if (logger.isDebugEnabled()) {
            logger.debug("Calling get item with exchange for resource: {}", resourceClass.getName());
        }

        return exchange.flatMap(o -> getItem.getItem(o, resourceClass));
    }

    @Override
    public Mono> updateItem(Mono> exchange, Class resourceClass) {
        if (logger.isDebugEnabled()) {
            logger.debug("Calling update item with exchange for resource: {}", resourceClass.getName());
        }

        return exchange.flatMap(o -> updateItem.updateItem(o, resourceClass));
    }

    @Override
    public Mono> deleteItem(Mono> exchange) {
        if (logger.isDebugEnabled()) {
            logger.debug("Calling delete item with exchange");
        }

        return exchange.flatMap(deleteItem::deleteItem);
    }

    @Override
    public Mono>> getCollection(Mono>> exchange, Class resourceClass) {
        if (logger.isDebugEnabled()) {
            logger.debug("Calling get collection with exchange for resource: {}", resourceClass.getName());
        }

        return exchange.flatMap(o -> getCollection.getCollection(o, resourceClass));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy