mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-9298: Add @MappedSuperClass support for persistence inheritance
This commit is contained in:
parent
db54b26fed
commit
9857f41d9a
|
|
@ -38,10 +38,12 @@ import javax.persistence.Embedded;
|
|||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.SecondaryTable;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.db.Attribute.Flag;
|
||||
|
|
@ -54,6 +56,7 @@ public class SqlGenerator {
|
|||
LinkedHashMap<String, List<Attribute>> _ids;
|
||||
HashMap<String, TableGenerator> _generators;
|
||||
ArrayList<Attribute> _ecAttrs;
|
||||
Field[] _mappedSuperclassFields;
|
||||
|
||||
public SqlGenerator(Class<?> clazz) {
|
||||
_clazz = clazz;
|
||||
|
|
@ -91,6 +94,12 @@ public class SqlGenerator {
|
|||
|
||||
protected void buildAttributes(Class<?> clazz, String tableName, AttributeOverride[] overrides, boolean embedded, boolean isId) {
|
||||
if (!embedded && clazz.getAnnotation(Entity.class) == null) {
|
||||
// A class designated with the MappedSuperclass annotation can be mapped in the same way as an entity
|
||||
// except that the mappings will apply only to its subclasses since no table exists for the mapped superclass itself
|
||||
if (clazz.getAnnotation(MappedSuperclass.class) != null){
|
||||
Field[] declaredFields = clazz.getDeclaredFields();
|
||||
_mappedSuperclassFields = (Field[]) ArrayUtils.addAll(_mappedSuperclassFields, declaredFields);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +114,8 @@ public class SqlGenerator {
|
|||
}
|
||||
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
fields = (Field[]) ArrayUtils.addAll(fields, _mappedSuperclassFields);
|
||||
_mappedSuperclassFields = null;
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,13 +16,21 @@
|
|||
// under the License.
|
||||
package com.cloud.api.query.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import com.cloud.server.ResourceTag.ResourceObjectType;
|
||||
|
||||
public abstract class BaseViewWithTagInformationVO extends BaseViewVO {
|
||||
@MappedSuperclass
|
||||
public abstract class BaseViewWithTagInformationVO extends BaseViewVO implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private long id;
|
||||
|
||||
@Column(name = "tag_id")
|
||||
private long tagId;
|
||||
|
|
@ -168,4 +176,8 @@ public abstract class BaseViewWithTagInformationVO extends BaseViewVO {
|
|||
this.tagDomainName = tagDomainName;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import javax.persistence.Column;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
|
@ -41,10 +40,6 @@ import com.cloud.utils.db.GenericDao;
|
|||
@Table(name = "template_view")
|
||||
public class TemplateJoinVO extends BaseViewWithTagInformationVO implements ControlledViewEntity {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private long id;
|
||||
|
||||
@Column(name = "uuid")
|
||||
private String uuid;
|
||||
|
||||
|
|
@ -227,11 +222,6 @@ public class TemplateJoinVO extends BaseViewWithTagInformationVO implements Cont
|
|||
public TemplateJoinVO() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import java.net.URI;
|
|||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
|
|
@ -39,6 +40,7 @@ import com.cloud.vm.VirtualMachine.State;
|
|||
|
||||
@Entity
|
||||
@Table(name = "user_vm_view")
|
||||
@AttributeOverride( name="id", column = @Column(name = "id", updatable = false, nullable = false) )
|
||||
public class UserVmJoinVO extends BaseViewWithTagInformationVO implements ControlledViewEntity {
|
||||
|
||||
@Id
|
||||
|
|
@ -372,11 +374,6 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
|
|||
public UserVmJoinVO() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
|
|
@ -793,7 +790,7 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
|
|||
@Override
|
||||
public String toString() {
|
||||
if (toString == null) {
|
||||
toString = new StringBuilder("VM[").append(id).append("|").append(name).append("]").toString();
|
||||
toString = new StringBuilder("VM[").append(getId()).append("|").append(name).append("]").toString();
|
||||
}
|
||||
return toString;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import javax.persistence.Column;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
|
@ -38,10 +37,6 @@ import com.cloud.vm.VirtualMachine;
|
|||
@Table(name = "volume_view")
|
||||
public class VolumeJoinVO extends BaseViewWithTagInformationVO implements ControlledViewEntity {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private long id;
|
||||
|
||||
@Column(name = "uuid")
|
||||
private String uuid;
|
||||
|
||||
|
|
@ -263,11 +258,6 @@ public class VolumeJoinVO extends BaseViewWithTagInformationVO implements Contro
|
|||
public VolumeJoinVO() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
|
|
|
|||
Loading…
Reference in New Issue