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 java.util.Date;
23
24 import org.apache.torque.templates.typemapping.SchemaType;
25 import org.apache.torque.templates.typemapping.SqlType;
26
27 /**
28 * Interface for RDBMS platform specific behaviour.
29 *
30 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
31 * @version $Id: Platform.java 1363653 2012-07-20 04:31:30Z tfischer $
32 */
33 public interface Platform
34 {
35 /**
36 * Returns the db specific SQL type for a Torque type.
37 *
38 * @param schemaType the Torque type, not null.
39 *
40 * @return the db specific SQL type, or null if no SQL type is defined
41 * for the given Torque type.
42 */
43 SqlType getSqlTypeForSchemaType(SchemaType schemaType);
44
45 /**
46 * @return The RDBMS-specific SQL fragment for <code>NULL</code>
47 * or <code>NOT NULL</code>.
48 */
49 String getNullString(boolean notNull);
50
51 /**
52 * @return The RDBMS-specific SQL fragment for autoincrement.
53 */
54 String getAutoIncrement();
55
56 /**
57 * Returns if the RDBMS-specific SQL type has a size attribute.
58 *
59 * @param sqlType the SQL type
60 * @return true if the type has a size attribute
61 */
62 boolean hasSize(String sqlType);
63
64 /**
65 * Returns if the RDBMS-specific SQL type has a scale attribute.
66 *
67 * @param sqlType the SQL type
68 * @return true if the type has a scale attribute
69 */
70 boolean hasScale(String sqlType);
71
72 /**
73 * Returns a possible SQL suffix for column definitions of certain
74 * SQL Types, e.g. for Oracle VARCHAR2 columns, it typically
75 * makes sense to use 'XXX CHAR' instead of 'XXX' as size.
76 *
77 * @param sqlType the SQL type to determine the suffix for.
78 *
79 * @return the size suffix, not null, may be empty.
80 */
81 String getSizeSuffix(String sqlType);
82
83 /**
84 * Returns whether the "not null part" of the definition of a column
85 * should be generated before the "autoincrement part" in a "create table"
86 * statement.
87 *
88 * @return true if the "not null part" should be first,
89 * false if the "autoincrement part" should be first in a
90 * "create table" statement.
91 */
92 boolean createNotNullBeforeAutoincrement();
93
94 /**
95 * Quotes and escapes a string such that it can be used
96 * as literal String value in SQL.
97 *
98 * @param value The string to escape, or null.
99 *
100 * @return the escaped String, not null.
101 */
102 String quoteAndEscape(String value);
103
104 /**
105 * Formats the given date as date string which is parseable by the database.
106 *
107 * @param date the date to format.
108 *
109 * @return the date string, inclusive string escaping.
110 */
111 String getDateString(Date date);
112
113 /**
114 * Formats the given date as time string which is parseable by the database.
115 *
116 * @param date the date to format.
117 *
118 * @return the time string, inclusive string escaping.
119 */
120 String getTimeString(Date date);
121
122 /**
123 * Formats the given date as timestamp string which is parseable
124 * by the database.
125 *
126 * @param date the date to format.
127 *
128 * @return the timestamp string, inclusive string escaping.
129 */
130 String getTimestampString(Date date);
131 }