View Javadoc

1   /*
2    * Copyright 2006 Outsource Cafe, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the 'License')
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an 'AS IS' BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.javagen.agile.db.model;
17  
18  import java.sql.Types;
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  public enum DbType {
23  	    
24  	BIT(Types.BIT),
25  	TINYINT(Types.TINYINT),
26  	SMALLINT(Types.SMALLINT),
27  	INTEGER(Types.INTEGER),
28  	BIGINT(Types.BIGINT),
29  	FLOAT(Types.FLOAT),
30  	REAL(Types.REAL),
31  	DOUBLE(Types.DOUBLE),
32  	NUMERIC(Types.NUMERIC),
33  	DECIMAL(Types.DECIMAL),
34  	CHAR(Types.CHAR),
35  	VARCHAR(Types.VARCHAR),
36  	LONGVARCHAR(Types.LONGVARCHAR),
37  	DATE(Types.DATE),
38  	TIME(Types.TIME),
39  	TIMESTAMP(Types.TIMESTAMP),
40  	BINARY(Types.BINARY),
41  	VARBINARY(Types.VARBINARY),
42  	LONGVARBINARY(Types.LONGVARBINARY),
43  	NULL(Types.NULL),
44  	OTHER(Types.OTHER),
45  	JAVA_OBJECT(Types.JAVA_OBJECT),
46  	DISTINCT(Types.DISTINCT),
47  	STRUCT(Types.STRUCT),
48  	ARRAY(Types.ARRAY),
49  	BLOB(Types.BLOB),
50  	CLOB(Types.CLOB),
51  	REF(Types.REF),
52  	DATALINK(Types.DATALINK),
53  	BOOLEAN(Types.BOOLEAN),
54  	;
55  	
56  	/*** enum constructor */
57  	private DbType(int jdbcType) { this.jdbcType = jdbcType; }
58  
59  	private int jdbcType;
60  	
61  	public int getJdbcType() { return this.jdbcType; }
62  	
63  	//////////////////////////////////////////////////////////////////////////////
64  	//static lookup methods
65  	//////////////////////////////////////////////////////////////////////////////
66  
67  	public static DbType lookup(String enumName) { return enumName==null ? null : DbType.valueOf(enumName.toUpperCase()); }
68  
69  	public static DbType lookup(int jdbcType) {
70  		return jdbcTypeCache.get(jdbcType); 
71  	}
72  
73  	private static Map<Integer, DbType> jdbcTypeCache = new HashMap<Integer, DbType>();
74  	
75  	static {
76  	    for (DbType dbType: DbType.values())
77  	    	jdbcTypeCache.put(dbType.getJdbcType(), dbType);
78  	}
79  }