All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.envers.boot.model.JoinedSubclassPersistentEntity Maven / Gradle / Ivy

There is a newer version: 7.0.0.Beta2
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.envers.boot.model;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmJoinedSubclassEntityType;
import org.hibernate.envers.configuration.internal.metadata.AuditTableData;
import org.hibernate.envers.internal.tools.StringTools;
import org.hibernate.mapping.PersistentClass;

/**
 * A persistent entity mapping that uses joined table(s) to store the hierarchy of entity types.
 *
 * @author Chris Cranford
 */
public class JoinedSubclassPersistentEntity extends SubclassPersistentEntity {

	private final List attributes;
	private String discriminatorValue;
	private Key key;

	public JoinedSubclassPersistentEntity(AuditTableData auditTableData, PersistentClass persistentClass) {
		super( auditTableData, persistentClass );
		this.attributes = new ArrayList<>();
	}

	@Override
	public void addAttribute(Attribute attribute) {
		attributes.add( attribute );
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getDiscriminatorValue() {
		return discriminatorValue;
	}

	public void setDiscriminatorValue(String discriminatorValue) {
		this.discriminatorValue = discriminatorValue;
	}

//	@Override
//	public List getJoins() {
//		throw new UnsupportedOperationException();
//	}
//
//	@Override
//	public void addJoin(Join join) {
//		throw new UnsupportedOperationException();
//	}

	@Override
	public void build(JaxbHbmHibernateMapping mapping) {
		mapping.getJoinedSubclass().add( buildJaxbMapping() );
	}

	public JaxbHbmJoinedSubclassEntityType buildJaxbMapping() {
		final JaxbHbmJoinedSubclassEntityType entity = new JaxbHbmJoinedSubclassEntityType();
		entity.setExtends( getExtends() );

		// Set common stuff
		if ( getPersistentClass() != null ) {
			entity.setAbstract( getPersistentClass().isAbstract() );
		}

		if ( !StringTools.isEmpty(getAuditTableData().getAuditEntityName() ) ) {
			entity.setEntityName( getAuditTableData().getAuditEntityName() );
		}

		if ( !StringTools.isEmpty( getAuditTableData().getAuditTableName() ) ) {
			entity.setTable( getAuditTableData().getAuditTableName() );
		}

		if ( !StringTools.isEmpty( getAuditTableData().getSchema() ) ) {
			entity.setSchema( getAuditTableData().getSchema() );
		}

		if ( !StringTools.isEmpty( getAuditTableData().getCatalog() ) ) {
			entity.setCatalog( getAuditTableData().getCatalog() );
		}

		for ( Attribute attribute : attributes ) {
			entity.getAttributes().add( attribute.build() );
		}

		entity.setKey( key.build() );

		if ( !StringTools.isEmpty( discriminatorValue ) ) {
			entity.setDiscriminatorValue( discriminatorValue );
		}

		return entity;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy