private static final long serialVersionUID = 1L;
public static Hotel create() {
return new Hotel();
}
public enum Type { BUSINESS, LEISURE }
private String name;
private Date startDate;
private int stars;
private boolean takesCreditCards;
private Type type;
private Set<String> tags;
@Transient
private String temp;
@Embedded
private Address address;
@Embedded(concreteClass = java.util.Vector.class)
private List<PhoneNumber> phoneNumbers;
private Hotel() {
super();
tags = new HashSet<String>();
phoneNumbers = new Vector<PhoneNumber>();
}
/** The id for this instance */
@Id
protected String id = new ObjectId().toString();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getStars() {
return stars;
}
public void setStars(int stars) {
this.stars = stars;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public boolean isTakesCreditCards() {
return takesCreditCards;
}
public void setTakesCreditCards(boolean takesCreditCards) {
this.takesCreditCards = takesCreditCards;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public Set<String> getTags() {
return tags;
}
public void setTags(Set<String> tags) {
this.tags = tags;
}
public List<PhoneNumber> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
}
package com.easyway.mongodb.morphia.basic;
public enum PayforType {
network(0,"网络支付"),cash(1,"现金支付");
private int code;
private String desc;
private PayforType(int code,String name){
this.code=code;
this.desc=name;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
package com.easyway.mongodb.morphia.basic;
import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.Property;
/**
* Morphia支持枚举值的使用
*
* @Description:
* @Copyright:Copyright (c) 2011
* @Company:易程科技股份有限公司
* @Date:2012-3-2
* @author
* @version 1.0
*/
@Embedded
public class PhoneNumber {
public enum Type { PHONE, FAX }
@Property
private int countryCode;
@Property
private int localExtension;
@Property
private Type type;
public PhoneNumber() {
this.type = Type.PHONE;
}
public PhoneNumber( int countryCode, int localExtension, Type type ) {
this.countryCode = countryCode;
this.localExtension = localExtension;
this.type = type;
}
public int getCountryCode() {
return countryCode;
}
public void setCountryCode(int countryCode) {
this.countryCode = countryCode;
}
public int getLocalExtension() {
return localExtension;
}
public void setLocalExtension(int localExtension) {
this.localExtension = localExtension;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PhoneNumber other = (PhoneNumber) obj;
if (this.countryCode != other.countryCode) {
return false;
}
if (this.localExtension != other.localExtension) {
return false;
}
if (this.type != other.type) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 43 * hash + this.countryCode;
hash = 43 * hash + this.localExtension;
hash = 43 * hash + this.type.hashCode();
return hash;
}
}
package com.easyway.mongodb.morphia.basic;
import org.bson.types.ObjectId;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;
@Entity
public class RecursiveChild {
private static final long serialVersionUID = 1L;
/** The id for this instance */
@Id
protected String id = new ObjectId().toString();
private PayforType payforType;
private String name;
@Reference
private RecursiveParent parent;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public PayforType getPayforType() {
return payforType;
}
public void setPayforType(PayforType payforType) {
this.payforType = payforType;
}
package com.easyway.mongodb.morphia.basic;
import org.bson.types.ObjectId;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;
@Entity
public class RecursiveParent {
private static final long serialVersionUID = 1L;
private PayforType payforType;
@Reference
private RecursiveChild child;
/** The id for this instance */
@Id
protected String id = new ObjectId().toString();
public String getId() {
return id;
}
public PayforType getPayforType() {
return payforType;
}
public void setPayforType(PayforType payforType) {
this.payforType = payforType;
}
public void setId(String id) {
this.id = id;
}
public RecursiveParent() {
super();
}
public RecursiveChild getChild() {
return child;
}
public void setChild(RecursiveChild child) {
this.child = child;
}
}