001/* 002 * Copyright 2006-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.sample.domain.trade; 018 019import java.math.BigDecimal; 020 021import javax.persistence.Entity; 022import javax.persistence.Id; 023import javax.persistence.Table; 024 025@Entity 026@Table(name = "CUSTOMER") 027public class CustomerCredit { 028 029 @Id 030 private int id; 031 032 private String name; 033 034 private BigDecimal credit; 035 036 public CustomerCredit() { 037 } 038 039 public CustomerCredit(int id, String name, BigDecimal credit) { 040 this.id = id; 041 this.name = name; 042 this.credit = credit; 043 } 044 045 @Override 046 public String toString() { 047 return "CustomerCredit [id=" + id + ",name=" + name + ", credit=" + credit + "]"; 048 } 049 050 public BigDecimal getCredit() { 051 return credit; 052 } 053 054 public int getId() { 055 return id; 056 } 057 058 public void setId(int id) { 059 this.id = id; 060 } 061 062 public void setCredit(BigDecimal credit) { 063 this.credit = credit; 064 } 065 066 public String getName() { 067 return name; 068 } 069 070 public void setName(String name) { 071 this.name = name; 072 } 073 074 public CustomerCredit increaseCreditBy(BigDecimal sum) { 075 CustomerCredit newCredit = new CustomerCredit(); 076 newCredit.credit = this.credit.add(sum); 077 newCredit.name = this.name; 078 newCredit.id = this.id; 079 return newCredit; 080 } 081 082 @Override 083 public boolean equals(Object o) { 084 return (o instanceof CustomerCredit) && ((CustomerCredit) o).id == id; 085 } 086 087 @Override 088 public int hashCode() { 089 return id; 090 } 091 092}