EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
LoanRepository.java
1 /*******************************************************************************
2  * Copyright 2012 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package emlab.gen.repository;
17 
18 
19 import org.springframework.stereotype.Repository;
20 import org.springframework.transaction.annotation.Transactional;
21 
22 import com.tinkerpop.blueprints.pgm.Vertex;
23 import com.tinkerpop.pipes.Pipe;
24 
28 
29 
35 @Repository
36 public class LoanRepository extends AbstractRepository<Loan> {
37 
48  @Transactional
49  public Loan createLoan(DecarbonizationAgent from, DecarbonizationAgent to, double amount, long numberOfPayments, long loanStartTime, PowerPlant plant) {
50  Loan loan = new Loan().persist();
51  loan.setFrom(from);
52  loan.setTo(to);
53  loan.setAmountPerPayment(amount);
54  loan.setTotalNumberOfPayments(numberOfPayments);
55  loan.setRegardingPowerPlant(plant);
56  loan.setLoanStartTime(loanStartTime);
57  loan.setNumberOfPaymentsDone(0);
58  return loan;
59  }
60 
66  public Iterable<Loan> findLoansFromAgent(DecarbonizationAgent agent) {
67  Pipe<Vertex, Vertex> loansPipe = new LabeledEdgePipe("LEND_TO_AGENT", LabeledEdgePipe.Step.IN_OUT);
68  return findAllByPipe(agent, loansPipe);
69  }
70 
76  public Iterable<Loan> findLoansToAgent(DecarbonizationAgent agent) {
77  Pipe<Vertex, Vertex> loansPipe = new LabeledEdgePipe("LEND_BY_AGENT", LabeledEdgePipe.Step.IN_OUT);
78  return findAllByPipe(agent, loansPipe);
79  }
80 
81 }
Iterable< Loan > findLoansToAgent(DecarbonizationAgent agent)
Loan createLoan(DecarbonizationAgent from, DecarbonizationAgent to, double amount, long numberOfPayments, long loanStartTime, PowerPlant plant)
Iterable< Loan > findLoansFromAgent(DecarbonizationAgent agent)