blob: d013c2c5693d296baf8b6eef3fca2bb5fec522b5 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*/
package org.apache.polygene.library.sql.generator.implementation.transformation.sqlite;
import java.util.HashMap;
import java.util.Map;
import org.apache.polygene.library.sql.generator.Typeable;
import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
import org.apache.polygene.library.sql.generator.grammar.common.datatypes.BigInt;
import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInteger;
import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SmallInt;
import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
import org.apache.polygene.library.sql.generator.implementation.transformation.DefaultSQLProcessor;
import org.apache.polygene.library.sql.generator.implementation.transformation.NoOpProcessor;
import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.TableProcessing;
import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
import org.apache.polygene.library.sql.generator.implementation.transformation.sqlite.DefinitionProcessing.SQLListeTableElementListProcessor;
import org.apache.polygene.library.sql.generator.implementation.transformation.sqlite.DefinitionProcessing.SQLiteColumnDefinitionProcessor;
import org.apache.polygene.library.sql.generator.implementation.transformation.sqlite.DefinitionProcessing.SQLiteSchemaDefinitionProcessor;
import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
public class SQLiteProcessor
extends DefaultSQLProcessor
{
private static final Map<Class<? extends Typeable<?>>, SQLProcessor> _defaultProcessors;
static
{
Map<Class<? extends Typeable<?>>, SQLProcessor> processors = new HashMap<Class<? extends Typeable<?>>, SQLProcessor>(
DefaultSQLProcessor.getDefaultProcessors() );
// SQLite does not understand schema-qualified table names (or anything related to schemas)
processors.put( TableNameDirect.class, new TableProcessing.MySQLTableNameDirectProcessor() );
processors.put( TableNameFunction.class, new TableProcessing.MySQLTableNameFunctionProcessor() );
// Only process schema elements from schema definition, and ignore drop schema statements
processors.put( SchemaDefinition.class, new SQLiteSchemaDefinitionProcessor() );
processors.put( DropSchemaStatement.class, new NoOpProcessor() );
// SQLite MUST use INTEGER PRIMARY KEY AUTOINCREMENT type when autogenerated
// see http://www.sqlite.org/autoinc.html
// Override default table element list support
processors.put( TableElementList.class, new SQLListeTableElementListProcessor() );
// Override default column definition support
Map<Class<?>, String> autoGenDataTypes = new HashMap<Class<?>, String>();
autoGenDataTypes.put( BigInt.class, "INTEGER PRIMARY KEY AUTOINCREMENT" );
autoGenDataTypes.put( SQLInteger.class, "INTEGER PRIMARY KEY AUTOINCREMENT" );
autoGenDataTypes.put( SmallInt.class, "INTEGER PRIMARY KEY AUTOINCREMENT" );
processors.put( ColumnDefinition.class, new SQLiteColumnDefinitionProcessor( autoGenDataTypes ) );
_defaultProcessors = processors;
}
public SQLiteProcessor( SQLVendor vendor )
{
super( vendor, _defaultProcessors );
}
}