use of org.hibernate.boot.model.source.spi.FilterSource in project hibernate-orm by hibernate.
the class AbstractPluralAttributeSourceImpl method buildFilterSources.
private static FilterSource[] buildFilterSources(MappingDocument mappingDocument, PluralAttributeInfo pluralAttributeElement) {
final int size = pluralAttributeElement.getFilter().size();
if (size == 0) {
return null;
}
FilterSource[] results = new FilterSource[size];
for (int i = 0; i < size; i++) {
JaxbHbmFilterType element = pluralAttributeElement.getFilter().get(i);
results[i] = new FilterSourceImpl(mappingDocument, element);
}
return results;
}
use of org.hibernate.boot.model.source.spi.FilterSource in project hibernate-orm by hibernate.
the class ModelBinder method bindBasicEntityValues.
private void bindBasicEntityValues(MappingDocument sourceDocument, AbstractEntitySourceImpl entitySource, PersistentClass entityDescriptor) {
entityDescriptor.setEntityName(entitySource.getEntityNamingSource().getEntityName());
entityDescriptor.setJpaEntityName(entitySource.getEntityNamingSource().getJpaEntityName());
entityDescriptor.setClassName(entitySource.getEntityNamingSource().getClassName());
entityDescriptor.setDiscriminatorValue(entitySource.getDiscriminatorMatchValue() != null ? entitySource.getDiscriminatorMatchValue() : entityDescriptor.getEntityName());
// NOTE : entitySource#isLazy already accounts for MappingDefaults#areEntitiesImplicitlyLazy
if (StringHelper.isNotEmpty(entitySource.getProxy())) {
final String qualifiedProxyName = sourceDocument.qualifyClassName(entitySource.getProxy());
entityDescriptor.setProxyInterfaceName(qualifiedProxyName);
entityDescriptor.setLazy(true);
} else if (entitySource.isLazy()) {
entityDescriptor.setProxyInterfaceName(entityDescriptor.getClassName());
entityDescriptor.setLazy(true);
} else {
entityDescriptor.setProxyInterfaceName(null);
entityDescriptor.setLazy(false);
}
entityDescriptor.setAbstract(entitySource.isAbstract());
sourceDocument.getMetadataCollector().addImport(entitySource.getEntityNamingSource().getEntityName(), entitySource.getEntityNamingSource().getEntityName());
if (sourceDocument.getMappingDefaults().isAutoImportEnabled() && entitySource.getEntityNamingSource().getEntityName().indexOf('.') > 0) {
sourceDocument.getMetadataCollector().addImport(StringHelper.unqualify(entitySource.getEntityNamingSource().getEntityName()), entitySource.getEntityNamingSource().getEntityName());
}
if (entitySource.getTuplizerClassMap() != null) {
if (entitySource.getTuplizerClassMap().size() > 1) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfMultipleEntityModeSupport();
}
for (Map.Entry<EntityMode, String> tuplizerEntry : entitySource.getTuplizerClassMap().entrySet()) {
entityDescriptor.addTuplizer(tuplizerEntry.getKey(), tuplizerEntry.getValue());
}
}
if (StringHelper.isNotEmpty(entitySource.getXmlNodeName())) {
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
}
entityDescriptor.setDynamicInsert(entitySource.isDynamicInsert());
entityDescriptor.setDynamicUpdate(entitySource.isDynamicUpdate());
entityDescriptor.setBatchSize(entitySource.getBatchSize());
entityDescriptor.setSelectBeforeUpdate(entitySource.isSelectBeforeUpdate());
if (StringHelper.isNotEmpty(entitySource.getCustomPersisterClassName())) {
try {
entityDescriptor.setEntityPersisterClass(sourceDocument.getClassLoaderAccess().classForName(entitySource.getCustomPersisterClassName()));
} catch (ClassLoadingException e) {
throw new MappingException(String.format(Locale.ENGLISH, "Unable to load specified persister class : %s", entitySource.getCustomPersisterClassName()), e, sourceDocument.getOrigin());
}
}
bindCustomSql(sourceDocument, entitySource, entityDescriptor);
final JdbcEnvironment jdbcEnvironment = sourceDocument.getMetadataCollector().getDatabase().getJdbcEnvironment();
for (String tableName : entitySource.getSynchronizedTableNames()) {
final Identifier physicalTableName = sourceDocument.getBuildingOptions().getPhysicalNamingStrategy().toPhysicalTableName(jdbcEnvironment.getIdentifierHelper().toIdentifier(tableName), jdbcEnvironment);
entityDescriptor.addSynchronizedTable(physicalTableName.render(jdbcEnvironment.getDialect()));
}
for (FilterSource filterSource : entitySource.getFilterSources()) {
String condition = filterSource.getCondition();
if (condition == null) {
final FilterDefinition filterDefinition = sourceDocument.getMetadataCollector().getFilterDefinition(filterSource.getName());
if (filterDefinition != null) {
condition = filterDefinition.getDefaultFilterCondition();
}
}
entityDescriptor.addFilter(filterSource.getName(), condition, filterSource.shouldAutoInjectAliases(), filterSource.getAliasToTableMap(), filterSource.getAliasToEntityMap());
}
for (JaxbHbmNamedQueryType namedQuery : entitySource.getNamedQueries()) {
NamedQueryBinder.processNamedQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
}
for (JaxbHbmNamedNativeQueryType namedQuery : entitySource.getNamedNativeQueries()) {
NamedQueryBinder.processNamedNativeQuery(sourceDocument, namedQuery, entitySource.getEntityNamingSource().getEntityName() + ".");
}
entityDescriptor.setMetaAttributes(entitySource.getToolingHintContext().getMetaAttributeMap());
}
use of org.hibernate.boot.model.source.spi.FilterSource in project hibernate-orm by hibernate.
the class ModelBinder method bindCollectionMetadata.
private void bindCollectionMetadata(MappingDocument mappingDocument, PluralAttributeSource source, Collection binding) {
binding.setRole(source.getAttributeRole().getFullPath());
binding.setInverse(source.isInverse());
binding.setMutable(source.isMutable());
binding.setOptimisticLocked(source.isIncludedInOptimisticLocking());
if (source.getCustomPersisterClassName() != null) {
binding.setCollectionPersisterClass(mappingDocument.getClassLoaderAccess().classForName(mappingDocument.qualifyClassName(source.getCustomPersisterClassName())));
}
applyCaching(mappingDocument, source.getCaching(), binding);
// bind the collection type info
String typeName = source.getTypeInformation().getName();
Map typeParameters = new HashMap();
if (typeName != null) {
// see if there is a corresponding type-def
final TypeDefinition typeDef = mappingDocument.getMetadataCollector().getTypeDefinition(typeName);
if (typeDef != null) {
typeName = typeDef.getTypeImplementorClass().getName();
if (typeDef.getParameters() != null) {
typeParameters.putAll(typeDef.getParameters());
}
} else {
// it could be a unqualified class name, in which case we should qualify
// it with the implicit package name for this context, if one.
typeName = mappingDocument.qualifyClassName(typeName);
}
}
if (source.getTypeInformation().getParameters() != null) {
typeParameters.putAll(source.getTypeInformation().getParameters());
}
binding.setTypeName(typeName);
binding.setTypeParameters(typeParameters);
if (source.getFetchCharacteristics().getFetchTiming() == FetchTiming.DELAYED) {
binding.setLazy(true);
binding.setExtraLazy(source.getFetchCharacteristics().isExtraLazy());
} else {
binding.setLazy(false);
}
switch(source.getFetchCharacteristics().getFetchStyle()) {
case SELECT:
{
binding.setFetchMode(FetchMode.SELECT);
break;
}
case JOIN:
{
binding.setFetchMode(FetchMode.JOIN);
break;
}
case BATCH:
{
binding.setFetchMode(FetchMode.SELECT);
binding.setBatchSize(source.getFetchCharacteristics().getBatchSize());
break;
}
case SUBSELECT:
{
binding.setFetchMode(FetchMode.SELECT);
binding.setSubselectLoadable(true);
// todo : this could totally be done using a "symbol map" approach
binding.getOwner().setSubselectLoadableCollections(true);
break;
}
default:
{
throw new AssertionFailure("Unexpected FetchStyle : " + source.getFetchCharacteristics().getFetchStyle().name());
}
}
for (String name : source.getSynchronizedTableNames()) {
binding.getSynchronizedTables().add(name);
}
binding.setWhere(source.getWhere());
binding.setLoaderName(source.getCustomLoaderName());
if (source.getCustomSqlInsert() != null) {
binding.setCustomSQLInsert(source.getCustomSqlInsert().getSql(), source.getCustomSqlInsert().isCallable(), source.getCustomSqlInsert().getCheckStyle());
}
if (source.getCustomSqlUpdate() != null) {
binding.setCustomSQLUpdate(source.getCustomSqlUpdate().getSql(), source.getCustomSqlUpdate().isCallable(), source.getCustomSqlUpdate().getCheckStyle());
}
if (source.getCustomSqlDelete() != null) {
binding.setCustomSQLDelete(source.getCustomSqlDelete().getSql(), source.getCustomSqlDelete().isCallable(), source.getCustomSqlDelete().getCheckStyle());
}
if (source.getCustomSqlDeleteAll() != null) {
binding.setCustomSQLDeleteAll(source.getCustomSqlDeleteAll().getSql(), source.getCustomSqlDeleteAll().isCallable(), source.getCustomSqlDeleteAll().getCheckStyle());
}
if (source instanceof Sortable) {
final Sortable sortable = (Sortable) source;
if (sortable.isSorted()) {
binding.setSorted(true);
if (!sortable.getComparatorName().equals("natural")) {
binding.setComparatorClassName(sortable.getComparatorName());
}
} else {
binding.setSorted(false);
}
}
if (source instanceof Orderable) {
if (((Orderable) source).isOrdered()) {
binding.setOrderBy(((Orderable) source).getOrder());
}
}
final String cascadeStyle = source.getCascadeStyleName();
if (cascadeStyle != null && cascadeStyle.contains("delete-orphan")) {
binding.setOrphanDelete(true);
}
for (FilterSource filterSource : source.getFilterSources()) {
String condition = filterSource.getCondition();
if (condition == null) {
final FilterDefinition filterDefinition = mappingDocument.getMetadataCollector().getFilterDefinition(filterSource.getName());
if (filterDefinition != null) {
condition = filterDefinition.getDefaultFilterCondition();
}
}
binding.addFilter(filterSource.getName(), condition, filterSource.shouldAutoInjectAliases(), filterSource.getAliasToTableMap(), filterSource.getAliasToEntityMap());
}
}
use of org.hibernate.boot.model.source.spi.FilterSource in project hibernate-orm by hibernate.
the class PluralAttributeElementSourceManyToManyImpl method buildFilterSources.
private FilterSource[] buildFilterSources() {
final int size = jaxbManyToManyElement.getFilter().size();
if (size == 0) {
return NO_FILTER_SOURCES;
}
FilterSource[] results = new FilterSource[size];
for (int i = 0; i < size; i++) {
JaxbHbmFilterType element = jaxbManyToManyElement.getFilter().get(i);
results[i] = new FilterSourceImpl(sourceMappingDocument(), element);
}
return results;
}
use of org.hibernate.boot.model.source.spi.FilterSource in project hibernate-orm by hibernate.
the class AbstractEntitySourceImpl method buildFilterSources.
private FilterSource[] buildFilterSources() {
//todo for now, i think all EntityElement should support this.
if (JaxbHbmRootEntityType.class.isInstance(jaxbEntityMapping())) {
final JaxbHbmRootEntityType jaxbClassElement = (JaxbHbmRootEntityType) jaxbEntityMapping();
final int size = jaxbClassElement.getFilter().size();
if (size == 0) {
return NO_FILTER_SOURCES;
}
FilterSource[] results = new FilterSource[size];
for (int i = 0; i < size; i++) {
JaxbHbmFilterType element = jaxbClassElement.getFilter().get(i);
results[i] = new FilterSourceImpl(sourceMappingDocument(), element);
}
return results;
} else {
return NO_FILTER_SOURCES;
}
}
Aggregations