mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 13:14:50 +00:00
HHH-7049 - Add tests of org.hibernate.metamodel.internal.source stuff
This commit is contained in:
parent
b0f5c9758f
commit
107444ef61
38
hibernate-core/src/main/java/org/hibernate/TruthValue.java
Normal file
38
hibernate-core/src/main/java/org/hibernate/TruthValue.java
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate;
|
||||
|
||||
/**
|
||||
* An enumeration of truth values.
|
||||
* <p/>
|
||||
* Yes this *could* be handled with Boolean, but then you run into potential problems with premature
|
||||
* auto-unboxing.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum TruthValue {
|
||||
TRUE,
|
||||
FALSE,
|
||||
UNKNOWN
|
||||
}
|
@ -36,28 +36,30 @@
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.beans.BeanInfoHelper;
|
||||
import org.hibernate.metamodel.internal.source.hbm.Helper;
|
||||
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
||||
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding;
|
||||
import org.hibernate.metamodel.spi.binding.Cascadeable;
|
||||
import org.hibernate.metamodel.spi.binding.CollectionLaziness;
|
||||
import org.hibernate.metamodel.spi.binding.ComponentAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.spi.binding.Fetchable;
|
||||
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.MetaAttribute;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature;
|
||||
import org.hibernate.metamodel.spi.binding.CollectionLaziness;
|
||||
import org.hibernate.metamodel.spi.binding.EntityDiscriminator;
|
||||
import org.hibernate.metamodel.spi.binding.Fetchable;
|
||||
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.MetaAttribute;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature;
|
||||
import org.hibernate.metamodel.spi.binding.SimpleValueBinding;
|
||||
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.TypeDefinition;
|
||||
@ -76,23 +78,24 @@
|
||||
import org.hibernate.metamodel.spi.relational.TableSpecification;
|
||||
import org.hibernate.metamodel.spi.relational.Tuple;
|
||||
import org.hibernate.metamodel.spi.relational.UniqueKey;
|
||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||
import org.hibernate.metamodel.spi.source.MappingException;
|
||||
import org.hibernate.metamodel.spi.source.MetaAttributeContext;
|
||||
import org.hibernate.metamodel.spi.relational.Value;
|
||||
import org.hibernate.metamodel.spi.source.AttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
||||
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
||||
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||
import org.hibernate.metamodel.spi.source.EntitySource;
|
||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
||||
import org.hibernate.metamodel.internal.source.hbm.Helper;
|
||||
import org.hibernate.metamodel.spi.source.BasicPluralAttributeElementSource;
|
||||
import org.hibernate.metamodel.spi.source.ColumnBindingDefaults;
|
||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||
import org.hibernate.metamodel.spi.source.ComponentAttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.ConstraintSource;
|
||||
import org.hibernate.metamodel.spi.source.DerivedValueSource;
|
||||
import org.hibernate.metamodel.spi.source.DiscriminatorSource;
|
||||
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||
import org.hibernate.metamodel.spi.source.EntitySource;
|
||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||
import org.hibernate.metamodel.spi.source.LocalBindingContext;
|
||||
import org.hibernate.metamodel.spi.source.MappingException;
|
||||
import org.hibernate.metamodel.spi.source.MetaAttributeContext;
|
||||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
||||
import org.hibernate.metamodel.spi.source.Orderable;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeElementSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeNature;
|
||||
@ -109,7 +112,6 @@
|
||||
import org.hibernate.metamodel.spi.source.TableSource;
|
||||
import org.hibernate.metamodel.spi.source.ToOneAttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.UniqueConstraintSource;
|
||||
import org.hibernate.metamodel.spi.relational.Value;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
@ -413,6 +415,23 @@ private void bindVersion(EntityBinding entityBinding, RootEntitySource entitySou
|
||||
entityBinding.getHierarchyDetails().setVersioningAttributeBinding( attributeBinding );
|
||||
}
|
||||
|
||||
public static final ColumnBindingDefaults DISCRIMINATOR_COLUMN_BINDING_DEFAULTS = new ColumnBindingDefaults() {
|
||||
@Override
|
||||
public boolean areValuesIncludedInInsertByDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areValuesIncludedInUpdateByDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areValuesNullableByDefault() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private void bindDiscriminator(RootEntitySource entitySource, EntityBinding entityBinding) {
|
||||
final DiscriminatorSource discriminatorSource = entitySource.getDiscriminatorSource();
|
||||
if ( discriminatorSource == null ) {
|
||||
@ -422,7 +441,8 @@ private void bindDiscriminator(RootEntitySource entitySource, EntityBinding enti
|
||||
EntityDiscriminator discriminator = new EntityDiscriminator();
|
||||
SimpleValue relationalValue = makeSimpleValue(
|
||||
entityBinding,
|
||||
discriminatorSource.getDiscriminatorRelationalValueSource()
|
||||
discriminatorSource.getDiscriminatorRelationalValueSource(),
|
||||
DISCRIMINATOR_COLUMN_BINDING_DEFAULTS
|
||||
);
|
||||
discriminator.setBoundValue( relationalValue );
|
||||
|
||||
@ -1108,12 +1128,12 @@ private List<SimpleValueBinding> createSimpleRelationalValues(
|
||||
|
||||
if ( ColumnSource.class.isInstance( valueSource ) ) {
|
||||
final ColumnSource columnSource = ColumnSource.class.cast( valueSource );
|
||||
final Column column = makeColumn( (ColumnSource) valueSource, table );
|
||||
final Column column = makeColumn( (ColumnSource) valueSource, relationalValueSourceContainer, table );
|
||||
valueBindings.add(
|
||||
new SimpleValueBinding(
|
||||
column,
|
||||
columnSource.isIncludedInInsert(),
|
||||
columnSource.isIncludedInUpdate()
|
||||
decode( columnSource.isIncludedInInsert(), relationalValueSourceContainer.areValuesIncludedInInsertByDefault() ),
|
||||
decode( columnSource.isIncludedInUpdate(), relationalValueSourceContainer.areValuesIncludedInUpdateByDefault() )
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -1136,13 +1156,7 @@ private List<SimpleValueBinding> createSimpleRelationalValues(
|
||||
.getPrimaryTable()
|
||||
.locateOrCreateColumn( name );
|
||||
column.setNullable( relationalValueSourceContainer.areValuesNullableByDefault() );
|
||||
valueBindings.add(
|
||||
new SimpleValueBinding(
|
||||
column,
|
||||
relationalValueSourceContainer.areValuesIncludedInInsertByDefault(),
|
||||
relationalValueSourceContainer.areValuesIncludedInUpdateByDefault()
|
||||
)
|
||||
);
|
||||
valueBindings.add( new SimpleValueBinding( column ) );
|
||||
}
|
||||
return valueBindings;
|
||||
}
|
||||
@ -1153,23 +1167,29 @@ private String quoteIdentifier(String identifier) {
|
||||
|
||||
private SimpleValue makeSimpleValue(
|
||||
EntityBinding entityBinding,
|
||||
RelationalValueSource valueSource) {
|
||||
RelationalValueSource valueSource,
|
||||
ColumnBindingDefaults columnBindingDefaults) {
|
||||
final TableSpecification table = entityBinding.locateTable( valueSource.getContainingTableName() );
|
||||
|
||||
if ( ColumnSource.class.isInstance( valueSource ) ) {
|
||||
return makeColumn( (ColumnSource) valueSource, table );
|
||||
return makeColumn( (ColumnSource) valueSource, columnBindingDefaults, table );
|
||||
}
|
||||
else {
|
||||
return makeDerivedValue( (DerivedValueSource) valueSource, table );
|
||||
}
|
||||
}
|
||||
|
||||
private Column makeColumn(ColumnSource columnSource, TableSpecification table) {
|
||||
private Column makeColumn(
|
||||
ColumnSource columnSource,
|
||||
ColumnBindingDefaults columnBindingDefaults,
|
||||
TableSpecification table) {
|
||||
String name = columnSource.getName();
|
||||
name = metadata.getOptions().getNamingStrategy().columnName( name );
|
||||
name = quoteIdentifier( name );
|
||||
final Column column = table.locateOrCreateColumn( name );
|
||||
column.setNullable( columnSource.isNullable() );
|
||||
column.setNullable(
|
||||
decode( columnSource.isNullable(), columnBindingDefaults.areValuesNullableByDefault() )
|
||||
);
|
||||
column.setDefaultValue( columnSource.getDefaultValue() );
|
||||
column.setSqlType( columnSource.getSqlType() );
|
||||
column.setSize( columnSource.getSize() );
|
||||
@ -1182,6 +1202,20 @@ private Column makeColumn(ColumnSource columnSource, TableSpecification table) {
|
||||
return column;
|
||||
}
|
||||
|
||||
private boolean decode(TruthValue truthValue, boolean defaultValue) {
|
||||
switch ( truthValue ) {
|
||||
case FALSE: {
|
||||
return false;
|
||||
}
|
||||
case TRUE: {
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DerivedValue makeDerivedValue(DerivedValueSource derivedValueSource, TableSpecification table) {
|
||||
return table.locateOrCreateDerivedValue( derivedValueSource.getExpression() );
|
||||
}
|
||||
|
@ -23,10 +23,10 @@
|
||||
*/
|
||||
package org.hibernate.metamodel.internal.source.annotations.attribute;
|
||||
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.metamodel.spi.relational.Datatype;
|
||||
import org.hibernate.metamodel.spi.relational.Size;
|
||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
@ -53,8 +53,8 @@ public String getName() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return columnValues.isNullable();
|
||||
public TruthValue isNullable() {
|
||||
return columnValues.isNullable() ? TruthValue.TRUE : TruthValue.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -96,13 +96,13 @@ public String getComment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInInsert() {
|
||||
return columnValues.isInsertable();
|
||||
public TruthValue isIncludedInInsert() {
|
||||
return columnValues.isInsertable() ? TruthValue.TRUE : TruthValue.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInUpdate() {
|
||||
return columnValues.isUpdatable();
|
||||
public TruthValue isIncludedInUpdate() {
|
||||
return columnValues.isUpdatable() ? TruthValue.TRUE : TruthValue.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,16 +60,6 @@ public String getPropertyAccessorName() {
|
||||
return attribute.getAccessType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return attribute.isInsertable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return attribute.isUpdatable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
return attribute.getPropertyGeneration();
|
||||
@ -119,17 +109,17 @@ public Iterable<MetaAttributeSource> metaAttributes() {
|
||||
|
||||
@Override
|
||||
public boolean areValuesIncludedInInsertByDefault() {
|
||||
return true;
|
||||
return attribute.isInsertable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areValuesIncludedInUpdateByDefault() {
|
||||
return true;
|
||||
return attribute.isUpdatable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areValuesNullableByDefault() {
|
||||
return true;
|
||||
return attribute.isOptional();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,16 +169,6 @@ public ExplicitHibernateTypeSource getTypeInformation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
return null;
|
||||
|
@ -23,10 +23,10 @@
|
||||
*/
|
||||
package org.hibernate.metamodel.internal.source.hbm;
|
||||
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.metamodel.spi.relational.Datatype;
|
||||
import org.hibernate.metamodel.spi.relational.Size;
|
||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
|
||||
/**
|
||||
* Implementation of a {@link ColumnSource} when the column is declared as just the name via the column XML
|
||||
@ -37,29 +37,29 @@
|
||||
class ColumnAttributeSourceImpl implements ColumnSource {
|
||||
private final String tableName;
|
||||
private final String columnName;
|
||||
private boolean includedInInsert;
|
||||
private boolean includedInUpdate;
|
||||
private boolean isForceNotNull;
|
||||
private TruthValue includedInInsert;
|
||||
private TruthValue includedInUpdate;
|
||||
private TruthValue nullable;
|
||||
|
||||
ColumnAttributeSourceImpl(
|
||||
String tableName,
|
||||
String columnName,
|
||||
boolean includedInInsert,
|
||||
boolean includedInUpdate) {
|
||||
this(tableName, columnName, includedInInsert, includedInUpdate, false);
|
||||
TruthValue includedInInsert,
|
||||
TruthValue includedInUpdate) {
|
||||
this( tableName, columnName, includedInInsert, includedInUpdate, TruthValue.UNKNOWN );
|
||||
}
|
||||
|
||||
ColumnAttributeSourceImpl(
|
||||
String tableName,
|
||||
String columnName,
|
||||
boolean includedInInsert,
|
||||
boolean includedInUpdate,
|
||||
boolean isForceNotNull) {
|
||||
TruthValue includedInInsert,
|
||||
TruthValue includedInUpdate,
|
||||
TruthValue nullable) {
|
||||
this.tableName = tableName;
|
||||
this.columnName = columnName;
|
||||
this.includedInInsert = includedInInsert;
|
||||
this.includedInUpdate = includedInUpdate;
|
||||
this.isForceNotNull = isForceNotNull;
|
||||
this.nullable = nullable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,12 +68,12 @@ public Nature getNature() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInInsert() {
|
||||
public TruthValue isIncludedInInsert() {
|
||||
return includedInInsert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInUpdate() {
|
||||
public TruthValue isIncludedInUpdate() {
|
||||
return includedInUpdate;
|
||||
}
|
||||
|
||||
@ -88,8 +88,8 @@ public String getName() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return !isForceNotNull;
|
||||
public TruthValue isNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,11 +23,11 @@
|
||||
*/
|
||||
package org.hibernate.metamodel.internal.source.hbm;
|
||||
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbColumnElement;
|
||||
import org.hibernate.metamodel.spi.relational.Datatype;
|
||||
import org.hibernate.metamodel.spi.relational.Size;
|
||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
@ -35,29 +35,29 @@
|
||||
class ColumnSourceImpl implements ColumnSource {
|
||||
private final String tableName;
|
||||
private final JaxbColumnElement columnElement;
|
||||
private boolean includedInInsert;
|
||||
private boolean includedInUpdate;
|
||||
private final boolean isForceNotNull;
|
||||
private final TruthValue includedInInsert;
|
||||
private final TruthValue includedInUpdate;
|
||||
private final TruthValue nullable;
|
||||
|
||||
ColumnSourceImpl(
|
||||
String tableName,
|
||||
JaxbColumnElement columnElement,
|
||||
boolean isIncludedInInsert,
|
||||
boolean isIncludedInUpdate) {
|
||||
this(tableName, columnElement, isIncludedInInsert, isIncludedInUpdate, false);
|
||||
TruthValue isIncludedInInsert,
|
||||
TruthValue isIncludedInUpdate) {
|
||||
this( tableName, columnElement, isIncludedInInsert, isIncludedInUpdate, TruthValue.UNKNOWN );
|
||||
}
|
||||
|
||||
ColumnSourceImpl(
|
||||
String tableName,
|
||||
JaxbColumnElement columnElement,
|
||||
boolean isIncludedInInsert,
|
||||
boolean isIncludedInUpdate,
|
||||
boolean isForceNotNull) {
|
||||
TruthValue isIncludedInInsert,
|
||||
TruthValue isIncludedInUpdate,
|
||||
TruthValue nullable) {
|
||||
this.tableName = tableName;
|
||||
this.columnElement = columnElement;
|
||||
this.isForceNotNull = isForceNotNull;
|
||||
includedInInsert = isIncludedInInsert;
|
||||
includedInUpdate = isIncludedInUpdate;
|
||||
this.nullable = nullable;
|
||||
this.includedInInsert = isIncludedInInsert;
|
||||
this.includedInUpdate = isIncludedInUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,9 +71,8 @@ public String getName() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
if(isForceNotNull)return false;
|
||||
return ! columnElement.isNotNull();
|
||||
public TruthValue isNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -127,12 +126,12 @@ public String getComment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInInsert() {
|
||||
public TruthValue isIncludedInInsert() {
|
||||
return includedInInsert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInUpdate() {
|
||||
public TruthValue isIncludedInUpdate() {
|
||||
return includedInUpdate;
|
||||
}
|
||||
|
||||
|
@ -185,16 +185,6 @@ public String getPropertyAccessorName() {
|
||||
return componentElement.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return componentElement.isInsert();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return componentElement.isUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
// todo : is this correct here?
|
||||
@ -218,12 +208,12 @@ public Iterable<MetaAttributeSource> metaAttributes() {
|
||||
|
||||
@Override
|
||||
public boolean areValuesIncludedInInsertByDefault() {
|
||||
return isInsertable();
|
||||
return componentElement.isInsert();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areValuesIncludedInUpdateByDefault() {
|
||||
return isUpdatable();
|
||||
return componentElement.isUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +30,7 @@
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.CustomSqlElement;
|
||||
@ -366,9 +367,9 @@ public static List<RelationalValueSource> buildValueSources(
|
||||
new ColumnAttributeSourceImpl(
|
||||
valueSourcesAdapter.getContainingTableName(),
|
||||
valueSourcesAdapter.getColumnAttribute(),
|
||||
valueSourcesAdapter.isIncludedInInsertByDefault(),
|
||||
valueSourcesAdapter.isIncludedInUpdateByDefault(),
|
||||
valueSourcesAdapter.isForceNotNull()
|
||||
valueSourcesAdapter.isIncludedInInsertByDefault() ? TruthValue.TRUE : TruthValue.FALSE,
|
||||
valueSourcesAdapter.isIncludedInUpdateByDefault() ? TruthValue.TRUE : TruthValue.FALSE,
|
||||
valueSourcesAdapter.isForceNotNull() ? TruthValue.FALSE : TruthValue.TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -400,9 +401,9 @@ else if ( valueSourcesAdapter.getColumnOrFormulaElements() != null
|
||||
new ColumnSourceImpl(
|
||||
valueSourcesAdapter.getContainingTableName(),
|
||||
(JaxbColumnElement) columnOrFormulaElement,
|
||||
valueSourcesAdapter.isIncludedInInsertByDefault(),
|
||||
valueSourcesAdapter.isIncludedInUpdateByDefault(),
|
||||
valueSourcesAdapter.isForceNotNull()
|
||||
valueSourcesAdapter.isIncludedInInsertByDefault() ? TruthValue.TRUE : TruthValue.FALSE,
|
||||
valueSourcesAdapter.isIncludedInUpdateByDefault() ? TruthValue.TRUE : TruthValue.FALSE,
|
||||
valueSourcesAdapter.isForceNotNull() ? TruthValue.FALSE : TruthValue.TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -104,16 +104,6 @@ public String getPropertyAccessorName() {
|
||||
return manyToOneElement.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return manyToOneElement.isInsert();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return manyToOneElement.isUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
return PropertyGeneration.NEVER;
|
||||
|
@ -119,16 +119,6 @@ public String getPropertyAccessorName() {
|
||||
return propertyElement.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return Helper.getBooleanValue( propertyElement.isInsert(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return Helper.getBooleanValue( propertyElement.isUpdate(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
return PropertyGeneration.parse( propertyElement.getGenerated() );
|
||||
|
@ -24,6 +24,7 @@
|
||||
package org.hibernate.metamodel.internal.source.hbm;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbCacheElement;
|
||||
@ -217,8 +218,8 @@ public RelationalValueSource getDiscriminatorRelationalValueSource() {
|
||||
return new ColumnAttributeSourceImpl(
|
||||
null, // root table
|
||||
discriminatorElement.getColumnAttribute(),
|
||||
discriminatorElement.isInsert(),
|
||||
discriminatorElement.isInsert()
|
||||
discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE,
|
||||
discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE
|
||||
);
|
||||
}
|
||||
else if ( StringHelper.isNotEmpty( discriminatorElement.getFormulaAttribute() ) ) {
|
||||
@ -228,8 +229,8 @@ else if ( discriminatorElement.getColumn() != null ) {
|
||||
return new ColumnSourceImpl(
|
||||
null, // root table
|
||||
discriminatorElement.getColumn(),
|
||||
discriminatorElement.isInsert(),
|
||||
discriminatorElement.isInsert()
|
||||
discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE,
|
||||
discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE
|
||||
);
|
||||
}
|
||||
else if ( StringHelper.isNotEmpty( discriminatorElement.getFormula() ) ) {
|
||||
|
@ -128,16 +128,6 @@ public String getPropertyAccessorName() {
|
||||
return idElement.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyGeneration getGeneration() {
|
||||
return PropertyGeneration.INSERT;
|
||||
@ -170,7 +160,7 @@ public boolean areValuesIncludedInInsertByDefault() {
|
||||
|
||||
@Override
|
||||
public boolean areValuesIncludedInUpdateByDefault() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,16 +116,6 @@ public String getPropertyAccessorName() {
|
||||
return timestampElement.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Value<PropertyGeneration> propertyGenerationValue = new Value<PropertyGeneration>(
|
||||
new Value.DeferredInitializer<PropertyGeneration>() {
|
||||
@Override
|
||||
|
@ -116,16 +116,6 @@ public String getPropertyAccessorName() {
|
||||
return versionElement.getAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return Helper.getBooleanValue( versionElement.isInsert(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdatable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Value<PropertyGeneration> propertyGenerationValue = new Value<PropertyGeneration>(
|
||||
new Value.DeferredInitializer<PropertyGeneration>() {
|
||||
@Override
|
||||
@ -171,7 +161,7 @@ public boolean isVirtualAttribute() {
|
||||
|
||||
@Override
|
||||
public boolean areValuesIncludedInInsertByDefault() {
|
||||
return true;
|
||||
return Helper.getBooleanValue( versionElement.isInsert(), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.spi.source;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ColumnBindingDefaults {
|
||||
/**
|
||||
* How should non-specification of value insertion by the individual value sources here be
|
||||
* interpreted in terms of defaulting that value.
|
||||
*
|
||||
* @return {@code true} Indicates that insertions are enabled by default for all value sources which
|
||||
* do not explicitly specify.
|
||||
*/
|
||||
boolean areValuesIncludedInInsertByDefault();
|
||||
|
||||
/**
|
||||
* How should non-specification of value updating by the individual value sources here be
|
||||
* interpreted in terms of defaulting that value.
|
||||
*
|
||||
* @return {@code true} Indicates that updates are enabled by default for all value sources which
|
||||
* do not explicitly specify.
|
||||
*/
|
||||
boolean areValuesIncludedInUpdateByDefault();
|
||||
|
||||
/**
|
||||
* How should non-specification of value nullability by the individual value sources here be
|
||||
* interpreted in terms of defaulting that value.
|
||||
*
|
||||
* @return {@code true} Indicates that insertions are enabled by default for all value sources which
|
||||
* do not explicitly specify.
|
||||
*/
|
||||
boolean areValuesNullableByDefault();
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
*/
|
||||
package org.hibernate.metamodel.spi.source;
|
||||
|
||||
import org.hibernate.TruthValue;
|
||||
import org.hibernate.metamodel.spi.relational.Datatype;
|
||||
import org.hibernate.metamodel.spi.relational.Size;
|
||||
|
||||
@ -63,7 +64,7 @@ public interface ColumnSource extends RelationalValueSource {
|
||||
*
|
||||
* @return {@code true} indicates it is nullable; {@code false} non-nullable.
|
||||
*/
|
||||
public boolean isNullable();
|
||||
public TruthValue isNullable();
|
||||
|
||||
/**
|
||||
* Obtain a specified default value for the column
|
||||
@ -119,12 +120,12 @@ public interface ColumnSource extends RelationalValueSource {
|
||||
*
|
||||
* @return {@code true} indicates the column is written on insert from this attribute
|
||||
*/
|
||||
public boolean isIncludedInInsert();
|
||||
public TruthValue isIncludedInInsert();
|
||||
|
||||
/**
|
||||
* Is the described column written to as part of updates for the attribute being mapped.
|
||||
*
|
||||
* @return {@code true} indicates the column is written on update from this attribute
|
||||
*/
|
||||
public boolean isIncludedInUpdate();
|
||||
public TruthValue isIncludedInUpdate();
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface RelationalValueSourceContainer {
|
||||
public interface RelationalValueSourceContainer extends ColumnBindingDefaults {
|
||||
/**
|
||||
* Obtain the contained {@link RelationalValueSource} references.
|
||||
*
|
||||
@ -50,30 +50,4 @@ public interface RelationalValueSourceContainer {
|
||||
*/
|
||||
public List<RelationalValueSource> relationalValueSources();
|
||||
|
||||
/**
|
||||
* How should non-specification of value insertion by the individual value sources here be
|
||||
* interpreted in terms of defaulting that value.
|
||||
*
|
||||
* @return {@code true} Indicates that insertions are enabled by default for all value sources which
|
||||
* do not explicitly specify.
|
||||
*/
|
||||
public boolean areValuesIncludedInInsertByDefault();
|
||||
|
||||
/**
|
||||
* How should non-specification of value updating by the individual value sources here be
|
||||
* interpreted in terms of defaulting that value.
|
||||
*
|
||||
* @return {@code true} Indicates that updates are enabled by default for all value sources which
|
||||
* do not explicitly specify.
|
||||
*/
|
||||
public boolean areValuesIncludedInUpdateByDefault();
|
||||
|
||||
/**
|
||||
* How should non-specification of value nullability by the individual value sources here be
|
||||
* interpreted in terms of defaulting that value.
|
||||
*
|
||||
* @return {@code true} Indicates that insertions are enabled by default for all value sources which
|
||||
* do not explicitly specify.
|
||||
*/
|
||||
public boolean areValuesNullableByDefault();
|
||||
}
|
||||
|
@ -46,22 +46,6 @@ public interface SingularAttributeSource extends AttributeSource, RelationalValu
|
||||
*/
|
||||
public SingularAttributeNature getNature();
|
||||
|
||||
/**
|
||||
* Determine whether this attribute is insertable.
|
||||
*
|
||||
* @return {@code true} indicates the attribute value should be used in the {@code SQL INSERT}; {@code false}
|
||||
* indicates it should not.
|
||||
*/
|
||||
public boolean isInsertable();
|
||||
|
||||
/**
|
||||
* Determine whether this attribute is updateable.
|
||||
*
|
||||
* @return {@code true} indicates the attribute value should be used in the {@code SQL UPDATE}; {@code false}
|
||||
* indicates it should not.
|
||||
*/
|
||||
public boolean isUpdatable();
|
||||
|
||||
/**
|
||||
* Obtain a description of if/when the attribute value is generated by the database.
|
||||
*
|
||||
|
@ -24,7 +24,6 @@
|
||||
package org.hibernate.metamodel.internal.source;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
@ -34,10 +33,8 @@
|
||||
import org.hibernate.metamodel.internal.source.hbm.HbmMetadataSourceProcessorImpl;
|
||||
import org.hibernate.metamodel.spi.MetadataSourceProcessor;
|
||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||
import org.hibernate.metamodel.spi.source.ColumnSource;
|
||||
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||
import org.hibernate.metamodel.spi.source.IdentifierSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
import org.hibernate.metamodel.spi.source.RootEntitySource;
|
||||
import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
|
||||
import org.hibernate.metamodel.spi.source.SingularAttributeNature;
|
||||
@ -123,11 +120,6 @@ private void testUserEntitySources(MetadataSourceProcessor processor) {
|
||||
assertEquals( "id", identifierAttributeSource.getName() );
|
||||
assertTrue( identifierAttributeSource.isSingular() );
|
||||
assertFalse( identifierAttributeSource.isVirtualAttribute() );
|
||||
// todo : see note about semantic interpretation below ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// todo : also, it's not really the attribute that is insertable/updatable; it is its individual values
|
||||
assertTrue( identifierAttributeSource.isInsertable() );
|
||||
assertFalse( identifierAttributeSource.isUpdatable() );
|
||||
// todo : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertFalse( identifierAttributeSource.isLazy() );
|
||||
assertEquals( SingularAttributeNature.BASIC, identifierAttributeSource.getNature() );
|
||||
assertEquals( PropertyGeneration.INSERT, identifierAttributeSource.getGeneration() );
|
||||
@ -141,7 +133,7 @@ private void testUserEntitySources(MetadataSourceProcessor processor) {
|
||||
//
|
||||
// So do sources simply return explicit user values? Or do they consider such semantic analysis?
|
||||
assertTrue( identifierAttributeSource.areValuesIncludedInInsertByDefault() );
|
||||
assertTrue( identifierAttributeSource.areValuesIncludedInUpdateByDefault() );
|
||||
assertFalse( identifierAttributeSource.areValuesIncludedInUpdateByDefault() );
|
||||
assertFalse( identifierAttributeSource.areValuesNullableByDefault() );
|
||||
|
||||
// todo : return collections? or iterables?
|
||||
|
Loading…
x
Reference in New Issue
Block a user