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 java.sql.Connection;
23 import java.sql.DatabaseMetaData;
24 import java.sql.SQLException;
25 import java.util.List;
26
27 import org.apache.torque.engine.database.model.Domain;
28 import org.apache.torque.engine.database.model.SchemaType;
29
30 /**
31 * Interface for RDBMS platform specific behaviour.
32 *
33 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
34 * @version $Id: Platform.java,v 1.1.6.2 2008-04-18 17:04:37 jkeller Exp $
35 */
36 public interface Platform {
37 /** constant for native id method */
38 String IDENTITY = "identity";
39 /** constant for native id method */
40 String SEQUENCE = "sequence";
41
42 /**
43 * Given a JDBC url return a url that can connect directly to the database server itself. ie no database specified
44 */
45 String getServerUrl(String url);
46
47 /**
48 * Given an artifact id, return a string a schema name based on the artifact id that is allowed by the db vendor
49 */
50 String getSchemaName(String artifactId);
51
52 /**
53 * Returns the native IdMethod (sequence|identity)
54 *
55 * @return the native IdMethod
56 */
57 String getNativeIdMethod();
58
59 /**
60 * Returns the max column length supported by the db.
61 *
62 * @return the max column length
63 */
64 int getMaxColumnNameLength();
65
66 /**
67 * Returns the db specific domain for a jdbcType.
68 *
69 * @param jdbcType
70 * the jdbcType name
71 * @return the db specific domain
72 */
73 Domain getDomainForSchemaType(SchemaType jdbcType);
74
75 /**
76 * @return The RDBMS-specific SQL fragment for <code>NULL</code> or <code>NOT NULL</code>.
77 */
78 String getNullString(boolean notNull);
79
80 /**
81 * @return The RDBMS-specific SQL fragment for autoincrement.
82 */
83 String getAutoIncrement();
84
85 /**
86 * Returns if the RDBMS-specific SQL type has a size attribute.
87 *
88 * @param sqlType
89 * the SQL type
90 * @return true if the type has a size attribute
91 */
92 boolean hasSize(String sqlType);
93
94 /**
95 * Returns if the RDBMS-specific SQL type has a scale attribute.
96 *
97 * @param sqlType
98 * the SQL type
99 * @return true if the type has a scale attribute
100 */
101 boolean hasScale(String sqlType);
102
103 /**
104 * Returns whether the "not null part" of the definition of a column should be generated before the
105 * "autoincrement part" in a "create table" statement.
106 *
107 * @return true if the "not null part" should be first, false if the "autoincrement part" should be first in a
108 * "create table" statement.
109 */
110 boolean createNotNullBeforeAutoincrement();
111
112 String filterInvalidDefaultValues(String defaultValue);
113
114 public boolean isSpecialDefault(String defaultValue);
115
116 String getViewDefinition(Connection con, String schema, String viewName);
117
118 Long getSequenceNextVal(Connection con, String schema, String sequenceName);
119
120 public List<String> getPrimaryKeys(DatabaseMetaData dbMeta, String dbSchema, String tableName) throws SQLException;
121
122 public List<String> getTableNames(DatabaseMetaData dbMeta, String databaseSchema) throws SQLException;
123
124 /**
125 * Get the list of sequences defined in the database schema given.
126 *
127 * @param dbMetaData
128 * @param databaseSchema
129 * @return A list of sequences that exist in the database.
130 * @throws SQLException
131 */
132 public List<String> getSequenceNames(DatabaseMetaData dbMetaData, String databaseSchema) throws SQLException;
133 }