Java tutorial
/* * Copyright 2013 the original author or authors. * * 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 com.vladmihalcea.mongo.model; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Version; import org.springframework.data.mongodb.core.mapping.Document; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; /** * Product - Product document * * @author Vlad Mihalcea */ @Document public class Product implements Serializable { @Id() private Long _id; private String name; private BigDecimal price; private BigInteger quantity; private BigDecimal discount; @Version private Long version; public Long getId() { return _id; } public void setId(Long id) { this._id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } public BigInteger getQuantity() { return quantity; } public void setQuantity(BigInteger quantity) { this.quantity = quantity; } public BigDecimal getDiscount() { return discount; } public void setDiscount(BigDecimal discount) { this.discount = discount; } public Long getVersion() { return version; } public void setVersion(Long version) { this.version = version; } @Override public boolean equals(Object obj) { if (!(obj instanceof Product)) { return false; } Product that = (Product) obj; return new EqualsBuilder().append(_id, that._id).isEquals(); } @Override public int hashCode() { return new HashCodeBuilder().append(_id).hashCode(); } @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", _id).append("name", name) .toString(); } }