public void copyTypeFrom( SimpleValue sourceValue ) { setTypeName( sourceValue.getTypeName() ); setTypeParameters( sourceValue.getTypeParameters() ); type = sourceValue.type; attributeConverterDescriptor = sourceValue.attributeConverterDescriptor; }
if ( simpleValue.getTypeName() != null && simpleValue.getTypeName().length() > 0 && simpleValue.getMetadata().getTypeResolver().basic( simpleValue.getTypeName() ) == null ) { try { Class typeClass = buildingContext.getBootstrapContext().getClassLoaderAccess().classForName( simpleValue.getTypeName() ); throw new MappingException( "Could not determine type for: " + simpleValue.getTypeName(), e );
private void resolveLob(final SingularAttributeSourceBasic attributeSource, SimpleValue value) { // Resolves whether the property is LOB based on the type attribute on the attribute property source. // Essentially this expects the type to map to a CLOB/NCLOB/BLOB sql type internally and compares. if ( !value.isLob() && value.getTypeName() != null ) { final TypeResolver typeResolver = attributeSource.getBuildingContext().getMetadataCollector().getTypeResolver(); final BasicType basicType = typeResolver.basic( value.getTypeName() ); if ( basicType instanceof AbstractSingleColumnStandardBasicType ) { if ( isLob( ( (AbstractSingleColumnStandardBasicType) basicType ).getSqlTypeDescriptor().getSqlType(), null ) ) { value.makeLob(); } } } // If the prior check didn't set the lob flag, this will inspect the column sql-type attribute value and // if this maps to CLOB/NCLOB/BLOB then the value will be marked as lob. if ( !value.isLob() ) { for ( RelationalValueSource relationalValueSource : attributeSource.getRelationalValueSources() ) { if ( ColumnSource.class.isInstance( relationalValueSource ) ) { if ( isLob( null, ( (ColumnSource) relationalValueSource ).getSqlType() ) ) { value.makeLob(); } } } } }
final Property prop = (Property) props.next(); if ( prop.getValue().isSimpleValue() ) { if ( isLob( ( (SimpleValue) prop.getValue() ).getTypeName() ) ) { hasLob = true; break; isLob = isLob( ( (SimpleValue) collectionBinding.getElement() ).getTypeName() );
property.setValue( value ); final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue(); value.setTypeName( referencedValue.getTypeName() ); value.setTypeParameters( referencedValue.getTypeParameters() ); final Iterator<Selectable> columns = referencedValue.getColumnIterator();
targetValue.setTypeName( sourceValue.getTypeName() ); targetValue.setTypeParameters( sourceValue.getTypeParameters() );
property.setValue( value ); final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue(); value.setTypeName( referencedValue.getTypeName() ); value.setTypeParameters( referencedValue.getTypeParameters() ); final Iterator<Column> columns = referencedValue.getColumnIterator();
public boolean isTemporalValue(Property property) { if(property.getValue() instanceof SimpleValue) { String typeName = ((SimpleValue)property.getValue()).getTypeName(); if("date".equals(typeName) || "java.sql.Date".equals(typeName)) { return true; } else if ("timestamp".equals(typeName) || "java.sql.Timestamp".equals(typeName)) { return true; } else if ("time".equals(typeName) || "java.sql.Time".equals(typeName)) { return true; } } return false; }
public boolean isTemporalValue(Property property) { if(property.getValue() instanceof SimpleValue) { String typeName = ((SimpleValue)property.getValue()).getTypeName(); if("date".equals(typeName) || "java.sql.Date".equals(typeName)) { return true; } else if ("timestamp".equals(typeName) || "java.sql.Timestamp".equals(typeName)) { return true; } else if ("time".equals(typeName) || "java.sql.Time".equals(typeName)) { return true; } } return false; }
public String generateBasicAnnotation(Property property) { StringBuffer annotations = new StringBuffer( " " ); if(property.getValue() instanceof SimpleValue) { if (hasVersionProperty()) if (property.equals(getVersionProperty())) buildVersionAnnotation(annotations); String typeName = ((SimpleValue)property.getValue()).getTypeName(); if("date".equals(typeName) || "java.sql.Date".equals(typeName)) { buildTemporalAnnotation( annotations, "DATE" ); } else if ("timestamp".equals(typeName) || "java.sql.Timestamp".equals(typeName)) { buildTemporalAnnotation( annotations, "TIMESTAMP" ); } else if ("time".equals(typeName) || "java.sql.Time".equals(typeName)) { buildTemporalAnnotation(annotations, "TIME"); } //TODO: calendar etc. ? } return annotations.toString(); }
public String generateBasicAnnotation(Property property) { StringBuffer annotations = new StringBuffer( " " ); if(property.getValue() instanceof SimpleValue) { if (hasVersionProperty()) if (property.equals(getVersionProperty())) buildVersionAnnotation(annotations); String typeName = ((SimpleValue)property.getValue()).getTypeName(); if("date".equals(typeName) || "java.sql.Date".equals(typeName)) { buildTemporalAnnotation( annotations, "DATE" ); } else if ("timestamp".equals(typeName) || "java.sql.Timestamp".equals(typeName)) { buildTemporalAnnotation( annotations, "TIMESTAMP" ); } else if ("time".equals(typeName) || "java.sql.Time".equals(typeName)) { buildTemporalAnnotation(annotations, "TIME"); } //TODO: calendar etc. ? } return annotations.toString(); }
public void copyTypeFrom( SimpleValue sourceValue ) { setExplicitTypeName( sourceValue.getTypeName() ); setTypeParameters( sourceValue.getTypeParameters() ); }
public String getTag(Property property) { PersistentClass persistentClass = property.getPersistentClass(); if(persistentClass!=null) { if(persistentClass.getVersion()==property) { String typeName = ((SimpleValue)property.getValue()).getTypeName(); if("timestamp".equals(typeName) || "dbtimestamp".equals(typeName)) { return "timestamp"; } else { return "version"; } } } String toolTag = (String) property.getValue().accept(HBMTagForValueVisitor.INSTANCE); if ("component".equals(toolTag) && "embedded".equals(property.getPropertyAccessorName())){ toolTag = "properties"; } return toolTag; }
public String getTag(Property property) { PersistentClass persistentClass = property.getPersistentClass(); if(persistentClass!=null) { if(persistentClass.getVersion()==property) { String typeName = ((SimpleValue)property.getValue()).getTypeName(); if("timestamp".equals(typeName) || "dbtimestamp".equals(typeName)) { return "timestamp"; } else { return "version"; } } } String toolTag = (String) property.getValue().accept(HBMTagForValueVisitor.INSTANCE); if ("component".equals(toolTag) && "embedded".equals(property.getPropertyAccessorName())){ toolTag = "properties"; } return toolTag; }
@Test public void testTypes() { PersistentClass classMapping = metadata.getEntityBinding("MiscTypes"); Assert.assertEquals( "SomeUserType", ((SimpleValue)classMapping.getProperty("name").getValue()).getTypeName()); Assert.assertEquals( "string", ((SimpleValue)classMapping.getProperty("shortname").getValue()).getTypeName()); Assert.assertEquals( "yes_no", ((SimpleValue)classMapping.getProperty("flag").getValue()).getTypeName()); }
String typeName = simpleValue.getTypeName(); if ("java.util.Date".equals(typeName)) { UtilDateSimpleValue udsv = new UtilDateSimpleValue(simpleValue);
protected Object handle(Value o) { Value value = (Value) o; try { // have to attempt calling gettype to decide if its custom type. Type type = value.getType(); if(type instanceof CustomType || type instanceof CompositeCustomType) { return toName( type.getReturnedClass() ); } } catch(HibernateException he) { // ignore } if ( preferRawTypeNames && value.isSimpleValue() ) { // this logic make us use the raw typename if it is something else than an Hibernate type. So, if user wrote long we will use long...if he meant to have a Long then he should use the java.lang.Long version. String typename = ( (SimpleValue) value ).getTypeName(); if ( !Cfg2JavaTool.isNonPrimitiveTypeName( typename ) ) { String val = ( (SimpleValue) value ).getTypeName(); if(val!=null) return val; // val can be null when type is any } } return toName( value.getType().getReturnedClass() ); }
protected Object handle(Value o) { Value value = (Value) o; try { // have to attempt calling gettype to decide if its custom type. Type type = value.getType(); if(type instanceof CustomType || type instanceof CompositeCustomType) { return toName( type.getReturnedClass() ); } } catch(HibernateException he) { // ignore } if ( preferRawTypeNames && value.isSimpleValue() ) { // this logic make us use the raw typename if it is something else than an Hibernate type. So, if user wrote long we will use long...if he meant to have a Long then he should use the java.lang.Long version. String typename = ( (SimpleValue) value ).getTypeName(); if ( !Cfg2JavaTool.isNonPrimitiveTypeName( typename ) ) { String val = ( (SimpleValue) value ).getTypeName(); if(val!=null) return val; // val can be null when type is any } } return toName( value.getType().getReturnedClass() ); }
@Test public void testColumnTypeMappings() { OverrideRepository or = new OverrideRepository(); or.addResource(OVERRIDETEST_REVENG_XML); ReverseEngineeringStrategy repository = or.getReverseEngineeringStrategy(null); Assert.assertNull(repository.columnToHibernateTypeName(new TableIdentifier("blah"), "bogus",0,0,0,0, false, false)); Assert.assertNull(repository.columnToHibernateTypeName(new TableIdentifier("ORDERS"), "CUSTID",0,0,0,0, false, false)); Assert.assertEquals("string", repository.columnToHibernateTypeName(new TableIdentifier(null, null, "ORDERS"), "NAME",0,0,0,0, false, false)); PersistentClass classMapping = metadata.getEntityBinding("Orders"); Property property = classMapping.getProperty("completed"); Assert.assertEquals("boolean because of not null", "boolean", ((SimpleValue)property.getValue()).getTypeName()); property = classMapping.getProperty("verified"); Assert.assertEquals("java.lang.Boolean because of null","java.lang.Boolean", ((SimpleValue)property.getValue()).getTypeName()); classMapping = metadata.getEntityBinding("MiscTypes"); property = classMapping.getIdentifierProperty(); Assert.assertFalse(((SimpleValue)property.getValue()).isNullable()); Assert.assertEquals("java.lang.Long because of primary key", "java.lang.Long", ((SimpleValue)property.getValue()).getTypeName()); }
String typename = ( (SimpleValue) value ).getTypeName(); log.warn( msg + ". Falling back to typename: " + typename ); return typename;