private Property getConstrainedOneToOne(RootClass rc) { Iterator<?> propertyClosureIterator = rc.getPropertyClosureIterator(); while (propertyClosureIterator.hasNext()) { Property property = (Property) propertyClosureIterator.next(); if(property.getValue() instanceof OneToOne) { OneToOne oto = (OneToOne) property.getValue(); if(oto.isConstrained()) { return property; } } } return null; }
private Property getConstrainedOneToOne(RootClass rc) { Iterator<?> propertyClosureIterator = rc.getPropertyClosureIterator(); while (propertyClosureIterator.hasNext()) { Property property = (Property) propertyClosureIterator.next(); if(property.getValue() instanceof OneToOne) { OneToOne oto = (OneToOne) property.getValue(); if(oto.isConstrained()) { return property; } } } return null; }
lazy = ( (OneToOne) model ).isConstrained(); fetchStyle = lazy ? FetchMode.DEFAULT : FetchMode.JOIN;
lazy = ( (OneToOne) model ).isConstrained(); fetchStyle = lazy ? FetchMode.DEFAULT : FetchMode.JOIN;
lazy = ( (OneToOne) model ).isConstrained(); fetchStyle = lazy ? FetchMode.DEFAULT : FetchMode.JOIN;
lazy = ( (OneToOne) model ).isConstrained(); fetchStyle = lazy ? FetchMode.DEFAULT : FetchMode.JOIN;
value.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT
public static void bindOneToOne(Element node, OneToOne oneToOne, String path, boolean isNullable, Mappings mappings) throws MappingException { bindColumns( node, oneToOne, isNullable, false, null, mappings ); Attribute constrNode = node.attribute( "constrained" ); boolean constrained = constrNode != null && constrNode.getValue().equals( "true" ); oneToOne.setConstrained( constrained ); oneToOne.setForeignKeyType( constrained ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ); initOuterJoinFetchSetting( node, oneToOne ); initLaziness( node, oneToOne, mappings, true ); oneToOne.setEmbedded( "true".equals( node.attributeValue( "embed-xml" ) ) ); Attribute fkNode = node.attribute( "foreign-key" ); if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() ); Attribute ukName = node.attribute( "property-ref" ); if ( ukName != null ) oneToOne.setReferencedPropertyName( ukName.getValue() ); oneToOne.setPropertyName( node.attributeValue( "name" ) ); oneToOne.setReferencedEntityName( getEntityName( node, mappings ) ); String cascade = node.attributeValue( "cascade" ); if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) { if ( oneToOne.isConstrained() ) { throw new MappingException( "one-to-one attribute [" + path + "] does not support orphan delete as it is constrained" ); } } }
public static void bindOneToOne(Element node, OneToOne oneToOne, String path, boolean isNullable, Mappings mappings) throws MappingException { bindColumns( node, oneToOne, isNullable, false, null, mappings ); Attribute constrNode = node.attribute( "constrained" ); boolean constrained = constrNode != null && constrNode.getValue().equals( "true" ); oneToOne.setConstrained( constrained ); oneToOne.setForeignKeyType( constrained ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ); initOuterJoinFetchSetting( node, oneToOne ); initLaziness( node, oneToOne, mappings, true ); oneToOne.setEmbedded( "true".equals( node.attributeValue( "embed-xml" ) ) ); Attribute fkNode = node.attribute( "foreign-key" ); if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() ); Attribute ukName = node.attribute( "property-ref" ); if ( ukName != null ) oneToOne.setReferencedPropertyName( ukName.getValue() ); oneToOne.setPropertyName( node.attributeValue( "name" ) ); oneToOne.setReferencedEntityName( getEntityName( node, mappings ) ); String cascade = node.attributeValue( "cascade" ); if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) { if ( oneToOne.isConstrained() ) { throw new MappingException( "one-to-one attribute [" + path + "] does not support orphan delete as it is constrained" ); } } }
@Test public void testOneToOneSingleColumnBiDirectional() { PersistentClass person = metadata.getEntityBinding("Person"); Property addressProperty = person.getProperty("addressPerson"); Assert.assertNotNull(addressProperty); Assert.assertTrue(addressProperty.getValue() instanceof OneToOne); OneToOne oto = (OneToOne) addressProperty.getValue(); Assert.assertEquals(oto.getColumnSpan(),1); Assert.assertEquals("Person", oto.getEntityName()); Assert.assertEquals("AddressPerson", oto.getReferencedEntityName()); Assert.assertEquals(2, person.getPropertyClosureSpan()); Assert.assertEquals("personId", person.getIdentifierProperty().getName()); Assert.assertFalse(oto.isConstrained()); PersistentClass addressPerson = metadata.getEntityBinding("AddressPerson"); Property personProperty = addressPerson.getProperty("person"); Assert.assertNotNull(personProperty); Assert.assertTrue(personProperty.getValue() instanceof OneToOne); oto = (OneToOne) personProperty.getValue(); Assert.assertTrue(oto.isConstrained()); Assert.assertEquals(oto.getColumnSpan(),1); Assert.assertEquals("AddressPerson", oto.getEntityName()); Assert.assertEquals("Person", oto.getReferencedEntityName()); Assert.assertEquals(2, addressPerson.getPropertyClosureSpan()); Assert.assertEquals("addressId", addressPerson.getIdentifierProperty().getName()); }
@Test public void testOneToOneMultiColumnBiDirectional() { PersistentClass person = metadata.getEntityBinding("MultiPerson"); Property addressProperty = person.getProperty("addressMultiPerson"); Assert.assertNotNull(addressProperty); Assert.assertTrue(addressProperty.getValue() instanceof OneToOne); OneToOne oto = (OneToOne) addressProperty.getValue(); Assert.assertEquals(oto.getColumnSpan(),2); Assert.assertEquals("MultiPerson", oto.getEntityName()); Assert.assertEquals("AddressMultiPerson", oto.getReferencedEntityName()); Assert.assertFalse(oto.isConstrained()); Assert.assertEquals(2, person.getPropertyClosureSpan()); Assert.assertEquals("compositeid gives generic id name", "id", person.getIdentifierProperty().getName()); PersistentClass addressPerson = metadata.getEntityBinding("AddressMultiPerson"); Property personProperty = addressPerson.getProperty("multiPerson"); Assert.assertNotNull(personProperty); Assert.assertTrue(personProperty.getValue() instanceof OneToOne); oto = (OneToOne) personProperty.getValue(); Assert.assertEquals(oto.getColumnSpan(),2); Assert.assertEquals("AddressMultiPerson", oto.getEntityName()); Assert.assertEquals("MultiPerson", oto.getReferencedEntityName()); Assert.assertEquals(2, addressPerson.getPropertyClosureSpan()); Assert.assertEquals("compositeid gives generic id name","id", addressPerson.getIdentifierProperty().getName()); Assert.assertTrue(oto.isConstrained()); }
private static void bindOneToOne(final GrailsDomainClassProperty property, OneToOne oneToOne, String path, String sessionFactoryBeanName) { PropertyConfig config = getPropertyConfig(property); final GrailsDomainClassProperty otherSide = property.getOtherSide(); oneToOne.setConstrained(otherSide.isHasOne()); oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT); oneToOne.setAlternateUniqueKey(true); if (config != null && config.getFetch() != null) { oneToOne.setFetchMode(config.getFetch()); } else { oneToOne.setFetchMode(FetchMode.DEFAULT); } oneToOne.setReferencedEntityName(otherSide.getDomainClass().getFullName()); oneToOne.setPropertyName(property.getName()); if (otherSide.isHasOne()) { PropertyConfig pc = getPropertyConfig(property); bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName); } else { oneToOne.setReferencedPropertyName(otherSide.getName()); } }
protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne, String path, String sessionFactoryBeanName) { PropertyConfig config = getPropertyConfig(property); final Association otherSide = property.getInverseSide(); final boolean hasOne = isHasOne(otherSide); oneToOne.setConstrained(hasOne); oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT); oneToOne.setAlternateUniqueKey(true); if (config != null && config.getFetchMode() != null) { oneToOne.setFetchMode(config.getFetchMode()); } else { oneToOne.setFetchMode(FetchMode.DEFAULT); } oneToOne.setReferencedEntityName(otherSide.getOwner().getName()); oneToOne.setPropertyName(property.getName()); bindOneToOneInternal(property, oneToOne, path); if (hasOne) { PropertyConfig pc = getPropertyConfig(property); bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName); } else { oneToOne.setReferencedPropertyName(otherSide.getName()); } }
isLogicalOneToOne = false; persistentAttributeType = PersistentAttributeType.ONE_TO_ONE; constrained = ( (OneToOne) valueMapping ).isConstrained(); notFoundAction = NotFoundAction.EXCEPTION;
value.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT
value.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT
value.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT