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

org.hibernate.envers.configuration.internal.PersistentClassGraphDefiner 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.configuration.internal;

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

import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.envers.internal.tools.Tools;
import org.hibernate.envers.internal.tools.graph.GraphDefiner;
import org.hibernate.mapping.PersistentClass;

/**
 * Defines a graph, where the vertexes are all persistent classes, and there is an edge from
 * p.c. A to p.c. B iff A is a superclass of B.
 *
 * @author Adam Warski (adam at warski dot org)
 */
public class PersistentClassGraphDefiner implements GraphDefiner {
	private final MetadataImplementor metadata;

	public PersistentClassGraphDefiner(MetadataImplementor metadata) {
		this.metadata = metadata;
	}

	@Override
	public String getRepresentation(PersistentClass pc) {
		return pc.getEntityName();
	}

	@Override
	public PersistentClass getValue(String entityName) {
		return metadata.getEntityBinding( entityName );
	}

	private void addNeighbours(List neighbours, List subclasses) {
		for ( PersistentClass subclass : subclasses ) {
			neighbours.add( subclass );
			addNeighbours( neighbours, subclass.getSubclasses() );
		}
	}

	@Override
	public List getNeighbours(PersistentClass pc) {
		final List neighbours = new ArrayList<>();

		addNeighbours( neighbours, pc.getSubclasses() );

		return neighbours;
	}

	@Override
	public List getValues() {
		return Tools.collectionToList( metadata.getEntityBindings() );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy