javax.persistence.PrimaryKeyJoinColumn Java Examples

The following examples show how to use javax.persistence.PrimaryKeyJoinColumn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private PrimaryKeyJoinColumn[] buildPrimaryKeyJoinColumns(Element element) {
	if ( element == null ) {
		return new PrimaryKeyJoinColumn[] { };
	}
	List pkJoinColumnElementList = element.elements( "primary-key-join-column" );
	PrimaryKeyJoinColumn[] pkJoinColumns = new PrimaryKeyJoinColumn[pkJoinColumnElementList.size()];
	int index = 0;
	Iterator pkIt = pkJoinColumnElementList.listIterator();
	while ( pkIt.hasNext() ) {
		Element subelement = (Element) pkIt.next();
		AnnotationDescriptor pkAnn = new AnnotationDescriptor( PrimaryKeyJoinColumn.class );
		copyStringAttribute( pkAnn, subelement, "name", false );
		copyStringAttribute( pkAnn, subelement, "referenced-column-name", false );
		copyStringAttribute( pkAnn, subelement, "column-definition", false );
		pkJoinColumns[index++] = AnnotationFactory.create( pkAnn );
	}
	return pkJoinColumns;
}
 
Example #2
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param mergeWithAnnotations Whether to use Java annotations for this
 * element, if present and not disabled by the XMLContext defaults.
 * In some contexts (such as an association mapping) merging with
 * annotations is never allowed.
 */
private PrimaryKeyJoinColumns getPrimaryKeyJoinColumns(Element element, XMLContext.Default defaults, boolean mergeWithAnnotations) {
	PrimaryKeyJoinColumn[] columns = buildPrimaryKeyJoinColumns( element );
	if ( mergeWithAnnotations ) {
		if ( columns.length == 0 && defaults.canUseJavaAnnotations() ) {
			PrimaryKeyJoinColumn annotation = getPhysicalAnnotation( PrimaryKeyJoinColumn.class );
			if ( annotation != null ) {
				columns = new PrimaryKeyJoinColumn[] { annotation };
			}
			else {
				PrimaryKeyJoinColumns annotations = getPhysicalAnnotation( PrimaryKeyJoinColumns.class );
				columns = annotations != null ? annotations.value() : columns;
			}
		}
	}
	if ( columns.length > 0 ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( PrimaryKeyJoinColumns.class );
		ad.setValue( "value", columns );
		return AnnotationFactory.create( ad );
	}
	else {
		return null;
	}
}
 
Example #3
Source File: SqlGenerator.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
protected static void addPrimaryKeyJoinColumns(StringBuilder sql, String fromTable, String toTable, String joinType, PrimaryKeyJoinColumn[] pkjcs) {
    if ("right".equalsIgnoreCase(joinType)) {
        sql.append(" RIGHT JOIN ").append(toTable).append(" ON ");
    } else if ("left".equalsIgnoreCase(joinType)) {
        sql.append(" LEFT JOIN ").append(toTable).append(" ON ");
    } else {
        sql.append(" INNER JOIN ").append(toTable).append(" ON ");
    }
    for (PrimaryKeyJoinColumn pkjc : pkjcs) {
        sql.append(fromTable).append(".").append(pkjc.name());
        String refColumn = DbUtil.getReferenceColumn(pkjc);
        sql.append("=").append(toTable).append(".").append(refColumn).append(" ");
    }
}
 
Example #4
Source File: DbUtil.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public static PrimaryKeyJoinColumn[] getPrimaryKeyJoinColumns(Class<?> clazz) {
    PrimaryKeyJoinColumn pkjc = clazz.getAnnotation(PrimaryKeyJoinColumn.class);
    if (pkjc != null) {
        return new PrimaryKeyJoinColumn[] {pkjc};
    }

    PrimaryKeyJoinColumns pkjcs = clazz.getAnnotation(PrimaryKeyJoinColumns.class);
    if (pkjcs != null) {
        return pkjcs.value();
    }

    return null;
}
 
Example #5
Source File: JobData.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "jobData")
@Fetch(FetchMode.SELECT)
@BatchSize(size = 10)
@MapKey(name = "jobId")
@PrimaryKeyJoinColumn(name = "JOB_ID")
public List<JobContent> getJobContent() {
    return jobContent;
}
 
Example #6
Source File: SqlGenerator.java    From cosmic with Apache License 2.0 5 votes vote down vote up
protected static void addPrimaryKeyJoinColumns(final StringBuilder sql, final String fromTable, final String toTable, final String joinType, final PrimaryKeyJoinColumn[]
        pkjcs) {
    if ("right".equalsIgnoreCase(joinType)) {
        sql.append(" RIGHT JOIN ").append(toTable).append(" ON ");
    } else if ("left".equalsIgnoreCase(joinType)) {
        sql.append(" LEFT JOIN ").append(toTable).append(" ON ");
    } else {
        sql.append(" INNER JOIN ").append(toTable).append(" ON ");
    }
    for (final PrimaryKeyJoinColumn pkjc : pkjcs) {
        sql.append(fromTable).append(".").append(pkjc.name());
        final String refColumn = DbUtil.getReferenceColumn(pkjc);
        sql.append("=").append(toTable).append(".").append(refColumn).append(" ");
    }
}
 
Example #7
Source File: DbUtil.java    From cosmic with Apache License 2.0 5 votes vote down vote up
public static PrimaryKeyJoinColumn[] getPrimaryKeyJoinColumns(final Class<?> clazz) {
    final PrimaryKeyJoinColumn pkjc = clazz.getAnnotation(PrimaryKeyJoinColumn.class);
    if (pkjc != null) {
        return new PrimaryKeyJoinColumn[]{pkjc};
    }

    final PrimaryKeyJoinColumns pkjcs = clazz.getAnnotation(PrimaryKeyJoinColumns.class);
    if (pkjcs != null) {
        return pkjcs.value();
    }

    return null;
}
 
Example #8
Source File: Login.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public User getUser() {
	return this.user;
}
 
Example #9
Source File: EntityBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void createPrimaryColumnsToSecondaryTable(Object uncastedColumn, PropertyHolder propertyHolder, Join join) {
	Ejb3JoinColumn[] ejb3JoinColumns;
	PrimaryKeyJoinColumn[] pkColumnsAnn = null;
	JoinColumn[] joinColumnsAnn = null;
	if ( uncastedColumn instanceof PrimaryKeyJoinColumn[] ) {
		pkColumnsAnn = (PrimaryKeyJoinColumn[]) uncastedColumn;
	}
	if ( uncastedColumn instanceof JoinColumn[] ) {
		joinColumnsAnn = (JoinColumn[]) uncastedColumn;
	}
	if ( pkColumnsAnn == null && joinColumnsAnn == null ) {
		ejb3JoinColumns = new Ejb3JoinColumn[1];
		ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinColumn(
				null,
				null,
				persistentClass.getIdentifier(),
				secondaryTables,
				propertyHolder,
				context
		);
	}
	else {
		int nbrOfJoinColumns = pkColumnsAnn != null ?
				pkColumnsAnn.length :
				joinColumnsAnn.length;
		if ( nbrOfJoinColumns == 0 ) {
			ejb3JoinColumns = new Ejb3JoinColumn[1];
			ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinColumn(
					null,
					null,
					persistentClass.getIdentifier(),
					secondaryTables,
					propertyHolder,
					context
			);
		}
		else {
			ejb3JoinColumns = new Ejb3JoinColumn[nbrOfJoinColumns];
			if ( pkColumnsAnn != null ) {
				for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++) {
					ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
							pkColumnsAnn[colIndex],
							null,
							persistentClass.getIdentifier(),
							secondaryTables,
							propertyHolder,
							context
					);
				}
			}
			else {
				for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++) {
					ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
							null,
							joinColumnsAnn[colIndex],
							persistentClass.getIdentifier(),
							secondaryTables,
							propertyHolder,
							context
					);
				}
			}
		}
	}

	for (Ejb3JoinColumn joinColumn : ejb3JoinColumns) {
		joinColumn.forceNotNull();
	}
	bindJoinToPersistentClass( join, ejb3JoinColumns, context );
}
 
Example #10
Source File: Login.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public CustomerAccount getCustomerAccount() {
	return this.customerAccount;
}
 
Example #11
Source File: DbUtil.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public static String getReferenceColumn(PrimaryKeyJoinColumn pkjc) {
    return pkjc.referencedColumnName().length() != 0 ? pkjc.referencedColumnName() : pkjc.name();
}
 
Example #12
Source File: Video.java    From TinyMooc with Apache License 2.0 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Resource getResource() {
    return this.resource;
}
 
Example #13
Source File: Link.java    From TinyMooc with Apache License 2.0 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Resource getResource() {
    return this.resource;
}
 
Example #14
Source File: ImageText.java    From TinyMooc with Apache License 2.0 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Resource getResource() {
    return this.resource;
}
 
Example #15
Source File: Login.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public CustomerAccount getCustomerAccount() {
	return this.customerAccount;
}
 
Example #16
Source File: InvoicedProducts.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Invoice getInvoice() {
	return this.invoice;
}
 
Example #17
Source File: InvoicedProducts.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Invoice getInvoice() {
	return this.invoice;
}
 
Example #18
Source File: DbUtil.java    From cosmic with Apache License 2.0 4 votes vote down vote up
public static String getReferenceColumn(final PrimaryKeyJoinColumn pkjc) {
    return pkjc.referencedColumnName().length() != 0 ? pkjc.referencedColumnName() : pkjc.name();
}
 
Example #19
Source File: Race.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
@OneToOne(cascade=CascadeType.ALL,fetch = FetchType.EAGER)  
@PrimaryKeyJoinColumn
public AgeGroups getAgeGroups() {
    return ageGroups;
}
 
Example #20
Source File: Race.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
@OneToOne(cascade=CascadeType.ALL,fetch = FetchType.EAGER)  
@PrimaryKeyJoinColumn
public RaceAwards getAwards() {
    return awards;
}
 
Example #21
Source File: Login.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public CustomerInfo getCustomerInfo() {
	return this.customerInfo;
}
 
Example #22
Source File: Tblgpa.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Tblstudents getTblstudents() {
	return this.tblstudents;
}
 
Example #23
Source File: Tblgpa.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public Tblstudents getTblstudents() {
	return this.tblstudents;
}
 
Example #24
Source File: Login.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
public User getUser() {
	return this.user;
}