View Javadoc

1   package org.apache.torque.engine.platform;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.torque.engine.database.model.Domain;
23  import org.apache.torque.engine.database.model.SchemaType;
24  
25  /***
26   * Derby Platform implementation.
27   *
28   * @author <a href="mailto:johnnymac@tiscali.be">Johnny Macchione</a>
29   * @version $Id: PlatformDerbyImpl.java 473814 2006-11-11 22:30:30Z tv $
30   */
31  public class PlatformDerbyImpl extends PlatformDefaultImpl
32  {
33  
34      /***
35       * Default constructor.
36       */
37      public PlatformDerbyImpl()
38      {
39          super();
40          initialize();
41      }
42  
43      /***
44       * Initializes db specific domain mapping.
45       */
46      private void initialize()
47      {
48          setSchemaDomainMapping(new Domain(SchemaType.LONGVARCHAR, "LONG VARCHAR"));
49  
50          // PENDING: Support CHAR(n) FOR BIT DATA: n [1;254]
51          // The size is always appended to the type in the templates => CHAR FOR BIT DATA()!
52          //setSchemaDomainMapping(new Domain(SchemaType.BINARY, "CHAR(2048) FOR BIT DATA"));
53  
54          // PENDING: Support VARCHAR(n) FOR BIT DATA: n [1;32672]
55          // The size is always appended to the type in the templates => VARCHAR FOR BIT DATA()!
56          //setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "VARCHAR(2048) FOR BIT DATA"));
57  
58          // Mapped to VARBINARY, because LONG VARCHAR FOR BIT DATA doesn't require a size;
59          // turbine-schema.xml declares TURBINE_USER.OBJECT_DATA as VARBINARY without size
60          setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "LONG VARCHAR FOR BIT DATA"));
61          setSchemaDomainMapping(new Domain(SchemaType.LONGVARBINARY, "LONG VARCHAR FOR BIT DATA"));
62          setSchemaDomainMapping(new Domain(SchemaType.LONGVARCHAR, "LONG VARCHAR"));
63      }
64  
65      /***
66       * @see Platform#getMaxColumnNameLength()
67       */
68      public int getMaxColumnNameLength()
69      {
70          return 128;
71      }
72  
73      /***
74       * @see Platform#getAutoIncrement()
75       */
76      public String getAutoIncrement()
77      {
78          return "GENERATED BY DEFAULT AS IDENTITY";
79      }
80  
81      /***
82       * @see Platform#getNativeIdMethod()
83       */
84      public String getNativeIdMethod()
85      {
86          return Platform.IDENTITY;
87      }
88  
89      /***
90       * @see Platform#hasScale(String)
91       */
92      public boolean hasScale(String sqlType)
93      {
94          return "NUMERIC".equals(sqlType) || "DECIMAL".equals(sqlType);
95      }
96  
97      /***
98       * @see Platform#hasSize(String)
99       */
100     public boolean hasSize(String sqlType)
101     {
102         return "NUMERIC".equals(sqlType) || "DECIMAL".equals(sqlType)
103             || "VARCHAR".equals(sqlType) || "CHAR".equals(sqlType)
104             || "BINARY".equals(sqlType)
105             || "BLOB".equals(sqlType) || "CLOB".equals(sqlType);
106     }
107 }