Java Code Examples for org.hibernate.mapping.PersistentClass

The following are top voted examples for showing how to use org.hibernate.mapping.PersistentClass. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: dhus-core   File: EntityCallbackHandlerInitializer.java   View source code 6 votes vote down vote up
@PostConstruct
public void init() throws ClassNotFoundException
{
  final Configuration configuration = annotationSessionFactory
        .getConfiguration();
  final ReflectionManager reflectionManager = configuration
        .getReflectionManager();
  final Iterator<PersistentClass> classMappings = configuration
        .getClassMappings();
  while (classMappings.hasNext()) 
  {
     entityCallbackHandler.add(reflectionManager.classForName(
        classMappings.next().getClassName(), this.getClass()),
        reflectionManager);
  }
}
 
Example 2
Project: lams   File: HbmBinder.java   View source code 6 votes vote down vote up
private static void bindPojoRepresentation(Element node, PersistentClass entity,
		Mappings mappings, java.util.Map metaTags) {

	String className = getClassName( node.attribute( "name" ), mappings );
	String proxyName = getClassName( node.attribute( "proxy" ), mappings );

	entity.setClassName( className );

	if ( proxyName != null ) {
		entity.setProxyInterfaceName( proxyName );
		entity.setLazy( true );
	}
	else if ( entity.isLazy() ) {
		entity.setProxyInterfaceName( className );
	}

	Element tuplizer = locateTuplizerDefinition( node, EntityMode.POJO );
	if ( tuplizer != null ) {
		entity.addTuplizer( EntityMode.POJO, tuplizer.attributeValue( "class" ) );
	}
}
 
Example 3
Project: lams   File: HbmBinder.java   View source code 6 votes vote down vote up
private static String getClassTableName(
		PersistentClass model,
		Element node,
		String schema,
		String catalog,
		Table denormalizedSuperTable,
		Mappings mappings) {
	Attribute tableNameNode = node.attribute( "table" );
	String logicalTableName;
	String physicalTableName;
	if ( tableNameNode == null ) {
		logicalTableName = StringHelper.unqualify( model.getEntityName() );
		physicalTableName = getNamingStrategyDelegate( mappings ).determineImplicitPrimaryTableName(
				model.getEntityName(),
				model.getJpaEntityName()
		);
	}
	else {
		logicalTableName = tableNameNode.getValue();
		physicalTableName = getNamingStrategyDelegate( mappings ).toPhysicalTableName( logicalTableName );
	}
	mappings.addTableBinding( schema, catalog, logicalTableName, physicalTableName, denormalizedSuperTable );
	return physicalTableName;
}
 
Example 4
Project: lams   File: ToOneFkSecondPass.java   View source code 6 votes vote down vote up
public void doSecondPass(java.util.Map persistentClasses) throws MappingException {
	if ( value instanceof ManyToOne ) {
		ManyToOne manyToOne = (ManyToOne) value;
		PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() );
		if ( ref == null ) {
			throw new AnnotationException(
					"@OneToOne or @ManyToOne on "
							+ StringHelper.qualify( entityClassName, path )
							+ " references an unknown entity: "
							+ manyToOne.getReferencedEntityName()
			);
		}
		BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings );
		TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings );
		/*
		 * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null
		 */
		if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses );
	}
	else if ( value instanceof OneToOne ) {
		value.createForeignKey();
	}
	else {
		throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() );
	}
}
 
Example 5
Project: lams   File: VerifyFetchProfileReferenceSecondPass.java   View source code 6 votes vote down vote up
public void doSecondPass(Map persistentClasses) throws MappingException {
	org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile(
			fetchProfileName,
			MetadataSource.ANNOTATIONS
	);
	if ( MetadataSource.ANNOTATIONS != profile.getSource() ) {
		return;
	}

	PersistentClass clazz = mappings.getClass( fetch.entity().getName() );
	// throws MappingException in case the property does not exist
	clazz.getProperty( fetch.association() );

	profile.addFetch(
			fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase()
	);
}
 
Example 6
Project: lams   File: ResultSetMappingBinder.java   View source code 6 votes vote down vote up
private static NativeSQLQueryRootReturn bindReturn(Element returnElem, Mappings mappings, int elementCount) {
	String alias = returnElem.attributeValue( "alias" );
	if( StringHelper.isEmpty( alias )) {
		alias = "alias_" + elementCount; // hack/workaround as sqlquery impl depend on having a key.
	}

	String entityName = HbmBinder.getEntityName(returnElem, mappings);
	if(entityName==null) {
		throw new MappingException( "<return alias='" + alias + "'> must specify either a class or entity-name");
	}
	LockMode lockMode = getLockMode( returnElem.attributeValue( "lock-mode" ) );

	PersistentClass pc = mappings.getClass( entityName );
	java.util.Map propertyResults = bindPropertyResults(alias, returnElem, pc, mappings );

	return new NativeSQLQueryRootReturn(
			alias,
			entityName,
			propertyResults,
			lockMode
		);
}
 
Example 7
Project: lams   File: AnnotationBinder.java   View source code 6 votes vote down vote up
private static void processIdPropertiesIfNotAlready(
		Map<XClass, InheritanceState> inheritanceStatePerClass,
		Mappings mappings,
		PersistentClass persistentClass,
		EntityBinder entityBinder,
		PropertyHolder propertyHolder,
		HashMap<String, IdGenerator> classGenerators,
		InheritanceState.ElementsToProcess elementsToProcess,
		boolean subclassAndSingleTableStrategy,
		Set<String> idPropertiesIfIdClass) {
	Set<String> missingIdProperties = new HashSet<String>( idPropertiesIfIdClass );
	for ( PropertyData propertyAnnotatedElement : elementsToProcess.getElements() ) {
		String propertyName = propertyAnnotatedElement.getPropertyName();
		if ( !idPropertiesIfIdClass.contains( propertyName ) ) {
			processElementAnnotations(
					propertyHolder,
					subclassAndSingleTableStrategy ?
							Nullability.FORCED_NULL :
							Nullability.NO_CONSTRAINT,
					propertyAnnotatedElement, classGenerators, entityBinder,
					false, false, false, mappings, inheritanceStatePerClass
			);
		}
		else {
			missingIdProperties.remove( propertyName );
		}
	}

	if ( missingIdProperties.size() != 0 ) {
		StringBuilder missings = new StringBuilder();
		for ( String property : missingIdProperties ) {
			missings.append( property ).append( ", " );
		}
		throw new AnnotationException(
				"Unable to find properties ("
						+ missings.substring( 0, missings.length() - 2 )
						+ ") in entity annotated with @IdClass:" + persistentClass.getEntityName()
		);
	}
}
 
Example 8
Project: lams   File: AnnotationBinder.java   View source code 6 votes vote down vote up
private static PersistentClass getSuperEntity(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, Mappings mappings, InheritanceState inheritanceState) {
	InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity(
			clazzToProcess, inheritanceStatePerClass
	);
	PersistentClass superEntity = superEntityState != null ?
			mappings.getClass(
					superEntityState.getClazz().getName()
			) :
			null;
	if ( superEntity == null ) {
		//check if superclass is not a potential persistent class
		if ( inheritanceState.hasParents() ) {
			throw new AssertionFailure(
					"Subclass has to be binded after it's mother class: "
							+ superEntityState.getClazz().getName()
			);
		}
	}
	return superEntity;
}
 
Example 9
Project: lams   File: Ejb3JoinColumn.java   View source code 6 votes vote down vote up
public void linkValueUsingDefaultColumnNaming(
		Column referencedColumn,
		PersistentClass referencedEntity,
		SimpleValue value) {
	String columnName;
	String logicalReferencedColumn = getMappings().getLogicalColumnName(
			referencedColumn.getQuotedName(), referencedEntity.getTable()
	);
	columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn );
	//yuk side effect on an implicit column
	setLogicalColumnName( columnName );
	setReferencedColumn( logicalReferencedColumn );
	initMappingColumn(
			columnName,
			null, referencedColumn.getLength(),
			referencedColumn.getPrecision(),
			referencedColumn.getScale(),
			getMappingColumn() != null ? getMappingColumn().isNullable() : false,
			referencedColumn.getSqlType(),
			getMappingColumn() != null ? getMappingColumn().isUnique() : false,
		    false
	);
	linkWithValue( value );
}
 
Example 10
Project: lams   File: TableBinder.java   View source code 6 votes vote down vote up
public static void linkJoinColumnWithValueOverridingNameIfImplicit(
		PersistentClass referencedEntity,
		Iterator columnIterator,
		Ejb3JoinColumn[] columns,
		SimpleValue value) {
	for (Ejb3JoinColumn joinCol : columns) {
		Column synthCol = (Column) columnIterator.next();
		if ( joinCol.isNameDeferred() ) {
			//this has to be the default value
			joinCol.linkValueUsingDefaultColumnNaming( synthCol, referencedEntity, value );
		}
		else {
			joinCol.linkWithValue( value );
			joinCol.overrideFromReferencedColumnIfNecessary( synthCol );
		}
	}
}
 
Example 11
Project: lams   File: JoinedSubclassEntityPersister.java   View source code 6 votes vote down vote up
private Set<String> processPersistentClassHierarchy(
		PersistentClass persistentClass,
		boolean isBase,
		SessionFactoryImplementor factory,
		String[][] mapping) {

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// collect all the class names that indicate that the "main table" of the given PersistentClass should be
	// included when one of the collected class names is used in TREAT
	final Set<String> classNames = new HashSet<String>();

	final Iterator itr = persistentClass.getDirectSubclasses();
	while ( itr.hasNext() ) {
		final Subclass subclass = (Subclass) itr.next();
		final Set<String> subclassSubclassNames = processPersistentClassHierarchy(
				subclass,
				false,
				factory,
				mapping
		);
		classNames.addAll( subclassSubclassNames );
	}

	classNames.add( persistentClass.getEntityName() );

	if ( ! isBase ) {
		MappedSuperclass msc = persistentClass.getSuperMappedSuperclass();
		while ( msc != null ) {
			classNames.add( msc.getMappedClass().getName() );
			msc = msc.getSuperMappedSuperclass();
		}

		associateSubclassNamesToSubclassTableIndexes( persistentClass, classNames, mapping, factory );
	}

	return classNames;
}
 
Example 12
Project: lams   File: JoinedSubclassEntityPersister.java   View source code 6 votes vote down vote up
private void associateSubclassNamesToSubclassTableIndexes(
		PersistentClass persistentClass,
		Set<String> classNames,
		String[][] mapping,
		SessionFactoryImplementor factory) {

	final String tableName = persistentClass.getTable().getQualifiedName(
			factory.getDialect(),
			factory.getSettings().getDefaultCatalogName(),
			factory.getSettings().getDefaultSchemaName()
	);

	associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping );

	Iterator itr = persistentClass.getJoinIterator();
	while ( itr.hasNext() ) {
		final Join join = (Join) itr.next();
		final String secondaryTableName = join.getTable().getQualifiedName(
				factory.getDialect(),
				factory.getSettings().getDefaultCatalogName(),
				factory.getSettings().getDefaultSchemaName()
		);
		associateSubclassNamesToSubclassTableIndex( secondaryTableName, classNames, mapping );
	}
}
 
Example 13
Project: lams   File: DynamicMapEntityTuplizer.java   View source code 6 votes vote down vote up
@Override
   protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {

	ProxyFactory pf = new MapProxyFactory();
	try {
		//TODO: design new lifecycle for ProxyFactory
		pf.postInstantiate(
				getEntityName(),
				null,
				null,
				null,
				null,
				null
		);
	}
	catch ( HibernateException he ) {
		LOG.unableToCreateProxyFactory( getEntityName(), he );
		pf = null;
	}
	return pf;
}
 
Example 14
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
public static void bindClass(Element node, PersistentClass persistentClass, Mappings mappings,
		java.util.Map inheritedMetas) throws MappingException {
	// transfer an explicitly defined entity name
	// handle the lazy attribute
	Attribute lazyNode = node.attribute( "lazy" );
	boolean lazy = lazyNode == null ?
			mappings.isDefaultLazy() :
			"true".equals( lazyNode.getValue() );
	// go ahead and set the lazy here, since pojo.proxy can override it.
	persistentClass.setLazy( lazy );

	String entityName = node.attributeValue( "entity-name" );
	if ( entityName == null ) entityName = getClassName( node.attribute("name"), mappings );
	if ( entityName==null ) {
		throw new MappingException( "Unable to determine entity name" );
	}
	persistentClass.setEntityName( entityName );
	persistentClass.setJpaEntityName( StringHelper.unqualify( entityName ) );

	bindPojoRepresentation( node, persistentClass, mappings, inheritedMetas );
	bindDom4jRepresentation( node, persistentClass, mappings, inheritedMetas );
	bindMapRepresentation( node, persistentClass, mappings, inheritedMetas );

	Iterator itr = node.elementIterator( "fetch-profile" );
	while ( itr.hasNext() ) {
		final Element profileElement = ( Element ) itr.next();
		parseFetchProfile( profileElement, mappings, entityName );
	}

	bindPersistentClassCommonValues( node, persistentClass, mappings, inheritedMetas );
}
 
Example 15
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
private static void bindDom4jRepresentation(Element node, PersistentClass entity,
			Mappings mappings, java.util.Map inheritedMetas) {
		String nodeName = node.attributeValue( "node" );
		if (nodeName==null) nodeName = StringHelper.unqualify( entity.getEntityName() );
		entity.setNodeName(nodeName);

//		Element tuplizer = locateTuplizerDefinition( node, EntityMode.DOM4J );
//		if ( tuplizer != null ) {
//			entity.addTuplizer( EntityMode.DOM4J, tuplizer.attributeValue( "class" ) );
//		}
	}
 
Example 16
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
private static void bindMapRepresentation(Element node, PersistentClass entity,
		Mappings mappings, java.util.Map inheritedMetas) {
	Element tuplizer = locateTuplizerDefinition( node, EntityMode.MAP );
	if ( tuplizer != null ) {
		entity.addTuplizer( EntityMode.MAP, tuplizer.attributeValue( "class" ) );
	}
}
 
Example 17
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
private static void handleUnionSubclass(PersistentClass model, Mappings mappings,
		Element subnode, java.util.Map inheritedMetas) throws MappingException {
	UnionSubclass subclass = new UnionSubclass( model );
	bindUnionSubclass( subnode, subclass, mappings, inheritedMetas );
	model.addSubclass( subclass );
	mappings.addClass( subclass );
}
 
Example 18
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
private static void handleJoinedSubclass(PersistentClass model, Mappings mappings,
		Element subnode, java.util.Map inheritedMetas) throws MappingException {
	JoinedSubclass subclass = new JoinedSubclass( model );
	bindJoinedSubclass( subnode, subclass, mappings, inheritedMetas );
	model.addSubclass( subclass );
	mappings.addClass( subclass );
}
 
Example 19
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
private static void handleSubclass(PersistentClass model, Mappings mappings, Element subnode,
		java.util.Map inheritedMetas) throws MappingException {
	Subclass subclass = new SingleTableSubclass( model );
	bindSubclass( subnode, subclass, mappings, inheritedMetas );
	model.addSubclass( subclass );
	mappings.addClass( subclass );
}
 
Example 20
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
/**
 * Called for Lists, arrays, primitive arrays
 */
public static void bindListSecondPass(Element node, List list, java.util.Map classes,
		Mappings mappings, java.util.Map inheritedMetas) throws MappingException {

	bindCollectionSecondPass( node, list, classes, mappings, inheritedMetas );

	Element subnode = node.element( "list-index" );
	if ( subnode == null ) subnode = node.element( "index" );
	SimpleValue iv = new SimpleValue( mappings, list.getCollectionTable() );
	bindSimpleValue(
			subnode,
			iv,
			list.isOneToMany(),
			IndexedCollection.DEFAULT_INDEX_COLUMN_NAME,
			mappings
	);
	iv.setTypeName( "integer" );
	list.setIndex( iv );
	String baseIndex = subnode.attributeValue( "base" );
	if ( baseIndex != null ) list.setBaseIndex( Integer.parseInt( baseIndex ) );
	list.setIndexNodeName( subnode.attributeValue("node") );

	if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) {
		String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName();
		PersistentClass referenced = mappings.getClass( entityName );
		IndexBackref ib = new IndexBackref();
		ib.setName( '_' + list.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "IndexBackref" );
		ib.setUpdateable( false );
		ib.setSelectable( false );
		ib.setCollectionRole( list.getRole() );
		ib.setEntityName( list.getOwner().getEntityName() );
		ib.setValue( list.getIndex() );
		// ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next()
		// ).setNullable(false);
		referenced.addProperty( ib );
	}
}
 
Example 21
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
private static PersistentClass getSuperclass(Mappings mappings, Element subnode)
		throws MappingException {
	String extendsName = subnode.attributeValue( "extends" );
	PersistentClass superModel = mappings.getClass( extendsName );
	if ( superModel == null ) {
		String qualifiedExtendsName = getClassName( extendsName, mappings );
		superModel = mappings.getClass( qualifiedExtendsName );
	}

	if ( superModel == null ) {
		throw new MappingException( "Cannot extend unmapped class " + extendsName );
	}
	return superModel;
}
 
Example 22
Project: lams   File: Configuration.java   View source code 5 votes vote down vote up
private void validate() throws MappingException {
	Iterator iter = classes.values().iterator();
	while ( iter.hasNext() ) {
		( (PersistentClass) iter.next() ).validate( mapping );
	}
	iter = collections.values().iterator();
	while ( iter.hasNext() ) {
		( (Collection) iter.next() ).validate( mapping );
	}
}
 
Example 23
Project: lams   File: Configuration.java   View source code 5 votes vote down vote up
protected void secondPassCompileForeignKeys(Table table, Set<ForeignKey> done) throws MappingException {
	table.createForeignKeys();
	Iterator iter = table.getForeignKeyIterator();
	while ( iter.hasNext() ) {

		ForeignKey fk = (ForeignKey) iter.next();
		if ( !done.contains( fk ) ) {
			done.add( fk );
			final String referencedEntityName = fk.getReferencedEntityName();
			if ( referencedEntityName == null ) {
				throw new MappingException(
						"An association from the table " +
						fk.getTable().getName() +
						" does not specify the referenced entity"
					);
			}
			LOG.debugf( "Resolving reference to class: %s", referencedEntityName );
			PersistentClass referencedClass = classes.get( referencedEntityName );
			if ( referencedClass == null ) {
				throw new MappingException(
						"An association from the table " +
						fk.getTable().getName() +
						" refers to an unmapped class: " +
						referencedEntityName
					);
			}
			if ( referencedClass.isJoinedSubclass() ) {
				secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done );
			}
			fk.setReferencedTable( referencedClass.getTable() );
			fk.alignColumns();
		}
	}
}
 
Example 24
Project: lams   File: PojoInstantiator.java   View source code 5 votes vote down vote up
public PojoInstantiator(PersistentClass persistentClass, ReflectionOptimizer.InstantiationOptimizer optimizer) {
	this.mappedClass = persistentClass.getMappedClass();
	this.isAbstract = ReflectHelper.isAbstractClass( mappedClass );
	this.proxyInterface = persistentClass.getProxyInterface();
	this.embeddedIdentifier = persistentClass.hasEmbeddedIdentifier();
	this.optimizer = optimizer;

	try {
		constructor = ReflectHelper.getDefaultConstructor( mappedClass );
	}
	catch ( PropertyNotFoundException pnfe ) {
		LOG.noDefaultConstructor(mappedClass.getName());
		constructor = null;
	}
}
 
Example 25
Project: lams   File: ClassPropertyHolder.java   View source code 5 votes vote down vote up
public ClassPropertyHolder(
		PersistentClass persistentClass,
		XClass entityXClass,
		Map<String, Join> joins,
		Mappings mappings,
		Map<XClass, InheritanceState> inheritanceStatePerClass) {
	super( persistentClass.getEntityName(), null, entityXClass, mappings );
	this.persistentClass = persistentClass;
	this.joins = joins;
	this.inheritanceStatePerClass = inheritanceStatePerClass;

	this.attributeConversionInfoMap = buildAttributeConversionInfoMap( entityXClass );
}
 
Example 26
Project: lams   File: ClassPropertyHolder.java   View source code 5 votes vote down vote up
public ClassPropertyHolder(
		PersistentClass persistentClass,
		XClass entityXClass,
		EntityBinder entityBinder,
		Mappings mappings,
		Map<XClass, InheritanceState> inheritanceStatePerClass) {
	this( persistentClass, entityXClass, entityBinder.getSecondaryTables(), mappings, inheritanceStatePerClass );
	this.entityBinder = entityBinder;
}
 
Example 27
Project: lams   File: ToOneFkSecondPass.java   View source code 5 votes vote down vote up
@Override
   public boolean isInPrimaryKey() {
	if ( entityClassName == null ) return false;
	final PersistentClass persistentClass = mappings.getClass( entityClassName );
	Property property = persistentClass.getIdentifierProperty();
	if ( path == null ) {
		return false;
	}
	else if ( property != null) {
		//try explicit identifier property
		return path.startsWith( property.getName() + "." );
	}
	else {
		//try the embedded property
		//embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
		if ( path.startsWith( "id." ) ) {
			KeyValue valueIdentifier = persistentClass.getIdentifier();
			String localPath = path.substring( 3 );
			if ( valueIdentifier instanceof Component ) {
				Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
				while ( it.hasNext() ) {
					Property idProperty = (Property) it.next();
					if ( localPath.startsWith( idProperty.getName() ) ) return true;
				}

			}
		}
	}
	return false;
}
 
Example 28
Project: lams   File: TypeSafeActivator.java   View source code 5 votes vote down vote up
private static void applyDDL(
		String prefix,
		PersistentClass persistentClass,
		Class<?> clazz,
		ValidatorFactory factory,
		Set<Class<?>> groups,
		boolean activateNotNull,
		Dialect dialect) {
	final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass( clazz );
	//no bean level constraints can be applied, go to the properties

	for ( PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties() ) {
		Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() );
		boolean hasNotNull;
		if ( property != null ) {
			hasNotNull = applyConstraints(
					propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect
			);
			if ( property.isComposite() && propertyDesc.isCascaded() ) {
				Class<?> componentClass = ( (Component) property.getValue() ).getComponentClass();

				/*
				 * we can apply not null if the upper component let's us activate not null
				 * and if the property is not null.
				 * Otherwise, all sub columns should be left nullable
				 */
				final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull;
				applyDDL(
						prefix + propertyDesc.getPropertyName() + ".",
						persistentClass, componentClass, factory, groups,
						canSetNotNullOnColumns,
                           dialect
				);
			}
			//FIXME add collection of components
		}
	}
}
 
Example 29
Project: lams   File: OneToOneSecondPass.java   View source code 5 votes vote down vote up
/**
 * Builds the <code>Join</code> instance for the mapped by side of a <i>OneToOne</i> association using 
 * a join tables.
 * <p>
 * Note:<br/>
 * <ul>
 * <li>From the mappedBy side we should not create the PK nor the FK, this is handled from the other side.</li>
 * <li>This method is a dirty dupe of EntityBinder.bindSecondaryTable</i>.
 * </p>
 */
private Join buildJoinFromMappedBySide(PersistentClass persistentClass, Property otherSideProperty, Join originalJoin) {
	Join join = new Join();
	join.setPersistentClass( persistentClass );

	//no check constraints available on joins
	join.setTable( originalJoin.getTable() );
	join.setInverse( true );
	SimpleValue key = new DependantValue( mappings, join.getTable(), persistentClass.getIdentifier() );
	//TODO support @ForeignKey
	join.setKey( key );
	join.setSequentialSelect( false );
	//TODO support for inverse and optional
	join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway
	key.setCascadeDeleteEnabled( false );
	Iterator mappedByColumns = otherSideProperty.getValue().getColumnIterator();
	while ( mappedByColumns.hasNext() ) {
		Column column = (Column) mappedByColumns.next();
		Column copy = new Column();
		copy.setLength( column.getLength() );
		copy.setScale( column.getScale() );
		copy.setValue( key );
		copy.setName( column.getQuotedName() );
		copy.setNullable( column.isNullable() );
		copy.setPrecision( column.getPrecision() );
		copy.setUnique( column.isUnique() );
		copy.setSqlType( column.getSqlType() );
		copy.setCheckConstraint( column.getCheckConstraint() );
		copy.setComment( column.getComment() );
		copy.setDefaultValue( column.getDefaultValue() );
		key.addColumn( copy );
	}
	persistentClass.addJoin( join );
	return join;
}
 
Example 30
Project: lams   File: InheritanceState.java   View source code 5 votes vote down vote up
private void addMappedSuperClassInMetadata(PersistentClass persistentClass) {
	//add @MappedSuperclass in the metadata
	// classes from 0 to n-1 are @MappedSuperclass and should be linked
	org.hibernate.mapping.MappedSuperclass mappedSuperclass = null;
	final InheritanceState superEntityState =
			InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass );
	PersistentClass superEntity =
			superEntityState != null ?
					mappings.getClass( superEntityState.getClazz().getName() ) :
					null;
	final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1;
	for ( int index = 0; index < lastMappedSuperclass; index++ ) {
		org.hibernate.mapping.MappedSuperclass parentSuperclass = mappedSuperclass;
		final Class<?> type = mappings.getReflectionManager()
				.toClass( classesToProcessForMappedSuperclass.get( index ) );
		//add MAppedSuperclass if not already there
		mappedSuperclass = mappings.getMappedSuperclass( type );
		if ( mappedSuperclass == null ) {
			mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity );
			mappedSuperclass.setMappedClass( type );
			mappings.addMappedSuperclass( type, mappedSuperclass );
		}
	}
	if ( mappedSuperclass != null ) {
		persistentClass.setSuperMappedSuperclass( mappedSuperclass );
	}
}
 
Example 31
Project: lams   File: PkDrivenByDefaultMapsIdSecondPass.java   View source code 5 votes vote down vote up
public void doSecondPass(Map persistentClasses) throws MappingException {
	PersistentClass referencedEntity = (PersistentClass) persistentClasses.get( referencedEntityName );
	if ( referencedEntity == null ) {
		throw new AnnotationException(
				"Unknown entity name: " + referencedEntityName
		);
	};
	TableBinder.linkJoinColumnWithValueOverridingNameIfImplicit(
			referencedEntity,
			referencedEntity.getKey().getColumnIterator(),
			columns,
			value);
}
 
Example 32
Project: lams   File: Ejb3JoinColumn.java   View source code 5 votes vote down vote up
/**
 * Override persistent class on oneToMany Cases for late settings
 * Must only be used on second level pass binding
 */
public void setPersistentClass(
		PersistentClass persistentClass,
		Map<String, Join> joins,
		Map<XClass, InheritanceState> inheritanceStatePerClass) {
	// TODO shouldn't we deduce the classname from the persistentclasS?
	this.propertyHolder = PropertyHolderBuilder.buildPropertyHolder( persistentClass, joins, getMappings(), inheritanceStatePerClass );
}
 
Example 33
Project: lams   File: Ejb3JoinColumn.java   View source code 5 votes vote down vote up
public void copyReferencedStructureAndCreateDefaultJoinColumns(
		PersistentClass referencedEntity,
		Iterator columnIterator,
		SimpleValue value) {
	if ( !isNameDeferred() ) {
		throw new AssertionFailure( "Building implicit column but the column is not implicit" );
	}
	while ( columnIterator.hasNext() ) {
		Column synthCol = (Column) columnIterator.next();
		this.linkValueUsingDefaultColumnNaming( synthCol, referencedEntity, value );
	}
	//reset for the future
	setMappingColumn( null );
}
 
Example 34
Project: lams   File: PropertyHolderBuilder.java   View source code 5 votes vote down vote up
public static PropertyHolder buildPropertyHolder(
		XClass clazzToProcess,
		PersistentClass persistentClass,
		EntityBinder entityBinder,
		Mappings mappings,
		Map<XClass, InheritanceState> inheritanceStatePerClass) {
	return new ClassPropertyHolder(
			persistentClass, clazzToProcess, entityBinder, mappings, inheritanceStatePerClass
	);
}
 
Example 35
Project: lams   File: PropertyHolderBuilder.java   View source code 5 votes vote down vote up
/**
 * must only be used on second level phases (<join> has to be settled already)
 */
public static PropertyHolder buildPropertyHolder(
		PersistentClass persistentClass,
		Map<String, Join> joins,
		Mappings mappings,
		Map<XClass, InheritanceState> inheritanceStatePerClass) {
	return new ClassPropertyHolder( persistentClass, null, joins, mappings, inheritanceStatePerClass );
}
 
Example 36
Project: lams   File: CollectionBinder.java   View source code 5 votes vote down vote up
private static String buildOrderByClauseFromHql(String orderByFragment, PersistentClass associatedClass, String role) {
	if ( orderByFragment != null ) {
		if ( orderByFragment.length() == 0 ) {
			//order by id
			return "id asc";
		}
		else if ( "desc".equals( orderByFragment ) ) {
			return "id desc";
		}
	}
	return orderByFragment;
}
 
Example 37
Project: lams   File: PropertyFactory.java   View source code 5 votes vote down vote up
private static Constructor getConstructor(PersistentClass persistentClass) {
	if ( persistentClass == null || !persistentClass.hasPojoRepresentation() ) {
		return null;
	}

	try {
		return ReflectHelper.getDefaultConstructor( persistentClass.getMappedClass() );
	}
	catch( Throwable t ) {
		return null;
	}
}
 
Example 38
Project: lams   File: EntityBinder.java   View source code 5 votes vote down vote up
public EntityBinder(
		Entity ejb3Ann,
		org.hibernate.annotations.Entity hibAnn,
		XClass annotatedClass,
		PersistentClass persistentClass,
		Mappings mappings) {
	this.mappings = mappings;
	this.persistentClass = persistentClass;
	this.annotatedClass = annotatedClass;
	bindEjb3Annotation( ejb3Ann );
	bindHibernateAnnotation( hibAnn );
}
 
Example 39
Project: lams   File: JoinedSubclassEntityPersister.java   View source code 5 votes vote down vote up
/**
 * Essentially we are building a mapping that we can later use to determine whether a given "subclass table"
 * should be included in joins when JPA TREAT-AS is used.
 *
 * @param persistentClass
 * @param factory
 * @return
 */
private String[][] buildSubclassNamesBySubclassTableMapping(PersistentClass persistentClass, SessionFactoryImplementor factory) {
	// this value represents the number of subclasses (and not the class itself)
	final int numberOfSubclassTables = subclassTableNameClosure.length - coreTableSpan;
	if ( numberOfSubclassTables == 0 ) {
		return new String[0][];
	}

	final String[][] mapping = new String[numberOfSubclassTables][];
	processPersistentClassHierarchy( persistentClass, true, factory, mapping );
	return mapping;
}
 
Example 40
Project: lams   File: Dom4jInstantiator.java   View source code 5 votes vote down vote up
public Dom4jInstantiator(PersistentClass mappingInfo) {
	this.nodeName = mappingInfo.getNodeName();
	isInstanceNodeNames.add( nodeName );

	if ( mappingInfo.hasSubclasses() ) {
		Iterator itr = mappingInfo.getSubclassClosureIterator();
		while ( itr.hasNext() ) {
			final PersistentClass subclassInfo = ( PersistentClass ) itr.next();
			isInstanceNodeNames.add( subclassInfo.getNodeName() );
		}
	}
}