litesoft
@ 811
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.orsup.otherattributeaccessors; import org.litesoft.bo.attributes.*; import org.litesoft.core.typeutils.*; import org.litesoft.orsup.base.*; import org.litesoft.orsup.lazyload.*; import org.litesoft.orsup.nonpublic.*; public abstract class AttributeAccessorSCDtoOneVariable<Owner extends PersistentObjectImpl> extends AbstractAttributeAccessorSCDtoOne<Owner, PersistentObjectImpl> implements ToVariable { protected AttributeAccessorSCDtoOneVariable( String pName, String pColumnName, boolean pRequired, Mutability pMutability ) { super( pName, pColumnName, null, null, null, false, pRequired, _ToOneVariable.updateMutability( pMutability ) ); } @Override public final void setValueOnPO( Owner pPO, Object pValue ) { PersistentObjectImpl zNewThem = null; String zBackRefAttributeNameOnNewThem = null; if ( (pValue != null) ) { if ( !(pValue instanceof PO_VarURLstringHelper) ) { if ( !(pValue instanceof String) ) { throw new IllegalArgumentException( "Direct setting of a Variable To One relationship is Not Supported for type (" + Objects .classNameOf( pValue ) + ") w/ value: " + pValue ); } pValue = new PO_VarURLstringHelper( pValue.toString() ); } PO_VarURLstringHelper zVarURL = (PO_VarURLstringHelper) pValue; zNewThem = validateVarURL( pPO, zVarURL ); zBackRefAttributeNameOnNewThem = zVarURL.getPersistedObjectAttributeName(); } PersistentObjectImpl.BackDoor.processLazyLoadMutation( pPO, getValueHolder( pPO ), zNewThem, zBackRefAttributeNameOnNewThem ); } private PersistentObjectImpl validateVarURL( Owner pPO, PO_VarURLstringHelper pVarURL ) { PersistentObjectURL zURL = pPO.getFinder().createPersistentObjectURLfrom( pVarURL.getPersistentObjectURL() ); String problem = "po"; PersistentObject<?> them = pPO.getTransaction().findOne( zURL ); if ( them != null ) { problem += ".attribute"; AttributeAccessorSCD scd = them.getMetaDataForPO().getAccessorSCDoptional( pVarURL.getPersistedObjectAttributeName() ); if ( scd != null ) { problem += ".scdVarMany"; if ( scd instanceof AttributeAccessorSCDtoManyVariable ) { problem += ".po"; AttributeAccessorSCDtoManyVariable toMany = (AttributeAccessorSCDtoManyVariable) scd; if ( pPO.getClass().getName().equals( toMany.getToThemName() ) ) { problem += ".backref"; if ( getName().equals( toMany.getBackReference() ) ) { return (PersistentObjectImpl) them; } } } } } throw new IllegalArgumentException( "Variable To One relationship has Invalid references (" + problem + "): " + pVarURL ); } @Override public Object db_getValueOnPO( Owner pPO ) { return getValueHolder( pPO ).db_getValue(); } @Override public void db_setValueOnPO( Owner pPO, Object pValue ) { String value = null; if ( pValue != null ) { if ( !(pValue instanceof String) ) { throw new IllegalArgumentException( "Variable To One relationship is stored as a String, Not type (" + Objects.classNameOf( pValue ) + ") w/ value: " + pValue ); } PO_VarURLstringHelper varURLstring = new PO_VarURLstringHelper( pValue.toString() ); value = varURLstring.toString(); } getValueHolder( pPO ).db_setValue( value ); } @Override abstract public LazyLoadToOneVariable<Owner> getValueHolder( Owner pPO ); } |
Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/orsup/otherattributeaccessors/AttributeAccessorSCDtoOneVariable.java
Revision | Author | Commited | Message |
---|---|---|---|
811 Diff | GeorgeS | Sat 18 Aug, 2012 13:45:18 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
24 Diff | GeorgeS | Wed 24 Feb, 2010 01:51:38 +0000 | |
21 Diff | GeorgeS | Tue 23 Feb, 2010 21:11:25 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |