~starbuggers/sakila-server/mysql-5.1-wl820

« back to all changes in this revision

Viewing changes to plugin/java_udf/com/mysql/udf/InternalType.java

  • Committer: Antony T Curtis
  • Date: 2008-04-10 06:09:05 UTC
  • mto: (2542.76.4 mysql-5.1-wl820)
  • mto: This revision was merged to the branch mainline in revision 2772.
  • Revision ID: antony@anubis.xiphis.org-20080410060905-itpom5iyz8ae4dhh
Initial import into Bazaar repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.mysql.udf;
 
2
 
 
3
public abstract class InternalType {
 
4
 
 
5
    public final static InternalType UNKNOWN = new InternalType(-1) {
 
6
        public Object getArgument(int argIndex, UDFCallback callback) {
 
7
            // I'm thinking that this should throw.
 
8
            return null;
 
9
        }
 
10
    };
 
11
 
 
12
    public final static InternalType STRING_TYPE = new InternalType(0) {
 
13
        public Object getArgument(int argIndex, UDFCallback callback) {
 
14
            return callback.getStringArgument(argIndex);
 
15
        }
 
16
    };
 
17
 
 
18
    public final static InternalType REAL_TYPE = new InternalType(1) {
 
19
        public Object getArgument(int argIndex, UDFCallback callback) {
 
20
            return new Double(callback.getDoubleArgument(argIndex));
 
21
        }
 
22
    };
 
23
 
 
24
    public final static InternalType INTEGER_TYPE = new InternalType(2) {
 
25
        public Object getArgument(int argIndex, UDFCallback callback) {
 
26
            return new Long(callback.getLongArgument(argIndex));
 
27
        }
 
28
    };
 
29
 
 
30
    public final static InternalType DECIMAL_TYPE = new InternalType(3) {
 
31
        public Object getArgument(int argIndex, UDFCallback callback) {
 
32
            return callback.getBigDecimalArgument(argIndex);
 
33
        }
 
34
    };
 
35
 
 
36
    public final int typeCode;
 
37
 
 
38
    private InternalType(int typeCode) {
 
39
        this.typeCode = typeCode;
 
40
    }
 
41
 
 
42
    public abstract Object getArgument(int argIndex, UDFCallback callback);
 
43
 
 
44
    public static InternalType get(int typeCode) throws UDFException {
 
45
        if (typeCode == UNKNOWN.typeCode)
 
46
            return UNKNOWN;
 
47
        if (typeCode == STRING_TYPE.typeCode)
 
48
            return STRING_TYPE;
 
49
        if (typeCode == REAL_TYPE.typeCode)
 
50
            return REAL_TYPE;
 
51
        if (typeCode == INTEGER_TYPE.typeCode)
 
52
            return INTEGER_TYPE;
 
53
        if (typeCode == DECIMAL_TYPE.typeCode)
 
54
            return DECIMAL_TYPE;
 
55
        throw new UDFException("Bad or illegal typeCode");
 
56
    }
 
57
}