Create Base view VO object to remove some code duplication.

This commit is contained in:
Min Chen 2012-12-10 11:21:01 -08:00 committed by Rohit Yadav
parent e398b1e47a
commit 9a3632d807
6 changed files with 49 additions and 156 deletions

View File

@ -0,0 +1,44 @@
package org.apache.cloudstack.api.view.vo;
import javax.persistence.Column;
/**
* Base class for all VO objects for db views.
* @author minc
*
*/
public abstract class BaseViewVO {
@Column(name="id", updatable=false, nullable = false)
protected long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BaseViewVO other = (BaseViewVO) obj;
if (id != other.id)
return false;
return true;
}
}

View File

@ -33,10 +33,8 @@ import com.cloud.vm.VirtualMachine.State;
@Entity
@Table(name="domain_router_view")
public class DomainRouterJoinVO implements ControlledViewEntity {
public class DomainRouterJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@Column(name="name", updatable=false, nullable=false, length=255)
private String name = null;
@ -239,15 +237,6 @@ public class DomainRouterJoinVO implements ControlledViewEntity {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
@ -902,27 +891,4 @@ public class DomainRouterJoinVO implements ControlledViewEntity {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DomainRouterJoinVO other = (DomainRouterJoinVO) obj;
if (id != other.id)
return false;
return true;
}
}

View File

@ -29,10 +29,7 @@ import com.cloud.event.Event.State;
@Entity
@Table(name="event_view")
public class EventJoinVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
public class EventJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="uuid")
private String uuid;
@ -115,14 +112,6 @@ public class EventJoinVO implements ControlledViewEntity {
this.uuid = uuid;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Override
public long getAccountId() {
@ -307,25 +296,5 @@ public class EventJoinVO implements ControlledViewEntity {
this.parameters = parameters;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
EventJoinVO other = (EventJoinVO) obj;
if (id != other.id)
return false;
return true;
}
}

View File

@ -26,10 +26,8 @@ import com.cloud.server.ResourceTag.TaggedResourceType;
@Entity
@Table(name="resource_tag_view")
public class ResourceTagJoinVO implements ControlledViewEntity {
public class ResourceTagJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@Column(name="uuid")
private String uuid;
@ -41,7 +39,6 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
String value;
@Column(name="resource_id")
long resourceId;
@ -260,25 +257,5 @@ public class ResourceTagJoinVO implements ControlledViewEntity {
this.customer = customer;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ResourceTagJoinVO other = (ResourceTagJoinVO) obj;
if (id != other.id)
return false;
return true;
}
}

View File

@ -27,10 +27,7 @@ import com.cloud.server.ResourceTag.TaggedResourceType;
@Entity
@Table(name="security_group_view")
public class SecurityGroupJoinVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
public class SecurityGroupJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="name")
private String name;
@ -149,13 +146,6 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.uuid = uuid;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
@ -443,25 +433,5 @@ public class SecurityGroupJoinVO implements ControlledViewEntity {
this.tagCustomer = tagCustomer;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SecurityGroupJoinVO other = (SecurityGroupJoinVO) obj;
if (id != other.id)
return false;
return true;
}
}

View File

@ -40,10 +40,8 @@ import com.cloud.vm.VirtualMachine.State;
@Entity
@Table(name="user_vm_view")
public class UserVmJoinVO implements ControlledViewEntity {
public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@Column(name="name", updatable=false, nullable=false, length=255)
private String name = null;
@ -388,15 +386,6 @@ public class UserVmJoinVO implements ControlledViewEntity {
this.password = password;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
@ -1598,26 +1587,4 @@ public class UserVmJoinVO implements ControlledViewEntity {
return toString;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
UserVmJoinVO other = (UserVmJoinVO) obj;
if (id != other.id)
return false;
return true;
}
}