no.dusken.barweb.service.impl.InvoiceTransaksjonServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for no.dusken.barweb.service.impl.InvoiceTransaksjonServiceImpl.java

Source

/*
 Copyright 2009 - 2010 Under Dusken
    
 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 no.dusken.barweb.service.impl;

import no.dusken.barweb.model.Invoice;
import no.dusken.barweb.model.Transaksjon;
import no.dusken.barweb.service.InvoiceService;
import no.dusken.barweb.service.InvoiceTransaksjonService;
import no.dusken.barweb.service.TransaksjonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Marvin B. Lillehaug <lillehau@underdusken.no>
 */
@Service("invoiceTransaksjonService")
@Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT, readOnly = true)
public class InvoiceTransaksjonServiceImpl implements InvoiceTransaksjonService {

    @Autowired
    private InvoiceService invoiceService;

    @Autowired
    private TransaksjonService transaksjonService;

    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
    public Invoice saveInvoiceAndTransaksjons(Invoice invoice, List<Transaksjon> transaksjons) {
        //  invoice = invoiceService.save(invoice);
        for (Transaksjon t : transaksjons) {
            t.setInvoice(invoice);
        }
        transaksjonService.save(transaksjons);
        return invoice;
    }

    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
    public void deleteInvoiceUpdateTransaksjons(Invoice invoice, List<Transaksjon> transaksjons) {
        for (Transaksjon t : transaksjons) {
            t.setInvoice(null);
            transaksjonService.save(t);
        }
        invoiceService.delete(invoice);
    }
}