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

com.manywho.sdk.services.database.DatabaseDeleteService Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package com.manywho.sdk.services.database;

import com.manywho.sdk.api.run.elements.type.ObjectDataRequest;
import com.manywho.sdk.api.run.elements.type.ObjectDataResponse;
import com.manywho.sdk.services.configuration.ConfigurationParser;
import com.manywho.sdk.services.types.Type;
import com.manywho.sdk.services.values.ValueParser;

import javax.inject.Inject;

public class DatabaseDeleteService implements DatabaseService {
    private final ConfigurationParser configurationParser;
    private final ValueParser valueParser;

    @Inject
    public DatabaseDeleteService(ConfigurationParser configurationParser, ValueParser valueParser) {
        this.configurationParser = configurationParser;
        this.valueParser = valueParser;
    }

    public  ObjectDataResponse handle(ObjectDataRequest request, Class type, WritableDatabase database) {
        if (request.getObjectData() == null) {
            return new ObjectDataResponse();
        }

        if (request.getObjectData().size() == 1) {
            database.delete(configurationParser.from(request), valueParser.asObject(request.getObjectData(), type));
        } else {
            database.delete(configurationParser.from(request), valueParser.asList(request.getObjectData(), type));
        }

        return new ObjectDataResponse();
    }

    @Override
    public ObjectDataResponse handleRaw(ObjectDataRequest request, RawDatabase database) {
        if (request.getObjectData() == null) {
            return new ObjectDataResponse();
        }

        if (request.getObjectData().size() == 1) {
            database.delete(configurationParser.from(request), request.getObjectData().get(0));
        } else {
            database.delete(configurationParser.from(request), request.getObjectData());
        }

        return new ObjectDataResponse();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy