Subversion Repository Public Repository

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.orsup.base;

import java.sql.*;

import org.litesoft.bo.attributes.*;
import org.litesoft.commonfoundation.typeutils.*;

public abstract class AttributeAccessorSCD<Owner extends PersistentObject> extends SupplimentedSCD
{
    public static final AttributeAccessorSCD[] EMPTY_ARRAY = new AttributeAccessorSCD[0];

    public AttributeAccessorSCD( String pName, String pColumnName, boolean pRequired, AttributeMetaData pAMD )
    {
        super( pName, pColumnName, pRequired, pAMD );
    }

    public Object getDefault()
    {
        return null;
    }

    public void clrValueOnPO( Owner pPO )
    {
        setValueOnPO( pPO, null );
    }

    abstract public Object getValueOnPO( Owner pPO );

    abstract public void setValueOnPO( Owner pPO, Object pValue );

    abstract public Object db_getValueOnPO( Owner pPO );

    abstract public void db_setValueOnPO( Owner pPO, Object pValue );

    public void onSuccessfulCommit( Owner pPO, boolean pWasCommitted )
    {
    }

    public Object convertToAppropriateColumnType( Object pValue )
    {
        return convertToTargetType( pValue, getColumnType() );
    }

    private static Object convertToTargetType( Object pValue, Class<?> pTargetType )
    {
        // check first to see if we need to do a conversion
        if ( pValue == null || (pTargetType.isAssignableFrom( pValue.getClass() )) )
        {
            return pValue;
        }

        if ( pTargetType == String.class )
        {
            return pValue.toString();
        }
        if ( (pTargetType == Boolean.class) || (pTargetType == Boolean.TYPE) )
        {
            return to_Boolean( pValue );
        }
        if ( (pTargetType == Long.class) || (pTargetType == Long.TYPE) )
        {
            return to_Long( pValue );
        }
        if ( (pTargetType == Integer.class) || (pTargetType == Integer.TYPE) )
        {
            return to_Integer( pValue );
        }
        if ( (pTargetType == Short.class) || (pTargetType == Short.TYPE) )
        {
            return to_Short( pValue );
        }
        if ( (pTargetType == Double.class) || (pTargetType == Double.TYPE) )
        {
            return to_Double( pValue );
        }
        if ( (pTargetType == Float.class) || (pTargetType == Float.TYPE) )
        {
            return to_Float( pValue );
        }
        if ( pTargetType == Timestamp.class )
        {
            return to_Timestamp( pValue );
        }
        if ( pTargetType == Time.class )
        {
            return to_SqlTime( pValue );
        }
        if ( pTargetType == java.util.Date.class || pTargetType == java.sql.Date.class )
        {
            return to_UtilDate( pValue );
        }

        throw new IllegalArgumentException( "unexpected value; expected: " + pTargetType + " but got: " + Objects.classNameOf( pValue ) );
    }

    public static AttributeAccessorSCD[] append( AttributeAccessorSCD[] pOrig, AttributeAccessorSCD pNew )
    {
        if ( pNew == null )
        {
            return pOrig;
        }
        if ( Objects.isNullOrEmpty( pOrig ) )
        {
            return new AttributeAccessorSCD[]{pNew};
        }
        AttributeAccessorSCD[] newArray = new AttributeAccessorSCD[pOrig.length + 1];
        System.arraycopy( pOrig, 0, newArray, 0, pOrig.length );
        newArray[pOrig.length] = pNew;
        return newArray;
    }

    /**
     * Intended mainly for cleaning up after junit tests that might dynamically insert attributes
     */
    public static AttributeAccessorSCD[] remove( AttributeAccessorSCD[] pOrig, AttributeAccessorSCD pToRemove )
    {
        if ( (pToRemove != null) && !Objects.isNullOrEmpty( pOrig ) )
        {
            for ( int i = 0; i < pOrig.length; i++ )
            {
                if ( pToRemove.getName().equals( pOrig[i].getName() ) )
                {
                    return remove( pOrig, i );
                }
            }
        }
        return pOrig;
    }

    private static AttributeAccessorSCD[] remove( AttributeAccessorSCD[] pOrig, int pToRemove )
    {
        AttributeAccessorSCD[] newArray = new AttributeAccessorSCD[pOrig.length - 1];
        int zDst = 0;
        for ( int zSrc = 0; zSrc < pOrig.length; zSrc++ )
        {
            if ( zSrc != pToRemove )
            {
                newArray[zDst++] = pOrig[zSrc];
            }
        }
        return newArray;
    }
}

Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/orsup/base/AttributeAccessorSCD.java

Diff revisions: vs.
Revision Author Commited Message
947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

811 Diff Diff GeorgeS picture GeorgeS Sat 18 Aug, 2012 13:45:18 +0000
809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
151 Diff Diff GeorgeS picture GeorgeS Thu 17 Mar, 2011 04:16:22 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000