Dresden OCL Toolkit

tudresden.ocl.codegen.decl
Class ILSQLCodeGenerator

java.lang.Object
  extended bytudresden.ocl.parser.analysis.AnalysisAdapter
      extended bytudresden.ocl.parser.analysis.ReversedDepthFirstAdapter
          extended bytudresden.ocl.codegen.decl.DeclarativeCodeGenerator
              extended bytudresden.ocl.codegen.decl.ILSQLCodeGenerator
All Implemented Interfaces:
Analysis, CodeGenerator, Switch

public class ILSQLCodeGenerator
extends DeclarativeCodeGenerator

A class that generates SQL code out of a ocl contraint or the abstract syntax tree of the ocl contraint respectivly. This is the second version of a SQL code generator, formerly implemented as SQLCodeGenerator.

Author:
Sten Loecher

Field Summary
(package private) static String ALIAS
           
(package private)  int aliasCount
           
(package private) static String COMPLEX_PREDICATE
           
(package private)  String constrainedType
           
(package private)  String constraintName
           
(package private) static String dcolon
           
(package private)  Hashtable declarators
           
(package private)  boolean formatCode
          true if the generated code should be formated, false otherwise
(package private)  Set involvedTables
           
(package private)  int joinAliasCount
           
(package private)  boolean joinMode
          true if classic column joins should be generated, false if derived tables are needed
(package private)  String joinRepresentation
           
(package private)  String joinTargetObject
           
(package private)  ORMappingScheme map
           
(package private)  Set modelTypeFeatures
           
(package private)  Map navigation
           
(package private)  String oclAnyOperations
           
(package private)  String oclCollectionOperations
           
(package private)  String oclNotSupportedFeatures
           
(package private)  String oclTokBasic1
           
(package private)  String oclTokBasic2
           
(package private)  String oclTokBasic3
           
(package private)  String oclTokens
           
(package private)  String oclTypeOperations
           
(package private) static String SEQNO
           
(package private) static String STANDARDKEY
           
(package private) static String STANDARDTABLE
           
(package private)  String tableRepresentation
           
 
Fields inherited from class tudresden.ocl.codegen.decl.DeclarativeCodeGenerator
ca, code, fragments, theTree
 
Fields inherited from class tudresden.ocl.parser.analysis.AnalysisAdapter
 
Constructor Summary
ILSQLCodeGenerator(String rules)
           
 
Method Summary
private  boolean containsPackage(String pathName)
           
 void formatSQLCode()
          Does some formating of the generated SQL code.
 String getJoinRepresentation()
           
private  Table getOclSupertypeTable(AFeatureCall node)
          Note: If the type for expression does not have a supertype, a null value will be returned.
private  Table getOclTypeTable(AFeatureCall node)
           
private  String getPathName(APathName node)
           
 String getTableRepresentation()
           
private  String getUniqueAlias()
           
 void inAAdditiveExpressionTail(AAdditiveExpressionTail node)
           
 void inAConstraint(AConstraint node)
          Creates the first task, initializes the code buffer with it and delegates it to all subnodes.
 void inAConstraintBody(AConstraintBody node)
           
 void inAContextDeclaration(AContextDeclaration node)
           
 void inAFeatureCall(AFeatureCall node)
           
 void inAFeaturePrimaryExpression(AFeaturePrimaryExpression node)
           
 void inAIfExpression(AIfExpression node)
           
 void inALiteralCollection(ALiteralCollection node)
           
 void inALiteralPrimaryExpression(ALiteralPrimaryExpression node)
           
 void inALogicalExpressionTail(ALogicalExpressionTail node)
           
 void inAMultiplicativeExpressionTail(AMultiplicativeExpressionTail node)
           
 void inAParenthesesPrimaryExpression(AParenthesesPrimaryExpression node)
           
 void inAPostfixExpression(APostfixExpression node)
           
 void inARelationalExpressionTail(ARelationalExpressionTail node)
           
 void inAUnaryUnaryExpression(AUnaryUnaryExpression node)
           
 void outAConstraintBody(AConstraintBody node)
           
 void prepareClassicJoin(List guides)
           
 void prepareDerivedTable(List guides)
           
 void prepareNavigation(List guides)
           
 void reset()
          Resets the ILSQLCodeGenerator object to initial values.
private  void setContextAlias(List guides, String alias)
           
 void setJoinMode(boolean b)
          Sets the join mode for the generation process.
 void setORMappingScheme(ORMappingScheme map)
           
private  void updateInvolvedTables(List guides)
          Adds all tables to the involved tables list which are contained within the guides in the specified list.
 
Methods inherited from class tudresden.ocl.codegen.decl.DeclarativeCodeGenerator
defaultIn, getCode, getUniqueTask, replaceInString, replaceTask, setRules, transferTask, transferTask
 
Methods inherited from class tudresden.ocl.parser.analysis.ReversedDepthFirstAdapter
caseAActualParameterList, caseAActualParameterListTail, caseAAdditiveExpression, caseAAdditiveExpressionTail, caseAAndLogicalOperator, caseAArrowPostfixExpressionTailBegin, caseABagCollectionKind, caseABagCollectionType, caseABarFcpHelper, caseABooleanLiteral, caseAClassifierContext, caseAClassifierContextBody, caseAClassifierHead, caseACollectionCollectionKind, caseACollectionCollectionType, caseACollectionTypeName, caseAColonFcpHelper, caseACommaFcpHelper, caseAConcreteFeatureCallParameters, caseAConstraint, caseAConstraintBody, caseAContextDeclaration, caseADeclaratorTail, caseADeclaratorTypeDeclaration, caseADivMultiplyOperator, caseADotPostfixExpressionTailBegin, caseAEmptyFeatureCallParameters, caseAEnumerationType, caseAEnumerationTypeTail, caseAEnumLiteral, caseAEnumSimpleTypeSpecifier, caseAEqualRelationalOperator, caseAExpression, caseAExpressionListOrRange, caseAExpressionListTail, caseAFeatureCall, caseAFeatureCallParameters, caseAFeaturePrimaryExpression, caseAFormalParameter, caseAFormalParameterList, caseAFormalParameterListTail, caseAGteqRelationalOperator, caseAGtRelationalOperator, caseAIfExpression, caseAIfPrimaryExpression, caseAImpliesLogicalOperator, caseAIntegerLiteral, caseAInvStereotype, caseAIterateDeclarator, caseAIterateFcpHelper, caseALetExpression, caseALetExpressionTypeDeclaration, caseAListExpressionListOrRangeTail, caseALitColPrimaryExpression, caseALiteralCollection, caseALiteralPrimaryExpression, caseALogicalExpression, caseALogicalExpressionTail, caseALteqRelationalOperator, caseALtRelationalOperator, caseAMinusAddOperator, caseAMinusUnaryOperator, caseAMultiplicativeExpression, caseAMultiplicativeExpressionTail, caseAMultMultiplyOperator, caseANamePathNameBegin, caseANamePathNameEnd, caseANEqualRelationalOperator, caseANonCollectionTypeName, caseANotUnaryOperator, caseAOperationContext, caseAOperationContextBody, caseAOrLogicalOperator, caseAParenthesesPrimaryExpression, caseAPathName, caseAPathNameTail, caseAPathSimpleTypeSpecifier, caseAPathTypeName, caseAPathTypeNameTail, caseAPlusAddOperator, caseAPostfixExpression, caseAPostfixExpressionTail, caseAPostfixUnaryExpression, caseAPostStereotype, caseAPreStereotype, caseAQualifiers, caseARangeExpressionListOrRangeTail, caseARealLiteral, caseARelationalExpression, caseARelationalExpressionTail, caseAReturnTypeDeclaration, caseASequenceCollectionKind, caseASequenceCollectionType, caseASetCollectionKind, caseASetCollectionType, caseAStandardDeclarator, caseAStringLiteral, caseATimeExpression, caseATypeNamePathNameBegin, caseATypeNamePathNameEnd, caseAUnaryUnaryExpression, caseAXorLogicalOperator, caseStart, defaultOut, inAActualParameterList, inAActualParameterListTail, inAAdditiveExpression, inAAndLogicalOperator, inAArrowPostfixExpressionTailBegin, inABagCollectionKind, inABagCollectionType, inABarFcpHelper, inABooleanLiteral, inAClassifierContext, inAClassifierContextBody, inAClassifierHead, inACollectionCollectionKind, inACollectionCollectionType, inACollectionTypeName, inAColonFcpHelper, inACommaFcpHelper, inAConcreteFeatureCallParameters, inADeclaratorTail, inADeclaratorTypeDeclaration, inADivMultiplyOperator, inADotPostfixExpressionTailBegin, inAEmptyFeatureCallParameters, inAEnumerationType, inAEnumerationTypeTail, inAEnumLiteral, inAEnumSimpleTypeSpecifier, inAEqualRelationalOperator, inAExpression, inAExpressionListOrRange, inAExpressionListTail, inAFeatureCallParameters, inAFormalParameter, inAFormalParameterList, inAFormalParameterListTail, inAGteqRelationalOperator, inAGtRelationalOperator, inAIfPrimaryExpression, inAImpliesLogicalOperator, inAIntegerLiteral, inAInvStereotype, inAIterateDeclarator, inAIterateFcpHelper, inALetExpression, inALetExpressionTypeDeclaration, inAListExpressionListOrRangeTail, inALitColPrimaryExpression, inALogicalExpression, inALteqRelationalOperator, inALtRelationalOperator, inAMinusAddOperator, inAMinusUnaryOperator, inAMultiplicativeExpression, inAMultMultiplyOperator, inANamePathNameBegin, inANamePathNameEnd, inANEqualRelationalOperator, inANonCollectionTypeName, inANotUnaryOperator, inAOperationContext, inAOperationContextBody, inAOrLogicalOperator, inAPathName, inAPathNameTail, inAPathSimpleTypeSpecifier, inAPathTypeName, inAPathTypeNameTail, inAPlusAddOperator, inAPostfixExpressionTail, inAPostfixUnaryExpression, inAPostStereotype, inAPreStereotype, inAQualifiers, inARangeExpressionListOrRangeTail, inARealLiteral, inARelationalExpression, inAReturnTypeDeclaration, inASequenceCollectionKind, inASequenceCollectionType, inASetCollectionKind, inASetCollectionType, inAStandardDeclarator, inAStringLiteral, inATimeExpression, inATypeNamePathNameBegin, inATypeNamePathNameEnd, inAXorLogicalOperator, inStart, outAActualParameterList, outAActualParameterListTail, outAAdditiveExpression, outAAdditiveExpressionTail, outAAndLogicalOperator, outAArrowPostfixExpressionTailBegin, outABagCollectionKind, outABagCollectionType, outABarFcpHelper, outABooleanLiteral, outAClassifierContext, outAClassifierContextBody, outAClassifierHead, outACollectionCollectionKind, outACollectionCollectionType, outACollectionTypeName, outAColonFcpHelper, outACommaFcpHelper, outAConcreteFeatureCallParameters, outAConstraint, outAContextDeclaration, outADeclaratorTail, outADeclaratorTypeDeclaration, outADivMultiplyOperator, outADotPostfixExpressionTailBegin, outAEmptyFeatureCallParameters, outAEnumerationType, outAEnumerationTypeTail, outAEnumLiteral, outAEnumSimpleTypeSpecifier, outAEqualRelationalOperator, outAExpression, outAExpressionListOrRange, outAExpressionListTail, outAFeatureCall, outAFeatureCallParameters, outAFeaturePrimaryExpression, outAFormalParameter, outAFormalParameterList, outAFormalParameterListTail, outAGteqRelationalOperator, outAGtRelationalOperator, outAIfExpression, outAIfPrimaryExpression, outAImpliesLogicalOperator, outAIntegerLiteral, outAInvStereotype, outAIterateDeclarator, outAIterateFcpHelper, outALetExpression, outALetExpressionTypeDeclaration, outAListExpressionListOrRangeTail, outALitColPrimaryExpression, outALiteralCollection, outALiteralPrimaryExpression, outALogicalExpression, outALogicalExpressionTail, outALteqRelationalOperator, outALtRelationalOperator, outAMinusAddOperator, outAMinusUnaryOperator, outAMultiplicativeExpression, outAMultiplicativeExpressionTail, outAMultMultiplyOperator, outANamePathNameBegin, outANamePathNameEnd, outANEqualRelationalOperator, outANonCollectionTypeName, outANotUnaryOperator, outAOperationContext, outAOperationContextBody, outAOrLogicalOperator, outAParenthesesPrimaryExpression, outAPathName, outAPathNameTail, outAPathSimpleTypeSpecifier, outAPathTypeName, outAPathTypeNameTail, outAPlusAddOperator, outAPostfixExpression, outAPostfixExpressionTail, outAPostfixUnaryExpression, outAPostStereotype, outAPreStereotype, outAQualifiers, outARangeExpressionListOrRangeTail, outARealLiteral, outARelationalExpression, outARelationalExpressionTail, outAReturnTypeDeclaration, outASequenceCollectionKind, outASequenceCollectionType, outASetCollectionKind, outASetCollectionType, outAStandardDeclarator, outAStringLiteral, outATimeExpression, outATypeNamePathNameBegin, outATypeNamePathNameEnd, outAUnaryUnaryExpression, outAXorLogicalOperator, outStart
 
Methods inherited from class tudresden.ocl.parser.analysis.AnalysisAdapter
caseEOF, caseTAnd, caseTApostroph, caseTArrow, caseTAt, caseTBar, caseTBlank, caseTBool, caseTChannel, caseTColon, caseTComma, caseTComment, caseTContext, caseTDcolon, caseTDdot, caseTDiv, caseTDot, caseTEndif, caseTEnum, caseTEqual, caseTGt, caseTGteq, caseTImplies, caseTInt, caseTLBrace, caseTLBracket, caseTLPar, caseTLt, caseTLteq, caseTMinus, caseTMult, caseTName, caseTNEqual, caseTNewLine, caseTNot, caseTOr, caseTPlus, caseTRBrace, caseTRBracket, caseTReal, caseTRPar, caseTSemicolon, caseTSimpleTypeName, caseTStringLit, caseTTab, caseTTBag, caseTTCollection, caseTTElse, caseTTIf, caseTTIn, caseTTInv, caseTTLet, caseTTPost, caseTTPre, caseTTSequence, caseTTSet, caseTTThen, caseTXor, defaultCase, getIn, getOut, setIn, setOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constrainedType

String constrainedType

constraintName

String constraintName

navigation

Map navigation

map

ORMappingScheme map

modelTypeFeatures

Set modelTypeFeatures

involvedTables

Set involvedTables

declarators

Hashtable declarators

aliasCount

int aliasCount

joinAliasCount

int joinAliasCount

tableRepresentation

String tableRepresentation

joinRepresentation

String joinRepresentation

joinTargetObject

String joinTargetObject

oclNotSupportedFeatures

String oclNotSupportedFeatures

oclCollectionOperations

String oclCollectionOperations

oclTypeOperations

String oclTypeOperations

oclAnyOperations

String oclAnyOperations

oclTokBasic1

String oclTokBasic1

oclTokBasic2

String oclTokBasic2

oclTokBasic3

String oclTokBasic3

oclTokens

String oclTokens

dcolon

static final String dcolon
See Also:
Constant Field Values

ALIAS

static final String ALIAS
See Also:
Constant Field Values

SEQNO

static final String SEQNO
See Also:
Constant Field Values

STANDARDKEY

static final String STANDARDKEY
See Also:
Constant Field Values

STANDARDTABLE

static final String STANDARDTABLE
See Also:
Constant Field Values

COMPLEX_PREDICATE

static final String COMPLEX_PREDICATE
See Also:
Constant Field Values

formatCode

boolean formatCode
true if the generated code should be formated, false otherwise


joinMode

boolean joinMode
true if classic column joins should be generated, false if derived tables are needed

Constructor Detail

ILSQLCodeGenerator

public ILSQLCodeGenerator(String rules)
Method Detail

formatSQLCode

public void formatSQLCode()
Does some formating of the generated SQL code.


getPathName

private String getPathName(APathName node)

containsPackage

private boolean containsPackage(String pathName)
Parameters:
pathName - a path name
Returns:
true if pathName contains packages, false otherwise

setContextAlias

private void setContextAlias(List guides,
                             String alias)
Parameters:
guides - a List of Guide objects
alias - an context alias to set in all Guides in the List

getUniqueAlias

private String getUniqueAlias()
Returns:
a unique table alias for use in the SQL code

setORMappingScheme

public void setORMappingScheme(ORMappingScheme map)
Parameters:
map - an object relational mapping schema

reset

public void reset()
Resets the ILSQLCodeGenerator object to initial values. Must be used, if multiple invariants will be translated by one code generator object.


updateInvolvedTables

private void updateInvolvedTables(List guides)
Adds all tables to the involved tables list which are contained within the guides in the specified list.

Parameters:
guides - a List object containing Guide objects for the translation of navigation

setJoinMode

public void setJoinMode(boolean b)
Sets the join mode for the generation process. See variable joinMode for more information.


prepareNavigation

public void prepareNavigation(List guides)

prepareClassicJoin

public void prepareClassicJoin(List guides)

prepareDerivedTable

public void prepareDerivedTable(List guides)

getTableRepresentation

public String getTableRepresentation()
Returns:
a String that contains all tables for a classic join to put into a from clause

getJoinRepresentation

public String getJoinRepresentation()
Returns:
a String that contains all join definitions to put into a where clause

inAConstraint

public void inAConstraint(AConstraint node)
Description copied from class: DeclarativeCodeGenerator
Creates the first task, initializes the code buffer with it and delegates it to all subnodes.

Overrides:
inAConstraint in class DeclarativeCodeGenerator

inAConstraintBody

public void inAConstraintBody(AConstraintBody node)
Overrides:
inAConstraintBody in class ReversedDepthFirstAdapter

outAConstraintBody

public void outAConstraintBody(AConstraintBody node)
Overrides:
outAConstraintBody in class ReversedDepthFirstAdapter

inAContextDeclaration

public void inAContextDeclaration(AContextDeclaration node)
Overrides:
inAContextDeclaration in class ReversedDepthFirstAdapter

inALogicalExpressionTail

public void inALogicalExpressionTail(ALogicalExpressionTail node)
Overrides:
inALogicalExpressionTail in class ReversedDepthFirstAdapter

inARelationalExpressionTail

public void inARelationalExpressionTail(ARelationalExpressionTail node)
Overrides:
inARelationalExpressionTail in class ReversedDepthFirstAdapter

inAAdditiveExpressionTail

public void inAAdditiveExpressionTail(AAdditiveExpressionTail node)
Overrides:
inAAdditiveExpressionTail in class ReversedDepthFirstAdapter

inAMultiplicativeExpressionTail

public void inAMultiplicativeExpressionTail(AMultiplicativeExpressionTail node)
Overrides:
inAMultiplicativeExpressionTail in class ReversedDepthFirstAdapter

inAUnaryUnaryExpression

public void inAUnaryUnaryExpression(AUnaryUnaryExpression node)
Overrides:
inAUnaryUnaryExpression in class ReversedDepthFirstAdapter

inAPostfixExpression

public void inAPostfixExpression(APostfixExpression node)
Overrides:
inAPostfixExpression in class ReversedDepthFirstAdapter

inAFeaturePrimaryExpression

public void inAFeaturePrimaryExpression(AFeaturePrimaryExpression node)
Overrides:
inAFeaturePrimaryExpression in class ReversedDepthFirstAdapter

inAFeatureCall

public void inAFeatureCall(AFeatureCall node)
Overrides:
inAFeatureCall in class ReversedDepthFirstAdapter

inALiteralPrimaryExpression

public void inALiteralPrimaryExpression(ALiteralPrimaryExpression node)
Overrides:
inALiteralPrimaryExpression in class ReversedDepthFirstAdapter

inALiteralCollection

public void inALiteralCollection(ALiteralCollection node)
Overrides:
inALiteralCollection in class ReversedDepthFirstAdapter

inAIfExpression

public void inAIfExpression(AIfExpression node)
Overrides:
inAIfExpression in class ReversedDepthFirstAdapter

inAParenthesesPrimaryExpression

public void inAParenthesesPrimaryExpression(AParenthesesPrimaryExpression node)
Overrides:
inAParenthesesPrimaryExpression in class ReversedDepthFirstAdapter

getOclTypeTable

private Table getOclTypeTable(AFeatureCall node)
                       throws IllegalStateException
Returns:
the table/view that belongs to the type for expression: FeatureCall->FeatureCallParameters->ActualParameterList->Expression
Throws:
IllegalStateException

getOclSupertypeTable

private Table getOclSupertypeTable(AFeatureCall node)
                            throws IllegalStateException
Note: If the type for expression does not have a supertype, a null value will be returned.

Returns:
the table/view that belongs to the supertype for expression: FeatureCall->FeatureCallParameters->ActualParameterList->Expression
Throws:
IllegalStateException

Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.