Package org.locationtech.geogig.web.api.commands

Source Code of org.locationtech.geogig.web.api.commands.BeginTransaction

/* Copyright (c) 2013 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Kelsey Ishmael (LMN Solutions) - initial implementation
*/
package org.locationtech.geogig.web.api.commands;

import org.locationtech.geogig.api.GeoGIG;
import org.locationtech.geogig.api.GeogigTransaction;
import org.locationtech.geogig.api.plumbing.TransactionBegin;
import org.locationtech.geogig.web.api.AbstractWebAPICommand;
import org.locationtech.geogig.web.api.CommandContext;
import org.locationtech.geogig.web.api.CommandResponse;
import org.locationtech.geogig.web.api.CommandSpecException;
import org.locationtech.geogig.web.api.ResponseWriter;

/**
* The interface for the TransactionBegin operation in GeoGig.
*
* Web interface for {@link TransactionBegin}
*/

public class BeginTransaction extends AbstractWebAPICommand {

    /**
     * Runs the command and builds the appropriate response.
     *
     * @param context - the context to use for this command
     *
     * @throws CommandSpecException
     */
    @Override
    public void run(CommandContext context) {
        if (this.getTransactionId() != null) {
            throw new CommandSpecException("Tried to start a transaction within a transaction.");
        }
        final GeoGIG geogig = context.getGeoGIG();

        final GeogigTransaction transaction = geogig.command(TransactionBegin.class).call();

        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeTransactionId(transaction.getTransactionId());
                out.finish();
            }
        });
    }

}
TOP

Related Classes of org.locationtech.geogig.web.api.commands.BeginTransaction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.