org.eclipse.datatools.sqltools.sqlbuilder.model
Class SQLDomainModel

java.lang.Object
  extended by org.eclipse.datatools.sqltools.sqlbuilder.model.SQLDomainModel

public class SQLDomainModel
extends java.lang.Object

This class provides a central access point for state and environment information for a SQL statement being edited by the SQL Builder. It also provides access to services such as parsing.


Constructor Summary
SQLDomainModel()
          Constructs an instance of this class.
SQLDomainModel(QueryStatement aStatement, Database aDatabase)
          Constructs an instance of this class with the given initial query statement and database.
 
Method Summary
 void clearStatementToTemplate()
          Clears the current statement to its template form.
 org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider createContentProvider()
          Creates and returns a content provider for this statement, based on the current adapter factory.
 org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider createLabelProvider()
          Creates and returns a label provider for this statement, based on the current adapter factory.
 org.eclipse.emf.common.notify.AdapterFactory getAdapterFactory()
          Gets the adapter factory for this statement.
 java.sql.Connection getConnection()
          Gets a JDBC Connection object for the connection to the database.
 ISQLEditorConnectionInfo getConnectionInfo()
          Gets the ISQLEditorConnectionInfo object associated with this statement.
 java.lang.String getCurrentSchema()
          Gets the current schema.
 Database getDatabase()
          Gets the Database object that corresponds to this SQL statement.
 DatabaseDefinition getDatabaseDefinition()
          Gets the current DatabaseDefinition object.
 org.eclipse.datatools.sqltools.core.DatabaseIdentifier getDatabaseIdentifier()
           
 java.lang.String getDefaultSchema()
          Gets the default schema for the current connection profile.
 QueryStatement getDefaultStatementFromSQL(java.lang.String sql, java.lang.String statementName)
          Gets a default SQL statement object based on the given SQL string.
 QueryStatement getDefaultStatementFromStatementType(int statementType, java.lang.String statementName)
          Gets a default SQL statement object based on the given statement type.
 org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain getEditingDomain()
          Gets the editing domain for this statement.
 org.eclipse.core.resources.IFile getIFile()
          Gets the file resource associated with this statement, if any.
 java.lang.String getImproperStatement()
          Gets the current "improper" (failed to parse) statement, if there is one.
 java.lang.String getInitialSource()
          Gets the initial source contained in the IFile
 boolean getIsStatementTypeSupported(int stmtType)
          Gets whether or not the given SQL statement type is supported in the SQL Query Builder.
 IOmitSchemaInfo getOmitSchemaInfo()
          Gets the OmitSchemaInfo object associated with this statement
 PostParseProcessorConfiguration getPostParseProcessorConfiguration()
          Gets the configuration object to configure list of PostParseProcessor objects for the parser.
 java.util.List getPostParseProcessorList()
          Gets the current list of PostParseProcessor objects.
 org.eclipse.core.resources.IProject getProject()
          Gets the project associated with this statement.
 java.lang.String getSQLForExecution()
          Gets the source of a statement for execution (schema qaulified).
 SQLQuerySourceFormat getSqlSourceFormat()
          Gets the current SQLQuerySourceFormat object.
 QueryStatement getSQLStatement()
          Gets the current query statement.
 java.lang.String getTemplateSQL(int type)
          Gets template SQL for the given statement type.
 java.lang.String getTemplateSQLForCurrentStatement()
          Gets the template SQL for the current statement.
 java.lang.String getUserName()
          Gets the user name for the current connection profile
 VendorHelper getVendor()
          Gets the current vendor information object for this database.
 boolean initializeFromString(java.lang.String strSQL, java.lang.String statementName)
          Initializes the SQL statement in the SQL Builder from the content of the given string.
 boolean initializeFromType(int statementType)
          Initializes the SQL statement in the SQL Builder from the statement type.
 boolean isConnected()
           
 boolean isDirty()
          Gets whether or not this statement is "dirty" (that is, has unsaved changes).
 boolean isProper()
          Gets whether or not there is currently an "improper" (failed to parse) statement.
 boolean isUnmatchedSource()
          Gets whether or not the source and the SQL model matches
 boolean openFileResource(org.eclipse.core.resources.IFile fileResource)
          Initializes the SQL statement in the SQL Builder from the content of the given file.
 boolean openStorageResource(org.eclipse.core.resources.IStorage storageResource)
          Initializes the SQL statement in the SQL Builder from the contents of the given storage (non-file) resource object.
 QueryStatement parse(java.lang.String sqlStr)
          Parses string SQL statement passed and returns the QueryStatement object.
 QueryStatement parse(java.lang.String sqlStr, boolean createObjectTree)
          Parses string SQL statement passed and returns the QueryStatement object.If createObjectTree is false then parser is called for only a syntax check and only the toplevel statement object is constructed If parse fails it returns null.
 QueryStatement parse(java.lang.String sqlStr, java.util.List errorList)
          Parses string SQL statement passed and returns the QueryStatement object.
 void replaceStatementContents(QueryStatement newStmt)
          Replaces the content of the current statement with the content of the given statement without replacing the current statement object itself.
 void resetOmitSchemaToCurrentSchema()
          Sets the omit schema field of the source format to the current schema
 VendorHelper resetVendor(Database db)
          Resets the VendorHelper to associate with a new database.
 boolean save()
          Saves the current statement in the file resource associated with this editor.
 void setConnectionInfo(ISQLEditorConnectionInfo info)
          Sets the ISQLEditorConnectionInfo object associated with this statement to the given object.
 void setCurrentSchema()
          Sets the current schema
 void setDatabase(Database database)
          Sets the Database object associated with this statement to the given object.
 void setDirty(boolean dirty)
          Marks this statement as "dirty" (that is, has unsaved changes).
 void setEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain anEditingDomain)
          Sets the editing domain for this statement.
 void setEditorText(java.lang.String text)
          Sets the text to be used to save to project
 void setIFile(org.eclipse.core.resources.IFile aFileResource)
          Sets the file resource for this statement to the given object.
 void setImproperStatement(java.lang.String improperStmt)
          Sets the given string as the "improper" (failed to parser) statement.
 void setInitialSource(java.lang.String strSQL)
           
 void setOmitSchemaInfo(IOmitSchemaInfo info)
          Sets the OmitSchemaInfo object associated with this statement to the given object.
 void setProject(org.eclipse.core.resources.IProject proj)
          Sets the project associated with this statement to the given project.
 void setSqlSourceFormat(SQLQuerySourceFormat sqlSourceFormat)
          Sets the current SQLQuerySourceFormat object.
 void setSQLStatement(QueryStatement query)
          Sets the current query statement.
 void setUnmatchedSource(boolean unmatched)
          Sets whether or not the source is un-matched
static void showParseErrors(java.lang.Exception exception)
          Shows the current parse errors for this statement in an error dialog.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLDomainModel

public SQLDomainModel()
Constructs an instance of this class. This is the default constructor.


SQLDomainModel

public SQLDomainModel(QueryStatement aStatement,
                      Database aDatabase)
Constructs an instance of this class with the given initial query statement and database.

Parameters:
aStatement - the query statement to use
aDatabase - the database to use
Method Detail

getEditingDomain

public org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain getEditingDomain()
Gets the editing domain for this statement.

Returns:
the editing domain object

setEditingDomain

public void setEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain anEditingDomain)
Sets the editing domain for this statement.

Parameters:
anEditingDomain - the editing domain to use

getAdapterFactory

public org.eclipse.emf.common.notify.AdapterFactory getAdapterFactory()
Gets the adapter factory for this statement.

Returns:
the adapter factory object

createContentProvider

public org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider createContentProvider()
Creates and returns a content provider for this statement, based on the current adapter factory.

Returns:
the content provider

createLabelProvider

public org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider createLabelProvider()
Creates and returns a label provider for this statement, based on the current adapter factory.

Returns:
the label provider

getSQLStatement

public QueryStatement getSQLStatement()
Gets the current query statement.

Returns:
the current query statement object

setSQLStatement

public void setSQLStatement(QueryStatement query)
Sets the current query statement. This is intended for use by the QueryViewer.

Parameters:
query - the query statement to set

getTemplateSQL

public java.lang.String getTemplateSQL(int type)
Gets template SQL for the given statement type. Note: this method uses getTemplateSQL() in StatementHelper and caches the template sql for all the types.

Parameters:
type - the type of the statement as defined in StatementHelper
Returns:
the template SQL or null if the type is not defined

getTemplateSQLForCurrentStatement

public java.lang.String getTemplateSQLForCurrentStatement()
Gets the template SQL for the current statement.

Returns:
the template SQL

replaceStatementContents

public void replaceStatementContents(QueryStatement newStmt)
Replaces the content of the current statement with the content of the given statement without replacing the current statement object itself.

Parameters:
newStmt - the statement with the new content

clearStatementToTemplate

public void clearStatementToTemplate()
Clears the current statement to its template form.


setDirty

public void setDirty(boolean dirty)
Marks this statement as "dirty" (that is, has unsaved changes).

Parameters:
dirty - true when there are unsaved changes, otherwise false

isDirty

public boolean isDirty()
Gets whether or not this statement is "dirty" (that is, has unsaved changes).

Returns:
true when there are unsaved changes, otherwise false

getIFile

public org.eclipse.core.resources.IFile getIFile()
Gets the file resource associated with this statement, if any.

Returns:
the file resource for this statement, or null if none

setIFile

public void setIFile(org.eclipse.core.resources.IFile aFileResource)
Sets the file resource for this statement to the given object.

Parameters:
resource - the file resource to set

showParseErrors

public static void showParseErrors(java.lang.Exception exception)
Shows the current parse errors for this statement in an error dialog.

Parameters:
exception - an exception indicating the error

openFileResource

public boolean openFileResource(org.eclipse.core.resources.IFile fileResource)
Initializes the SQL statement in the SQL Builder from the content of the given file.

Parameters:
fileResource - the IFile containing the source SQL
Returns:
true when the statement is parsable, otherwise false
Throws:
java.lang.Exception - when error occurs reading the content of the file resource

openStorageResource

public boolean openStorageResource(org.eclipse.core.resources.IStorage storageResource)
                            throws java.lang.Exception
Initializes the SQL statement in the SQL Builder from the contents of the given storage (non-file) resource object.

Parameters:
storageResource - the IStorage resource containing the source SQL
Returns:
true when the statement was initialized successfully, otherwise false
Throws:
java.lang.Exception - when an error occurs obtaining the content of the storage resource

initializeFromString

public boolean initializeFromString(java.lang.String strSQL,
                                    java.lang.String statementName)
Initializes the SQL statement in the SQL Builder from the content of the given string.

Parameters:
strSQL - the source SQL string
Returns:
true when the statement is parsable, otherwise false

initializeFromType

public boolean initializeFromType(int statementType)
Initializes the SQL statement in the SQL Builder from the statement type.

Parameters:
statement - type Statement type is used for creating new statements. The value must be one of StatementHelper's STATEMENT_TYPE constants.
Returns:
true

getConnection

public java.sql.Connection getConnection()
Gets a JDBC Connection object for the connection to the database.

Returns:
the connection, or null if a connection is not available

getDatabase

public Database getDatabase()
Gets the Database object that corresponds to this SQL statement.

Returns:
the database object

setDatabase

public void setDatabase(Database database)
Sets the Database object associated with this statement to the given object.

Parameters:
database - the database object to set

getDatabaseDefinition

public DatabaseDefinition getDatabaseDefinition()
Gets the current DatabaseDefinition object.

Returns:
the database definition object

getProject

public org.eclipse.core.resources.IProject getProject()
Gets the project associated with this statement.

Returns:
the current project

setProject

public void setProject(org.eclipse.core.resources.IProject proj)
Sets the project associated with this statement to the given project.

Parameters:
proj - the project to set

getConnectionInfo

public ISQLEditorConnectionInfo getConnectionInfo()
Gets the ISQLEditorConnectionInfo object associated with this statement.

Returns:
ISQLEditorConnectionInfo the model's connection info object

setConnectionInfo

public void setConnectionInfo(ISQLEditorConnectionInfo info)
Sets the ISQLEditorConnectionInfo object associated with this statement to the given object.

Parameters:
info - the connection info object to set

setOmitSchemaInfo

public void setOmitSchemaInfo(IOmitSchemaInfo info)
Sets the OmitSchemaInfo object associated with this statement to the given object.

Parameters:
info - the OmitSchemaInfo object to set

getOmitSchemaInfo

public IOmitSchemaInfo getOmitSchemaInfo()
Gets the OmitSchemaInfo object associated with this statement

Returns:
OmitSchemaInfo the model's OmitSchemaInfo object

save

public boolean save()
Saves the current statement in the file resource associated with this editor.

Returns:
true when save is successful, otherwise false

setEditorText

public void setEditorText(java.lang.String text)
Sets the text to be used to save to project

Parameters:
text - the text to be used for saving to project

getVendor

public VendorHelper getVendor()
Gets the current vendor information object for this database.

Returns:
the current vendor helper object

resetVendor

public VendorHelper resetVendor(Database db)
Resets the VendorHelper to associate with a new database. This is need for cases where no connection is available when this class is first instantiated.

Parameters:
db - the new database to create the VendorHelper with
Returns:
the newly created VendorHelper, or null if db is null

isProper

public boolean isProper()
Gets whether or not there is currently an "improper" (failed to parse) statement.

Returns:
true when there is an improper statement, otherwise false

setImproperStatement

public void setImproperStatement(java.lang.String improperStmt)
Sets the given string as the "improper" (failed to parser) statement.

Parameters:
improperStmt - the statement string to set

getImproperStatement

public java.lang.String getImproperStatement()
Gets the current "improper" (failed to parse) statement, if there is one.

Returns:
the current improper statement, or null if none

setCurrentSchema

public void setCurrentSchema()
Sets the current schema

Parameters:
the - current schema to set

getCurrentSchema

public java.lang.String getCurrentSchema()
Gets the current schema.

Returns:
the current schema value

getDefaultStatementFromSQL

public QueryStatement getDefaultStatementFromSQL(java.lang.String sql,
                                                 java.lang.String statementName)
Gets a default SQL statement object based on the given SQL string. It does this by examining the first word of the string. This is used when the SQL string can't be properly parsed, and we need to reset to a default statement.

Parameters:
sql - the SQL string to use to determine the statement type
statementName - a name for the new statement
Returns:
the default SQL statement object

getDefaultStatementFromStatementType

public QueryStatement getDefaultStatementFromStatementType(int statementType,
                                                           java.lang.String statementName)
Gets a default SQL statement object based on the given statement type.

Parameters:
statementType - the statement type
statementName - a name for the new statement. The value should be one of StatementHelper's STATEMENT_TYPE constants.
Returns:
the default SQL statement object

parse

public QueryStatement parse(java.lang.String sqlStr)
                     throws SQLParserException,
                            SQLParserInternalException
Parses string SQL statement passed and returns the QueryStatement object. If parse fails it returns null.

Parameters:
sqlStr - the String sql statement
Returns:
the generated Query object
Throws:
SQLParserException - if the parse was not successful
SQLParserInternalException

parse

public QueryStatement parse(java.lang.String sqlStr,
                            java.util.List errorList)
                     throws SQLParserException,
                            SQLParserInternalException
Parses string SQL statement passed and returns the QueryStatement object. If parse fails it returns null. The ErrorList is also returned as a parameter

Parameters:
sqlStr - the String sql statement
errorList - the List to hold the errorList object from parseResult. Can not be null.
Returns:
the generated Query object
Throws:
SQLParserException - if the parse was not successful
SQLParserInternalException

parse

public QueryStatement parse(java.lang.String sqlStr,
                            boolean createObjectTree)
                     throws SQLParserException,
                            SQLParserInternalException
Parses string SQL statement passed and returns the QueryStatement object.If createObjectTree is false then parser is called for only a syntax check and only the toplevel statement object is constructed If parse fails it returns null.

Parameters:
sqlStr - the String sql statement
createObjectTree -
Returns:
the generated Query object
Throws:
SQLParserException - if the parse was not successful
SQLParserInternalException

getSqlSourceFormat

public SQLQuerySourceFormat getSqlSourceFormat()
Gets the current SQLQuerySourceFormat object. The SQLQuerySourceFormat object contains parameters that indicate how the SQL for the query model should be generated and parsed.

Returns:
the SQLQuerySourceFormat object

setSqlSourceFormat

public void setSqlSourceFormat(SQLQuerySourceFormat sqlSourceFormat)
Sets the current SQLQuerySourceFormat object. The SQLQuerySourceFormat object contains parameters that indicate how the SQL for the query model should be generated and parsed.

Parameters:
sqlSourceFormat - the SQLQuerySourceFormat object to use

getSQLForExecution

public java.lang.String getSQLForExecution()
Gets the source of a statement for execution (schema qaulified). This is for the omit schema support where the current schema set by the user may not match the SQLID of the server causing a table not found error.

Returns:
the schema qualified statement source

resetOmitSchemaToCurrentSchema

public void resetOmitSchemaToCurrentSchema()
Sets the omit schema field of the source format to the current schema


getPostParseProcessorList

public java.util.List getPostParseProcessorList()
Gets the current list of PostParseProcessor objects. PostParseProcessor objects are used by the parser after a query model is generated to by the parser to modify or verify the generated model before returning it to the caller of the parser. By default, the list contains a table reference resolver and a data type resolver.

Returns:
the current list of PostParseProcessor objects

getInitialSource

public java.lang.String getInitialSource()
Gets the initial source contained in the IFile

Returns:
the content of the IFile

isUnmatchedSource

public boolean isUnmatchedSource()
Gets whether or not the source and the SQL model matches

Returns:
true if the source and SQL model does not match, false if they do

setUnmatchedSource

public void setUnmatchedSource(boolean unmatched)
Sets whether or not the source is un-matched

Parameters:
whether - or not the source and the sql model is unmatched

getDefaultSchema

public java.lang.String getDefaultSchema()
Gets the default schema for the current connection profile. This is normally the login user id.

Returns:
the default schema

getUserName

public java.lang.String getUserName()
Gets the user name for the current connection profile


getPostParseProcessorConfiguration

public PostParseProcessorConfiguration getPostParseProcessorConfiguration()
Gets the configuration object to configure list of PostParseProcessor objects for the parser. PostParseProcessor objects are used by the parser after a query model is generated to by the parser to modify or verify the generated model before returning it to the caller of the parser. By default, the list contains a table reference resolver and a data type resolver.

Returns:
the configuration object for PostParseProcessor objects

getDatabaseIdentifier

public org.eclipse.datatools.sqltools.core.DatabaseIdentifier getDatabaseIdentifier()

isConnected

public boolean isConnected()

setInitialSource

public void setInitialSource(java.lang.String strSQL)

getIsStatementTypeSupported

public boolean getIsStatementTypeSupported(int stmtType)
Gets whether or not the given SQL statement type is supported in the SQL Query Builder. See the list of statement type constants defined in the StatementHelper class.

Parameters:
stmtType - the statement type to check
Returns:
true when the statement type is supported, otherwise false