litesoft
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
95
96
97
|
package org.litesoft.orsup.otherattributeaccessors;
import org.litesoft.bo.change.*;
import org.litesoft.orsup.base.*;
import org.litesoft.orsup.lazyload.*;
import org.litesoft.orsup.nonpublic.*;
import org.litesoft.util.*;
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 ) );
}
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 (" +
Utils.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 );
}
public Object db_getValueOnPO( Owner pPO )
{
return getValueHolder( pPO ).db_getValue();
}
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 (" + Utils.classNameOf( pValue ) +
") w/ value: " + pValue );
}
PO_VarURLstringHelper varURLstring = new PO_VarURLstringHelper( pValue.toString() );
value = varURLstring.toString();
}
getValueHolder( pPO ).db_setValue( value );
}
abstract public LazyLoadToOneVariable<Owner> getValueHolder( Owner pPO );
}
|
Revision |
Author |
Commited |
Message |
2
|
GeorgeS
|
Sun 07 Feb, 2010 12:50:58 +0000 |
|