public boolean isValid(Mapping mapping) throws MappingException { return getColumnSpan()==getType().getColumnSpan(mapping); }
private void applyNestedType(SimpleValue value, Element propertyMapping) { final Properties typeParameters = value.getTypeParameters(); final Element typeMapping = propertyMapping.addElement( "type" ); final String typeName = getBasicTypeName( value.getType() ); typeMapping.addAttribute( "name", typeName ); if ( isEnumType( value.getType(), typeName ) ) { // Proper handling of enumeration type mapEnumerationType( typeMapping, value.getType(), typeParameters ); } else { // By default copying all Hibernate properties for ( Object object : typeParameters.keySet() ) { final String keyType = (String) object; final String property = typeParameters.getProperty( keyType ); if ( property != null ) { typeMapping.addElement( "param" ).addAttribute( "name", keyType ).setText( property ); } } } }
identifierGenerator = identifierGeneratorFactory.createIdentifierGenerator( identifierGeneratorStrategy, getType(), params );
@Test @TestForIssue( jiraKey = "HHH-8630" ) public void testIt() { final PersistentClass entityBinding = metadata().getEntityBinding( AggregatedTypeValue.class.getName() ); final Property attributesBinding = entityBinding.getProperty( "attributes" ); final org.hibernate.mapping.Map attributesMap = (org.hibernate.mapping.Map) attributesBinding.getValue(); final SimpleValue mapKey = assertTyping( SimpleValue.class, attributesMap.getIndex() ); final BasicType mapKeyType = assertTyping( BasicType.class, mapKey.getType() ); assertTrue( String.class.equals( mapKeyType.getReturnedClass() ) ); // let's also make sure the @MapKeyColumn got applied assertThat( mapKey.getColumnSpan(), is(1) ); final org.hibernate.mapping.Column mapKeyColumn = assertTyping( org.hibernate.mapping.Column .class, mapKey.getColumnIterator().next() ); assertThat( mapKeyColumn.getName(), equalTo( "attribute_name" ) ); }
@Test public void testNonAutoApplyHandling() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester.class ) .getMetadataBuilder() .applyAttributeConverter( NotAutoAppliedConverter.class, false ) .build(); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); Property nameProp = tester.getProperty( "name" ); SimpleValue nameValue = (SimpleValue) nameProp.getValue(); Type type = nameValue.getType(); assertNotNull( type ); if ( AttributeConverterTypeAdapter.class.isInstance( type ) ) { fail( "AttributeConverter with autoApply=false was auto applied" ); } } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }
Property nameProp = tester.getProperty( "convertibleEnum" ); SimpleValue nameValue = (SimpleValue) nameProp.getValue(); Type type = nameValue.getType(); assertNotNull( type ); assertTyping( BasicType.class, type );
@Test public void testBasicOperation() { SimpleValue simpleValue = new SimpleValue( new MetadataBuildingContextTestingImpl() ); simpleValue.setJpaAttributeConverterDescriptor( new InstanceBasedConverterDescriptor( new StringClobConverter(), new ClassmateContext() ) ); simpleValue.setTypeUsingReflection( IrrelevantEntity.class.getName(), "name" ); Type type = simpleValue.getType(); assertNotNull( type ); if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { fail( "AttributeConverter not applied" ); } AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type ); assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); assertEquals( Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType() ); }
@Test public void testBasicConverterDisableApplication() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester2.class ) .getMetadataBuilder() .applyAttributeConverter( StringClobConverter.class, true ) .build(); PersistentClass tester = metadata.getEntityBinding( Tester2.class.getName() ); Property nameProp = tester.getProperty( "name" ); SimpleValue nameValue = (SimpleValue) nameProp.getValue(); Type type = nameValue.getType(); assertNotNull( type ); if ( AttributeConverterTypeAdapter.class.isInstance( type ) ) { fail( "AttributeConverter applied (should not have been)" ); } AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type ); assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); assertEquals( Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType() ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }
@Test public void testBasicConverterApplication() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester.class ) .getMetadataBuilder() .applyAttributeConverter( StringClobConverter.class, true ) .build(); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); Property nameProp = tester.getProperty( "name" ); SimpleValue nameValue = (SimpleValue) nameProp.getValue(); Type type = nameValue.getType(); assertNotNull( type ); assertTyping( BasicType.class, type ); if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { fail( "AttributeConverter not applied" ); } AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type ); assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); assertEquals( Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType() ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }
@Test @TestForIssue(jiraKey = "HHH-8462") public void testBasicOrmXmlConverterApplication() { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester.class ) .addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/orm.xml" ) ) .getMetadataBuilder() .build(); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); Property nameProp = tester.getProperty( "name" ); SimpleValue nameValue = (SimpleValue) nameProp.getValue(); Type type = nameValue.getType(); assertNotNull( type ); if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { fail( "AttributeConverter not applied" ); } AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type ); assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); assertEquals( Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType() ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }
@Test @FailureExpected( jiraKey = "HHH-9089" ) public void testEnumTypeInterpretation() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { final Metadata metadata = new MetadataSources( ssr ) .addAnnotatedClass( Customer.class ) .buildMetadata(); PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() ); Property investmentsProperty = classMetadata.getProperty( "investments" ); Collection investmentsValue = (Collection) investmentsProperty.getValue(); Component investmentMetadata = (Component) investmentsValue.getElement(); Value descriptionValue = investmentMetadata.getProperty( "description" ).getValue(); assertEquals( 1, descriptionValue.getColumnSpan() ); Column selectable = (Column) descriptionValue.getColumnIterator().next(); assertEquals( 500, selectable.getLength() ); Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue(); SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue(); CustomType currencyType = (CustomType) currencyMetadata.getType(); int[] currencySqlTypes = currencyType.sqlTypes( metadata ); assertEquals( 1, currencySqlTypes.length ); assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } } }
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue(); SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue(); CustomType currencyType = (CustomType) currencyMetadata.getType(); int[] currencySqlTypes = currencyType.sqlTypes( metadata ); assertEquals( 1, currencySqlTypes.length );
public boolean isValid(Mapping mapping) throws MappingException { return getColumnSpan()==getType().getColumnSpan(mapping); }
public boolean isValid(Mapping mapping) throws MappingException { return getColumnSpan()==getType().getColumnSpan(mapping); }
public boolean isValid(Mapping mapping) throws MappingException { return getColumnSpan()==getType().getColumnSpan(mapping); }
public boolean isValid(Mapping mapping) throws MappingException { return getColumnSpan()==getType().getColumnSpan(mapping); }
getType(), params, dialect
getType(), params, dialect
private static void bindVersion(GrailsDomainClassProperty version, RootClass entity, Mappings mappings, String sessionFactoryBeanName) { SimpleValue val = new SimpleValue(mappings, entity.getTable()); bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName); if (val.isTypeSpecified()) { if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType || val.getType() instanceof TimestampType)) { LOG.warn("Invalid version class specified in " + version.getDomainClass().getClazz().getName() + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version."); return; } } else { val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp"); } Property prop = new Property(); prop.setValue(val); bindProperty(version, prop, mappings); val.setNullValue("undefined"); entity.setVersion(prop); entity.addProperty(prop); }
protected void bindVersion(PersistentProperty version, RootClass entity, Mappings mappings, String sessionFactoryBeanName) { if(version != null) { SimpleValue val = new SimpleValue(mappings, entity.getTable()); bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName); if (val.isTypeSpecified()) { if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType || val.getType() instanceof TimestampType)) { LOG.warn("Invalid version class specified in " + version.getOwner().getName() + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version."); return; } } else { val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp"); } Property prop = new Property(); prop.setValue(val); bindProperty(version, prop, mappings); val.setNullValue("undefined"); entity.setVersion(prop); entity.setOptimisticLockMode(0); // 0 is to use version column entity.addProperty(prop); } }