Package org.apache.isis.objectstore.jdo.applib.service.background

Source Code of org.apache.isis.objectstore.jdo.applib.service.background.BackgroundCommandServiceJdo

/**
*  Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  See the NOTICE file distributed with
*  this work for additional information regarding copyright ownership.
*  The ASF licenses this file to You 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 org.apache.isis.objectstore.jdo.applib.service.background;

import java.util.UUID;

import javax.validation.executable.ExecutableType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.isis.applib.AbstractService;
import org.apache.isis.applib.annotation.Command.ExecuteIn;
import org.apache.isis.applib.annotation.Named;
import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.clock.Clock;
import org.apache.isis.applib.services.background.ActionInvocationMemento;
import org.apache.isis.applib.services.background.BackgroundCommandService;
import org.apache.isis.applib.services.command.Command;
import org.apache.isis.applib.services.command.Command.Executor;
import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode;
import org.apache.isis.objectstore.jdo.applib.service.command.CommandJdo;

@Named("Background Commands")
public class BackgroundCommandServiceJdo extends AbstractService implements BackgroundCommandService {

    @SuppressWarnings("unused")
    private static final Logger LOG = LoggerFactory.getLogger(BackgroundCommandServiceJdo.class);
   
    @Programmatic
    @Override
    public void schedule(
            final ActionInvocationMemento aim,
            final Command parentCommand,
            final String targetClassName,
            final String targetActionName,
            final String targetArgs) {
       
        final UUID transactionId = UUID.randomUUID();
        final String user = parentCommand.getUser();

        final CommandJdo backgroundCommand = newTransientInstance(CommandJdo.class);

        backgroundCommand.setParent(parentCommand);
       
        backgroundCommand.setTransactionId(transactionId);

        backgroundCommand.setUser(user);
        backgroundCommand.setTimestamp(Clock.getTimeAsJavaSqlTimestamp());

        backgroundCommand.setExecuteIn(ExecuteIn.BACKGROUND);

        backgroundCommand.setTargetClass(targetClassName);
        backgroundCommand.setTargetAction(targetActionName);
        backgroundCommand.setTargetStr(aim.getTarget().toString());
        backgroundCommand.setMemberIdentifier(aim.getActionId());

        backgroundCommand.setArguments(targetArgs);
        backgroundCommand.setMemento(aim.asMementoString());
       
        parentCommand.setPersistHint(true);
       
        persist(backgroundCommand);
    }

}
TOP

Related Classes of org.apache.isis.objectstore.jdo.applib.service.background.BackgroundCommandServiceJdo

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.