📄 platforminfo.java
字号:
package org.apache.ddlutils;
/*
* 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.
*/
import java.lang.reflect.Field;
import java.sql.Types;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Conatains information about the database platform such as supported features and native type mappings.
*
* @version $Revision: 289996 $
*/
public class PlatformInfo
{
/** The Log to which logging calls will be made. */
private final Log _log = LogFactory.getLog(PlatformInfo.class);
// properties influencing the definition of columns
/** Whether the database requires the explicit stating of NULL as the default value. */
private boolean _nullAsDefaultValueRequired = false;
/** Whether default values can be defined for LONGVARCHAR/LONGVARBINARY columns. */
private boolean _defaultValuesForLongTypesSupported = true;
// properties influencing the specification of table constraints
/** Whether primary key constraints are embedded inside the create table statement. */
private boolean _primaryKeyEmbedded = true;
/** Whether foreign key constraints are embedded inside the create table statement. */
private boolean _foreignKeysEmbedded = false;
/** Whether embedded foreign key constraints are explicitly named. */
private boolean _embeddedForeignKeysNamed = false;
/** Whether non-unique indices are supported. */
private boolean _indicesSupported = true;
/** Whether indices are embedded inside the create table statement. */
private boolean _indicesEmbedded = false;
/** Whether identity specification is supported for non-primary key columns. */
private boolean _nonPKIdentityColumnsSupported = true;
/** Whether the auto-increment definition is done via the DEFAULT part of the column definition. */
private boolean _defaultValueUsedForIdentitySpec = false;
// properties influencing the reading of models from live databases
/** Whether system indices (database-generated indices for primary and foreign keys) are returned when
reading a model from a database. */
private boolean _systemIndicesReturned = true;
/** Whether system indices for foreign keys are always non-unique or can be
unique (i.e. if a primary key column is used to establish the foreign key). */
private boolean _systemForeignKeyIndicesAlwaysNonUnique = false;
/** Whether the database returns a synthetic default value for non-identity required columns. */
private boolean _syntheticDefaultValueForRequiredReturned = false;
/** Whether the platform is able to determine auto increment status from an existing database. */
private boolean _identityStatusReadingSupported = true;
// other DDL/DML properties
/** Whether comments are supported. */
private boolean _sqlCommentsSupported = true;
/** Whether delimited identifiers are supported or not. */
private boolean _delimitedIdentifiersSupported = true;
/** Whether an ALTER TABLE is needed to drop indexes. */
private boolean _alterTableForDropUsed = false;
/** Whether the platform allows for the explicit specification of values for identity columns in INSERT
and UPDATE statements. */
private boolean _identityOverrideAllowed = true;
/** Whether the values of identity columns can be read back from the database after insertion. */
private boolean _lastIdentityValueReadable = true;
/** Whether auto-commit mode for the reading of the values of identity columns after insertion
shall be used. */
private boolean _autoCommitModeForLastIdentityValueReading = true;
/** Specifies the maximum length that a table name can have for this database (-1 if there is no limit). */
private int _maxTableNameLength = -1;
/** Specifies the maximum length that a column name can have for this database (-1 if there is no limit). */
private int _maxColumnNameLength = -1;
/** Specifies the maximum length that a constraint name can have for this database (-1 if there is no limit). */
private int _maxConstraintNameLength = -1;
/** Specifies the maximum length that a foreign key name can have for this database (-1 if there is no limit). */
private int _maxForeignKeyNameLength = -1;
/** The string used for delimiting SQL identifiers, eg. table names, column names etc. */
private String _delimiterToken = "\"";
/** The string used for escaping values when generating textual SQL statements. */
private String _valueQuoteToken = "'";
/** The string that starts a comment. */
private String _commentPrefix = "--";
/** The string that ends a comment. */
private String _commentSuffix = "";
/** The text separating individual sql commands. */
private String _sqlCommandDelimiter = ";";
/** Contains non-default mappings from jdbc to native types. */
private HashMap _nativeTypes = new HashMap();
/** Contains the jdbc types corresponding to the native types for non-default mappings. */
private HashMap _targetJdbcTypes = new HashMap();
/** Contains those JDBC types whose corresponding native types have a null value as the default value. */
private HashSet _typesWithNullDefault = new HashSet();
/** Contains those JDBC types whose corresponding native types are types that have a size on this platform. */
private HashSet _typesWithSize = new HashSet();
/** Contains the default sizes for those JDBC types whose corresponding native types require a size. */
private HashMap _typesDefaultSizes = new HashMap();
/** Contains those JDBC types whose corresponding native types are types that have precision and scale on this platform. */
private HashSet _typesWithPrecisionAndScale = new HashSet();
/**
* Creates a new platform info object.
*/
public PlatformInfo()
{
_typesWithNullDefault.add(new Integer(Types.CHAR));
_typesWithNullDefault.add(new Integer(Types.VARCHAR));
_typesWithNullDefault.add(new Integer(Types.LONGVARCHAR));
_typesWithNullDefault.add(new Integer(Types.CLOB));
_typesWithNullDefault.add(new Integer(Types.BINARY));
_typesWithNullDefault.add(new Integer(Types.VARBINARY));
_typesWithNullDefault.add(new Integer(Types.LONGVARBINARY));
_typesWithNullDefault.add(new Integer(Types.BLOB));
_typesWithSize.add(new Integer(Types.CHAR));
_typesWithSize.add(new Integer(Types.VARCHAR));
_typesWithSize.add(new Integer(Types.BINARY));
_typesWithSize.add(new Integer(Types.VARBINARY));
_typesWithPrecisionAndScale.add(new Integer(Types.DECIMAL));
_typesWithPrecisionAndScale.add(new Integer(Types.NUMERIC));
}
// properties influencing the definition of columns
/**
* Determines whether a NULL needs to be explicitly stated when the column
* has no specified default value. Default is false.
*
* @return <code>true</code> if NULL must be written for empty default values
*/
public boolean isNullAsDefaultValueRequired()
{
return _nullAsDefaultValueRequired;
}
/**
* Specifies whether a NULL needs to be explicitly stated when the column
* has no specified default value. Default is false.
*
* @param requiresNullAsDefaultValue Whether NULL must be written for empty
* default values
*/
public void setNullAsDefaultValueRequired(boolean requiresNullAsDefaultValue)
{
_nullAsDefaultValueRequired = requiresNullAsDefaultValue;
}
/**
* Determines whether default values can be specified for LONGVARCHAR/LONGVARBINARY columns.
*
* @return <code>true</code> if default values are allowed
*/
public boolean isDefaultValuesForLongTypesSupported()
{
return _defaultValuesForLongTypesSupported;
}
/**
* Specifies whether default values can be specified for LONGVARCHAR/LONGVARBINARY columns.
*
* @param isSupported <code>true</code> if default values are supported
*/
public void setDefaultValuesForLongTypesSupported(boolean isSupported)
{
_defaultValuesForLongTypesSupported = isSupported;
}
// properties influencing the specification of table constraints
/**
* Determines whether primary key constraints are embedded in the create
* table clause or as seperate alter table statements. The default is
* embedded pks.
*
* @return <code>true</code> if pk constraints are embedded
*/
public boolean isPrimaryKeyEmbedded()
{
return _primaryKeyEmbedded;
}
/**
* Specifies whether the primary key constraints are embedded in the create
* table clause or as seperate alter table statements.
*
* @param primaryKeyEmbedded Whether pk constraints are embedded
*/
public void setPrimaryKeyEmbedded(boolean primaryKeyEmbedded)
{
_primaryKeyEmbedded = primaryKeyEmbedded;
}
/**
* Determines whether foreign key constraints are embedded in the create
* table clause or as seperate alter table statements. Per default,
* foreign keys are external.
*
* @return <code>true</code> if fk constraints are embedded
*/
public boolean isForeignKeysEmbedded()
{
return _foreignKeysEmbedded;
}
/**
* Specifies whether foreign key constraints are embedded in the create
* table clause or as seperate alter table statements.
*
* @param foreignKeysEmbedded Whether fk constraints are embedded
*/
public void setForeignKeysEmbedded(boolean foreignKeysEmbedded)
{
_foreignKeysEmbedded = foreignKeysEmbedded;
}
/**
* Returns whether embedded foreign key constraints should have a name.
*
* @return <code>true</code> if embedded fks have name
*/
public boolean isEmbeddedForeignKeysNamed()
{
return _embeddedForeignKeysNamed;
}
/**
* Specifies whether embedded foreign key constraints should be named.
*
* @param embeddedForeignKeysNamed Whether embedded fks shall have a name
*/
public void setEmbeddedForeignKeysNamed(boolean embeddedForeignKeysNamed)
{
_embeddedForeignKeysNamed = embeddedForeignKeysNamed;
}
/**
* Determines whether indices are supported.
*
* @return <code>true</code> if indices are supported
*/
public boolean isIndicesSupported()
{
return _indicesSupported;
}
/**
* Specifies whether indices are supported.
*
* @param supportingIndices <code>true</code> if indices are supported
*/
public void setIndicesSupported(boolean supportingIndices)
{
_indicesSupported = supportingIndices;
}
/**
* Determines whether the indices are embedded in the create table clause
* or as seperate statements. Per default, indices are external.
*
* @return <code>true</code> if indices are embedded
*/
public boolean isIndicesEmbedded()
{
return _indicesEmbedded;
}
/**
* Specifies whether indices are embedded in the create table clause or
* as seperate alter table statements.
*
* @param indicesEmbedded Whether indices are embedded
*/
public void setIndicesEmbedded(boolean indicesEmbedded)
{
_indicesEmbedded = indicesEmbedded;
}
/**
* Determines whether non-primary key columns can be auto-incrementing (IDENTITY columns).
*
* @return <code>true</code> if normal non-PK columns can be auto-incrementing
*/
public boolean isNonPKIdentityColumnsSupported()
{
return _nonPKIdentityColumnsSupported;
}
/**
* Specifies whether non-primary key columns can be auto-incrementing (IDENTITY columns).
*
* @param supportingNonPKIdentityColumns <code>true</code> if normal non-PK columns can
* be auto-incrementing
*/
public void setNonPKIdentityColumnsSupported(boolean supportingNonPKIdentityColumns)
{
_nonPKIdentityColumnsSupported = supportingNonPKIdentityColumns;
}
/**
* Determines whether the auto-increment specification uses the DEFAULT value of the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -