/* * Copyright (c) 2010-2013 Evolveum * * 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.evolveum.midpoint.repo.sql.data.common.container; import com.evolveum.midpoint.repo.sql.data.common.RObject; import com.evolveum.midpoint.repo.sql.data.common.id.RCObjectReferenceId; import com.evolveum.midpoint.repo.sql.data.common.other.RCReferenceOwner; import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType; import com.evolveum.midpoint.repo.sql.query.definition.JaxbType; import com.evolveum.midpoint.repo.sql.query2.definition.NotQueryable; import com.evolveum.midpoint.repo.sql.util.MidPointSingleTablePersister; import com.evolveum.midpoint.repo.sql.util.RUtil; import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; import org.hibernate.annotations.ForeignKey; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.Persister; import javax.persistence.*; /** * @author lazyman */ @JaxbType(type = ObjectReferenceType.class) @Entity @IdClass(RCObjectReferenceId.class) @Table(name = "m_assignment_reference", indexes = { @javax.persistence.Index(name = "iAssignmentReferenceTargetOid", columnList = "targetOid") }) @Persister(impl = MidPointSingleTablePersister.class) public class RAssignmentReference extends RContainerReference { private RAssignment owner; @ForeignKey(name = "fk_assignment_reference") @MapsId("owner") @ManyToOne(fetch = FetchType.LAZY) @NotQueryable public RAssignment getOwner() { return owner; } @Id @Column(name = "owner_owner_oid", length = RUtil.COLUMN_LENGTH_OID) @NotQueryable public String getOwnerOid() { return super.getOwnerOid(); } @Id @Column(name = "owner_id") @NotQueryable public Integer getOwnerId() { return super.getOwnerId(); } //@MapsId("target") @ForeignKey(name="none") @ManyToOne(fetch = FetchType.LAZY, optional = true) @JoinColumn(referencedColumnName = "oid", updatable = false, insertable = false, nullable = true) @NotFound(action = NotFoundAction.IGNORE) @NotQueryable // declared for HQL use only public RObject getTarget() { return null; } @Id @Column(name = "targetOid", length = RUtil.COLUMN_LENGTH_OID) @Override public String getTargetOid() { return super.getTargetOid(); } @Id @Column(name="relation", length = RUtil.COLUMN_LENGTH_QNAME) public String getRelation() { return super.getRelation(); } /** * Represents {@link javax.xml.namespace.QName} type attribute in reference e.g. * {@link com.evolveum.midpoint.xml.ns._public.common.common_3.UserType} represented * as enum {@link com.evolveum.midpoint.repo.sql.data.common.other.RObjectType#USER} * * @return null if not defined, otherwise value from {@link com.evolveum.midpoint.repo.sql.data.common.other.RObjectType} enum */ @Column(name = "targetType") @Enumerated(EnumType.ORDINAL) @Override public RObjectType getType() { return super.getType(); } @Id @Column(name = REFERENCE_TYPE, nullable = false) public RCReferenceOwner getReferenceType() { return super.getReferenceType(); } public void setOwner(RAssignment owner) { this.owner = owner; } }