public Value getHibernateValue() { return getPropertyMapping().getValue(); }
public boolean isValid(Mapping mapping) throws MappingException { return getValue().isValid(mapping); }
private void mapPropertyToIndex(Property prop, int i) { propertyIndexes.put( prop.getName(), i ); if ( prop.getValue() instanceof Component ) { Iterator iter = ( (Component) prop.getValue() ).getPropertyIterator(); while ( iter.hasNext() ) { Property subprop = (Property) iter.next(); propertyIndexes.put( prop.getName() + '.' + subprop.getName(), i ); } } }
@SuppressWarnings("unchecked") private void createPropertiesGroupMapping(Property property) { final Component component = (Component) property.getValue(); final Iterator<Property> componentProperties = component.getPropertyIterator(); while ( componentProperties.hasNext() ) { final Property componentProperty = componentProperties.next(); propertiesGroupMapping.put( componentProperty.getName(), property.getName() ); } }
public Value getHibernateValue() { return ( (Map) getPropertyMapping().getValue() ).getIndex(); }
public Value getHibernateValue() { return ( (Collection) getPropertyMapping().getValue() ).getElement(); }
@Override public boolean[] getColumnUpdateability() { boolean[] result = new boolean[ getColumnSpan() ]; Iterator iter = getPropertyIterator(); int i=0; while ( iter.hasNext() ) { Property prop = (Property) iter.next(); boolean[] chunk = prop.getValue().getColumnUpdateability(); if ( prop.isUpdateable() ) { System.arraycopy(chunk, 0, result, i, chunk.length); } i+=chunk.length; } return result; }
protected void checkPropertyColumnDuplication(Set distinctColumns, Iterator properties) throws MappingException { while ( properties.hasNext() ) { Property prop = (Property) properties.next(); if ( prop.getValue() instanceof Component ) { //TODO: remove use of instanceof! Component component = (Component) prop.getValue(); checkPropertyColumnDuplication( distinctColumns, component.getPropertyIterator() ); } else { if ( prop.isUpdateable() || prop.isInsertable() ) { checkColumnDuplication( distinctColumns, prop.getColumnIterator() ); } } } }
public void addProperty(Property prop, XClass declaringClass) { if ( prop.getValue() instanceof Component ) { //TODO handle quote and non quote table comparison String tableName = prop.getValue().getTable().getName(); if ( getJoinsPerRealTableName().containsKey( tableName ) ) { final Join join = getJoinsPerRealTableName().get( tableName ); addPropertyToJoin( prop, declaringClass, join ); } else { addPropertyToPersistentClass( prop, declaringClass ); } } else { addPropertyToPersistentClass( prop, declaringClass ); } }
@Override public void process(InFlightMetadataCollector metadataCollector) { final PersistentClass clazz = metadataCollector.getEntityBinding( referencedClass ); if ( clazz == null ) { throw new MappingException( "property-ref to unmapped class: " + referencedClass ); } final Property prop = clazz.getReferencedProperty( propertyName ); if ( unique ) { ( (SimpleValue) prop.getValue() ).setAlternateUniqueKey( true ); } } }
private void checkComposite(Component composite) throws Exception { // check `eyeColor` final Property eyeColorProperty = composite.getProperty( "eyeColor" ); final SimpleValue eyeColorValueMapping = (SimpleValue) eyeColorProperty.getValue(); assertThat( simpleValueAttributeConverterDescriptorField.get( eyeColorValueMapping ), CoreMatchers.notNullValue() ); // check `hairColor` final Property hairColorProperty = composite.getProperty( "hairColor" ); final SimpleValue hairColorValueMapping = (SimpleValue) hairColorProperty.getValue(); assertThat( simpleValueAttributeConverterDescriptorField.get( hairColorValueMapping ), CoreMatchers.notNullValue() ); }
public void generateSecondPass(String entityName, PersistentClass persistentClass) { final Component identifierMapper = persistentClass.getIdentifierMapper(); final Property identifierProperty = persistentClass.getIdentifierProperty(); if ( identifierMapper != null ) { generateSecondPass( entityName, identifierMapper ); } else if ( identifierProperty != null && identifierProperty.isComposite() ) { final Component component = (Component) identifierProperty.getValue(); generateSecondPass( entityName, component ); } }
private Type getMapKeyType(Property prop) { Value value = prop.getValue(); assertEquals( Map.class, value.getClass() ); Map map = (Map) value; return map.getIndex().getType(); }
@Test public void testColumnDefinition() { Column idCol = ( Column ) metadata().getEntityBinding( Ball.class.getName() ) .getIdentifierProperty().getValue().getColumnIterator().next(); assertEquals( "ball_id", idCol.getName() ); }
@Override protected void afterMetadataBuilt(Metadata metadata) { Collection children = metadata.getCollectionBinding( Parent.class.getName() + ".children" ); Component childComponents = ( Component ) children.getElement(); Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next(); SQLFunction lengthFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "length" ); if ( lengthFunction != null ) { ArrayList args = new ArrayList(); args.add( "bio" ); f.setFormula( lengthFunction.render( StandardBasicTypes.INTEGER, args, null ) ); } }
@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 testSortedSetDefinitionInHbmXml() { final PersistentClass entityMapping = metadata().getEntityBinding( Search.class.getName() ); final Property sortedSetProperty = entityMapping.getProperty( "searchResults" ); final Collection sortedSetMapping = assertTyping( Collection.class, sortedSetProperty.getValue() ); assertTrue( "SortedSet mapping not interpreted as sortable", sortedSetMapping.isSorted() ); final Property sortedMapProperty = entityMapping.getProperty( "tokens" ); final Collection sortedMapMapping = assertTyping( Collection.class, sortedMapProperty.getValue() ); assertTrue( "SortedMap mapping not interpreted as sortable", sortedMapMapping.isSorted() ); }
@Test public void testComparator() { PersistentClass cm = metadata.getEntityBinding( "org.hibernate.test.legacy.Wicked" ); Property property = cm.getProperty("sortedEmployee"); Collection col = (Collection) property.getValue(); assertEquals(col.getComparatorClassName(),"org.hibernate.test.legacy.NonExistingComparator"); } }
@Test public void testJoinTableIndex(){ PersistentClass entity = metadata().getEntityBinding( Importer.class.getName() ); Property property = entity.getProperty( "cars" ); Bag set = (Bag)property.getValue(); Table collectionTable = set.getCollectionTable(); Iterator<Index> itr = collectionTable.getIndexIterator(); assertTrue( itr.hasNext() ); Index index = itr.next(); assertFalse( itr.hasNext() ); assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) ); assertEquals( 1, index.getColumnSpan() ); Iterator<Column> columnIterator = index.getColumnIterator(); Column column = columnIterator.next(); assertEquals( "importers_id", column.getName() ); assertSame( collectionTable, index.getTable() ); }