Skip to content

Commit

Permalink
#63 - Flesh out BindingCoordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Nov 4, 2023
1 parent ca586e9 commit b91f065
Show file tree
Hide file tree
Showing 17 changed files with 678 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* SPDX-License-Identifier: Apache-2.0
* Copyright: Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.models.orm.bind;

import org.hibernate.models.Internal;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.ValidIdRange;

import static org.jboss.logging.Logger.Level.INFO;

/**
* todo : find the proper min/max id range
*
* @author Steve Ebersole
*/
@Internal
public interface ModelBindingLogging extends BasicLogger {
String NAME = "org.hibernate.models.orm";

Logger MODEL_BINDING_LOGGER = Logger.getLogger( NAME );
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
* SPDX-License-Identifier: Apache-2.0
* Copyright: Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.models.orm.bind.spi;
package org.hibernate.models.orm.bind.internal;

import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.List;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.models.ModelsException;
import org.hibernate.models.orm.bind.spi.BindingContext;
import org.hibernate.models.orm.bind.spi.BindingOptions;
import org.hibernate.models.orm.bind.spi.QuotedIdentifierTarget;
import org.hibernate.models.source.spi.AnnotationDescriptor;
import org.hibernate.models.source.spi.AnnotationUsage;
import org.hibernate.models.source.spi.AttributeDescriptor;

import static org.hibernate.models.orm.bind.ModelBindingLogging.MODEL_BINDING_LOGGER;

/**
* @author Steve Ebersole
*/
Expand Down Expand Up @@ -98,4 +106,37 @@ public static <T,A extends Annotation> T getValue(AnnotationUsage<A> ann, String

return ann.getAttributeValue( attributeName, defaultValue );
}

public static void processSecondPassQueue(List<? extends SecondPass> secondPasses) {
if ( secondPasses == null ) {
return;
}

int processedCount = 0;
final Iterator<? extends SecondPass> secondPassItr = secondPasses.iterator();
while ( secondPassItr.hasNext() ) {
final SecondPass secondPass = secondPassItr.next();
try {
final boolean success = secondPass.process();
if ( success ) {
processedCount++;
secondPassItr.remove();
}
}
catch (Exception e) {
MODEL_BINDING_LOGGER.debug( "Error processing second pass", e );
}
}

if ( !secondPasses.isEmpty() ) {
if ( processedCount == 0 ) {
// there are second-passes in the queue, but we were not able to
// successfully process any of them. this is a non-changing
// error condition - just throw an exception
throw new ModelsException( "Unable to process second-pass list" );
}

processSecondPassQueue( secondPasses );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.models.ModelsException;
import org.hibernate.models.internal.CollectionHelper;
import org.hibernate.models.orm.bind.internal.binders.EntityTypeBinder;
import org.hibernate.models.orm.bind.internal.binders.IdentifiableTypeBinder;
import org.hibernate.models.orm.bind.internal.binders.ManagedTypeBinder;
import org.hibernate.models.orm.bind.internal.binders.TableBinder;
Expand Down Expand Up @@ -88,14 +89,18 @@ public MetadataBuildingContext getMetadataBuildingContext() {
public void registerTypeBinder(ManagedTypeMetadata type, ManagedTypeBinder binder) {
typeBinders.put( type.getClassDetails(), binder );

// if ( type instanceof IdentifiableTypeMetadata identifiableType ) {
// if ( identifiableType.getSuperType() != null ) {
// typeBindersBySuper.put(
// identifiableType.getSuperType().getClassDetails(),
// (IdentifiableTypeBinder) binder
// );
// }
// }
if ( type instanceof IdentifiableTypeMetadata identifiableType ) {
if ( identifiableType.getSuperType() != null ) {
typeBindersBySuper.put(
identifiableType.getSuperType().getClassDetails(),
(IdentifiableTypeBinder) binder
);
}
}

if ( binder instanceof EntityTypeBinder ) {
metadataBuildingContext.getMetadataCollector().addEntityBinding( ( (EntityTypeBinder) binder ).getTypeBinding() );
}
}

@Override
Expand All @@ -108,6 +113,11 @@ public IdentifiableTypeBinder getSuperTypeBinder(ClassDetails type) {
return typeBindersBySuper.get( type );
}

@Override
public void forEachType(NamedConsumer<ManagedTypeBinder> consumer) {
typeBinders.forEach( (classDetails, managedTypeBinder) -> consumer.consume( classDetails.getName(), managedTypeBinder ) );
}

@Override
public int getTableCount() {
return tableMap.size();
Expand Down
Loading

0 comments on commit b91f065

Please sign in to comment.