org.melati.poem.dbms
Class SQLServer

Package class diagram package SQLServer
java.lang.Object
  extended by org.melati.poem.dbms.AnsiStandard
      extended by org.melati.poem.dbms.SQLServer
All Implemented Interfaces:
Dbms

public class SQLServer
extends AnsiStandard

A Driver for the Microsoft SQL server.


Nested Class Summary
static class SQLServer.SQLServerBooleanPoemType
          Translates an SQLServer Boolean into a Poem BooleanPoemType.
 
Field Summary
static int sqlServerMaxBinarySize
          Maximum size of a binary field.
static int sqlServerTextHack
          SQL Server does not have a pleasant TEXT datatype, so we use an arbetary value in a VARCHAR.
 
Fields inherited from class org.melati.poem.dbms.AnsiStandard
schema
 
Constructor Summary
SQLServer()
          Constructor.
 
Method Summary
 String alterColumnNotNullableSQL(String tableName, Column column)
          Accommodate SQLServer syntax.
 String booleanTrueExpression(Column booleanColumn)
          Accomodate lack of boolean types.
 boolean canBeIndexed(Column column)
          MSSQL cannot index TEXT fields.
 PoemType canRepresent(PoemType storage, PoemType type)
          Accomodate our String size hack.
 String caseInsensitiveRegExpSQL(String term1, String term2)
          This is the Postgresql syntax.
 SQLPoemType defaultPoemTypeOfColumnMetaData(ResultSet md)
          The simplest POEM type corresponding to a JDBC description from the database.
 String getBinarySqlDefinition(int size)
          Accomodate different treatment of different sized binary data.
 String getForeignKeyDefinition(String tableName, String fieldName, String targetTableName, String targetTableFieldName, String fixName)
          Slightly different - embrace and extend.
 String getLongSqlDefinition()
          Accomodate Long / Bigint deviants.
 String getQuotedValue(SQLType sqlType, String value)
          Accomodate different quoting strategies for values.
 String getSchema()
          Get the user we are connected as and return that as the schema.
 String getSqlDefaultValue(SQLType sqlType)
          Used to set a not null value when creating a non nullable column.
 String getSqlDefinition(String sqlTypeName)
          Retrieve a SQL type keyword used by the DBMS for the given Melati type name.
 String getStringSqlDefinition(int size)
          Accomodate String / Text distinction.
 String melatiName(String name)
          Ignore dtproperties as it is a 'System' table used to store Entity Relationship diagrams which have a jdbc type of TABLE when it should probably have a jdbc type of 'SYSTEM TABLE'.
 String selectLimit(String querySelection, int limit)
          Accomodate different limiting syntax.
 String sqlBooleanValueOfRaw(Object raw)
          Accomodate different true and false values.
 
Methods inherited from class org.melati.poem.dbms.AnsiStandard
canDropColumns, canStoreBlobs, createTableOptionsSql, createTableSql, createTableTypeQualifierSql, exceptionForUpdate, exceptionForUpdate, getConnection, getDriverClassName, getDriverLoaded, getFixedPtSqlDefinition, getIndexLength, getJdbcMetadataName, getPrimaryKeyDefinition, getQuotedName, givesCapabilitySQL, loadDriver, preparedStatementPlaceholder, setDriverClassName, setDriverLoaded, shutdown, tableInitialisationSql, toString, unloadDriver, unreservedName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sqlServerTextHack

public static final int sqlServerTextHack
SQL Server does not have a pleasant TEXT datatype, so we use an arbetary value in a VARCHAR.

See Also:
Constant Field Values

sqlServerMaxBinarySize

public static final int sqlServerMaxBinarySize
Maximum size of a binary field.

See Also:
Constant Field Values
Constructor Detail

SQLServer

public SQLServer()
Constructor.

Method Detail

getSchema

public String getSchema()
Get the user we are connected as and return that as the schema. The db schema name to use, if any. This is typically the JDBC connection URL User string.

Specified by:
getSchema in interface Dbms
Overrides:
getSchema in class AnsiStandard
Returns:
the schema to use or null if not required
See Also:
Dbms.getSchema(), AnsiStandard.getSchema(), org.melati.poem.dbms.Ansistandard#getConnection()

getSqlDefinition

public String getSqlDefinition(String sqlTypeName)
Retrieve a SQL type keyword used by the DBMS for the given Melati type name. Override this in non-Ansi standard dbms to handle variants.

Specified by:
getSqlDefinition in interface Dbms
Overrides:
getSqlDefinition in class AnsiStandard
Parameters:
sqlTypeName - the Melati internal type name
Returns:
this dbms specific type keyword
See Also:
AnsiStandard.getSqlDefinition(java.lang.String)

getStringSqlDefinition

public String getStringSqlDefinition(int size)
                              throws SQLException
Accomodate String / Text distinction.

Specified by:
getStringSqlDefinition in interface Dbms
Overrides:
getStringSqlDefinition in class AnsiStandard
Parameters:
size - the string length (-1 means no limit)
Returns:
the SQL definition for a string of this size
Throws:
SQLException
See Also:
AnsiStandard.getStringSqlDefinition(int)

canRepresent

public PoemType canRepresent(PoemType storage,
                             PoemType type)
Accomodate our String size hack. Enable one PoemType to represent another, for example a bit to represent a boolean.

Specified by:
canRepresent in interface Dbms
Overrides:
canRepresent in class AnsiStandard
Parameters:
storage - the POEM native type
type - the current type
Returns:
the PoemType to use
See Also:
AnsiStandard.canRepresent(org.melati.poem.PoemType, org.melati.poem.PoemType)

sqlBooleanValueOfRaw

public String sqlBooleanValueOfRaw(Object raw)
Accomodate different true and false values.

Specified by:
sqlBooleanValueOfRaw in interface Dbms
Overrides:
sqlBooleanValueOfRaw in class AnsiStandard
Returns:
the DBMS specific truth and false values
See Also:
AnsiStandard.sqlBooleanValueOfRaw(java.lang.Object)

getLongSqlDefinition

public String getLongSqlDefinition()
Accomodate Long / Bigint deviants.

Specified by:
getLongSqlDefinition in interface Dbms
Overrides:
getLongSqlDefinition in class AnsiStandard
Returns:
the keyword to use.
See Also:
Dbms.getLongSqlDefinition()

getBinarySqlDefinition

public String getBinarySqlDefinition(int size)
                              throws SQLException
Accomodate different treatment of different sized binary data.

Specified by:
getBinarySqlDefinition in interface Dbms
Overrides:
getBinarySqlDefinition in class AnsiStandard
Parameters:
size - how big the field is
Returns:
the keyword to use
Throws:
SQLException
See Also:
Dbms.getBinarySqlDefinition(int)

defaultPoemTypeOfColumnMetaData

public SQLPoemType defaultPoemTypeOfColumnMetaData(ResultSet md)
                                            throws SQLException
The simplest POEM type corresponding to a JDBC description from the database.

Specified by:
defaultPoemTypeOfColumnMetaData in interface Dbms
Overrides:
defaultPoemTypeOfColumnMetaData in class AnsiStandard
Parameters:
md - the JDBC metadata
Returns:
the PoemType to use
Throws:
SQLException - potentially
See Also:
AnsiStandard.defaultPoemTypeOfColumnMetaData( java.sql.ResultSet)

melatiName

public String melatiName(String name)
Ignore dtproperties as it is a 'System' table used to store Entity Relationship diagrams which have a jdbc type of TABLE when it should probably have a jdbc type of 'SYSTEM TABLE'. Reverse the mapping in unreservedName.

Specified by:
melatiName in interface Dbms
Overrides:
melatiName in class AnsiStandard
Parameters:
name - an SQL name
Returns:
the coresponding name to use within Melati
See Also:
AnsiStandard.melatiName(java.lang.String)

canBeIndexed

public boolean canBeIndexed(Column column)
MSSQL cannot index TEXT fields. Probably means that if you are serious about using MSSQL you should use a varchar. If a field is defined as Text in the DSD we use a VARCHAR. Not sure what happens if a legacy db really uses TEXT.

Specified by:
canBeIndexed in interface Dbms
Overrides:
canBeIndexed in class AnsiStandard
Parameters:
column - the POEM Column we are dealing with
Returns:
whether it is allowed.
See Also:
Dbms.canBeIndexed(org.melati.poem.Column)

caseInsensitiveRegExpSQL

public String caseInsensitiveRegExpSQL(String term1,
                                       String term2)
This is the Postgresql syntax. Accomodate the variety of ways of ignoring case.

Specified by:
caseInsensitiveRegExpSQL in interface Dbms
Overrides:
caseInsensitiveRegExpSQL in class AnsiStandard
Parameters:
term1 - the term to find in
term2 - the quoted term to find
Returns:
the SQL query to use
See Also:
AnsiStandard.caseInsensitiveRegExpSQL(java.lang.String, java.lang.String)

getForeignKeyDefinition

public String getForeignKeyDefinition(String tableName,
                                      String fieldName,
                                      String targetTableName,
                                      String targetTableFieldName,
                                      String fixName)
Slightly different - embrace and extend. If Foreign key definitions are part of field definitions, otherwise blank (silently unsupported).

Specified by:
getForeignKeyDefinition in interface Dbms
Overrides:
getForeignKeyDefinition in class AnsiStandard
Parameters:
tableName - the table that this column is in, unquoted
fieldName - often the name of the foreign table, unquoted
targetTableName - the table that this is a foreign key into, unquoted
targetTableFieldName - name of the primary key field of the foreign table, often id, unquoted
fixName - name of the IntegrityFix
Returns:
The definition string
See Also:
AnsiStandard.getForeignKeyDefinition(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

alterColumnNotNullableSQL

public String alterColumnNotNullableSQL(String tableName,
                                        Column column)
Accommodate SQLServer syntax. Return the SQL snippet to alter a column to not nullable.

Specified by:
alterColumnNotNullableSQL in interface Dbms
Overrides:
alterColumnNotNullableSQL in class AnsiStandard
Returns:
SQL snippet to set a column not nullable
See Also:
alterColumnNotNullableSQL(java.lang.String, java.lang.String)

selectLimit

public String selectLimit(String querySelection,
                          int limit)
Accomodate different limiting syntax.

Specified by:
selectLimit in interface Dbms
Overrides:
selectLimit in class AnsiStandard
Parameters:
querySelection - main body of query
limit - number to limit to
Returns:
limited query
See Also:
Dbms.selectLimit(java.lang.String, int)

booleanTrueExpression

public String booleanTrueExpression(Column booleanColumn)
Accomodate lack of boolean types.

Specified by:
booleanTrueExpression in interface Dbms
Overrides:
booleanTrueExpression in class AnsiStandard
Returns:
an expresion that evaluates to True ie the column name or column name = 1
See Also:
Dbms.booleanTrueExpression(org.melati.poem.Column)

getSqlDefaultValue

public String getSqlDefaultValue(SQLType sqlType)
Used to set a not null value when creating a non nullable column.

Specified by:
getSqlDefaultValue in interface Dbms
Overrides:
getSqlDefaultValue in class AnsiStandard
Parameters:
sqlType - the type name
Returns:
a String suitable for substitution in UPDATE table SET field = ?
See Also:
AnsiStandard.getSqlDefaultValue(org.melati.poem.SQLType)

getQuotedValue

public String getQuotedValue(SQLType sqlType,
                             String value)
Accomodate different quoting strategies for values.

Specified by:
getQuotedValue in interface Dbms
Overrides:
getQuotedValue in class AnsiStandard
Parameters:
sqlType - the SQLType of the value
value - the value
Returns:
a String quoted appropriately
See Also:
org.melati.poem.dbms.Dbms#getQuotedValue(org.melati.poem.SQLType, java.lang.Object)


Copyright © 2000-2010 PanEris. All Rights Reserved.