KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > engine > platform > PlatformDefaultImpl


1 package org.apache.torque.engine.platform;
2
3 /*
4  * Copyright 2003-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Hashtable JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.torque.engine.database.model.Domain;
24 import org.apache.torque.engine.database.model.SchemaType;
25
26
27 /**
28  * Default implementation for the Platform interface.
29  *
30  * @author <a HREF="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
31  * @version $Id: PlatformDefaultImpl.java,v 1.9 2004/02/22 06:27:19 jmcnally Exp $
32  */

33 public class PlatformDefaultImpl implements Platform
34 {
35     private Map JavaDoc schemaDomainMap;
36     
37     /**
38      * Default constructor.
39      */

40     public PlatformDefaultImpl()
41     {
42         initialize();
43     }
44     
45     private void initialize()
46     {
47         schemaDomainMap = new Hashtable JavaDoc(30);
48         Iterator JavaDoc iter = SchemaType.iterator();
49         while (iter.hasNext())
50         {
51             SchemaType type = (SchemaType) iter.next();
52             schemaDomainMap.put(type, new Domain(type));
53         }
54         schemaDomainMap.put(SchemaType.BOOLEANCHAR,
55                 new Domain(SchemaType.BOOLEANCHAR, "CHAR"));
56         schemaDomainMap.put(SchemaType.BOOLEANINT,
57                 new Domain(SchemaType.BOOLEANINT, "INTEGER"));
58     }
59
60     protected void setSchemaDomainMapping(Domain domain)
61     {
62         schemaDomainMap.put(domain.getType(), domain);
63     }
64     
65     /**
66      * @see Platform#getMaxColumnNameLength()
67      */

68     public int getMaxColumnNameLength()
69     {
70         return 64;
71     }
72
73     /**
74      * @see Platform#getNativeIdMethod()
75      */

76     public String JavaDoc getNativeIdMethod()
77     {
78         return Platform.IDENTITY;
79     }
80
81     /**
82      * @see Platform#getDomainForJdbcType(SchemaType)
83      */

84     public Domain getDomainForSchemaType(SchemaType jdbcType)
85     {
86         return (Domain) schemaDomainMap.get(jdbcType);
87     }
88
89     /**
90      * @return Only produces a SQL fragment if null values are
91      * disallowed.
92      * @see Platform#getNullString(boolean)
93      */

94     public String JavaDoc getNullString(boolean notNull)
95     {
96         // TODO: Check whether this is true for all DBs. Also verify
97
// the old Sybase templates.
98
return (notNull ? "NOT NULL" : "");
99     }
100
101     /**
102      * @see Platform#getAutoIncrement()
103      */

104     public String JavaDoc getAutoIncrement()
105     {
106         return "IDENTITY";
107     }
108
109     /**
110      * @see Platform#hasScale(String)
111      * TODO collect info for all platforms
112      */

113     public boolean hasScale(String JavaDoc sqlType)
114     {
115         return true;
116     }
117
118     /**
119      * @see Platform#hasSize(String)
120      * TODO collect info for all platforms
121      */

122     public boolean hasSize(String JavaDoc sqlType)
123     {
124         return true;
125     }
126
127 }
128
Popular Tags