View Javadoc

1   package org.apache.torque.templates.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.templates.typemapping.SchemaType;
23  import org.apache.torque.templates.typemapping.SqlType;
24  
25  /**
26   * Postgresql Platform implementation.
27   *
28   * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
29   * @version $Id: PlatformPostgresqlImpl.java 1331196 2012-04-27 02:56:12Z tfischer $
30   */
31  public class PlatformPostgresqlImpl extends PlatformDefaultImpl
32  {
33      /**
34       * Default constructor.
35       */
36      public PlatformPostgresqlImpl()
37      {
38          super();
39          initialize();
40      }
41  
42      /**
43       * Initializes db specific domain mapping.
44       */
45      private void initialize()
46      {
47          setSchemaTypeToSqlTypeMapping(
48                  SchemaType.BIT,
49                  new SqlType("BOOLEAN"));
50          setSchemaTypeToSqlTypeMapping(
51                  SchemaType.TINYINT,
52                  new SqlType("INT2"));
53          setSchemaTypeToSqlTypeMapping(
54                  SchemaType.SMALLINT,
55                  new SqlType("INT2"));
56          setSchemaTypeToSqlTypeMapping(
57                  SchemaType.BIGINT,
58                  new SqlType("INT8"));
59          setSchemaTypeToSqlTypeMapping(
60                  SchemaType.REAL,
61                  new SqlType("FLOAT"));
62          setSchemaTypeToSqlTypeMapping(
63                  SchemaType.BOOLEANCHAR,
64                  new SqlType("CHAR"));
65          setSchemaTypeToSqlTypeMapping(
66                  SchemaType.BOOLEANINT,
67                  new SqlType("INT2"));
68          setSchemaTypeToSqlTypeMapping(
69                  SchemaType.DOUBLE,
70                  new SqlType("DOUBLE PRECISION"));
71          setSchemaTypeToSqlTypeMapping(
72                  SchemaType.LONGVARCHAR,
73                  new SqlType("TEXT"));
74          setSchemaTypeToSqlTypeMapping(
75                  SchemaType.BINARY,
76                  new SqlType("BYTEA"));
77          setSchemaTypeToSqlTypeMapping(
78                  SchemaType.VARBINARY,
79                  new SqlType("BYTEA"));
80          setSchemaTypeToSqlTypeMapping(
81                  SchemaType.LONGVARBINARY,
82                  new SqlType("BYTEA"));
83          setSchemaTypeToSqlTypeMapping(
84                  SchemaType.BLOB,
85                  new SqlType("BYTEA"));
86          setSchemaTypeToSqlTypeMapping(
87                  SchemaType.CLOB,
88                  new SqlType("TEXT"));
89      }
90  
91      /**
92       * @see Platform#getAutoIncrement()
93       */
94      public String getAutoIncrement()
95      {
96          return "";
97      }
98  
99      /**
100      * @see Platform#hasScale(String)
101      * TODO collect info for all platforms
102      */
103     public boolean hasScale(String sqlType)
104     {
105         if ("INT2".equalsIgnoreCase(sqlType)
106                 || "TEXT".equalsIgnoreCase(sqlType))
107         {
108             return false;
109         }
110         return true;
111     }
112 
113     /**
114      * @see Platform#hasSize(String)
115      * TODO collect info for all platforms
116      */
117     public boolean hasSize(String sqlType)
118     {
119         if ("INT2".equalsIgnoreCase(sqlType)
120                 || "TEXT".equalsIgnoreCase(sqlType))
121         {
122             return false;
123         }
124         return true;
125     }
126 
127     protected boolean escapeBackslashes()
128     {
129         return true;
130     }
131 }