001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: * The contents of this file are subject to the Mozilla Public License Version
004: * 1.1 (the "License"); you may not use this file except in compliance with
005: * the License. You may obtain a copy of the License at
006: * http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the
011: * License.
012: *
013: * The Original Code is Riot.
014: *
015: * The Initial Developer of the Original Code is
016: * Neteye GmbH.
017: * Portions created by the Initial Developer are Copyright (C) 2006
018: * the Initial Developer. All Rights Reserved.
019: *
020: * Contributor(s):
021: * Felix Gnass [fgnass at neteye dot de]
022: *
023: * ***** END LICENSE BLOCK ***** */
024: package org.riotfamily.revolt.dialect;
025:
026: import org.riotfamily.revolt.Script;
027: import org.riotfamily.revolt.definition.Column;
028: import org.riotfamily.revolt.definition.Index;
029: import org.riotfamily.revolt.support.TypeMap;
030:
031: /**
032: * @author Felix Gnass [fgnass at neteye dot de]
033: *
034: */
035: public class MySqlDialect extends Sql92Dialect {
036:
037: protected void registerTypes() {
038: registerType(TypeMap.BIT, "TINYINT(1)");
039: registerType(TypeMap.TINYINT, "SMALLINT");
040: registerType(TypeMap.SMALLINT, "SMALLINT");
041: registerType(TypeMap.INTEGER, "INTEGER");
042: registerType(TypeMap.BIGINT, "BIGINT");
043: registerType(TypeMap.FLOAT, "FLOAT");
044: registerType(TypeMap.REAL, "REAL");
045: registerType(TypeMap.DOUBLE, "DOUBLE");
046: registerType(TypeMap.NUMERIC, "NUMERIC");
047: registerType(TypeMap.DECIMAL, "DECIMAL");
048: registerType(TypeMap.CHAR, "CHAR", true);
049: registerType(TypeMap.VARCHAR, "VARCHAR", true);
050: registerType(TypeMap.LONGVARCHAR, "TEXT");
051: registerType(TypeMap.DATE, "DATE");
052: registerType(TypeMap.TIME, "TIME");
053: registerType(TypeMap.TIMESTAMP, "TIMESTAMP");
054: registerType(TypeMap.BINARY, "BINARY", true);
055: registerType(TypeMap.VARBINARY, "VARBINARY", true);
056: registerType(TypeMap.LONGVARBINARY, "VARBINARY");
057: registerType(TypeMap.BLOB, "BLOB");
058: registerType(TypeMap.CLOB, "TEXT");
059: }
060:
061: public boolean supports(String databaseProductName,
062: int majorVersion, int minorVersion) {
063:
064: return "MySQL".equals(databaseProductName);
065: }
066:
067: protected void addColumnDefinition(Script sql, Column column) {
068: super .addColumnDefinition(sql, column);
069: if (column.isAutoIncrement()) {
070: sql.append("AUTO_INCREMENT");
071: }
072: }
073:
074: public Script createAutoIncrementSequence(String name) {
075: return null;
076: }
077:
078: public Script renameTable(String name, String renameTo) {
079: return alterTable(name).append("RENAME TO").append(
080: quote(renameTo));
081: }
082:
083: public Script renameColumn(String table, String name,
084: String renameTo) {
085: return alterTable(table).append("CHANGE COLUMN").append(name)
086: .append(renameTo);
087: }
088:
089: public Script modifyColumn(String table, Column column) {
090: Script sql = alterTable(table).append("CHANGE COLUMN");
091: addColumnDefinition(sql, column);
092: return sql;
093: }
094:
095: public Script createIndex(String table, Index index) {
096: Script sql = alterTable(table).append("ADD INDEX").append(
097: index.getName());
098: addColumnNames(sql, index.getColumns());
099: return sql;
100: }
101:
102: public Script dropIndex(String table, String name) {
103: return alterTable(table).append("DROP INDEX").append(name);
104: }
105:
106: protected String convertBackticksToIdentifierDelimiter(String s) {
107: return s;
108: }
109: }
|