From VisualWorks®, 7.6 of February 1, 2008 on February 1, 2008 at 1:13:40 pm (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>DB2LensTransporter</name> <environment>Smalltalk</environment> <super>Lens.LensSQLTransporter</super> <private>false</private> none <imports></imports> <category>Lens-Private-DB2</category> <attributes> <package>DB2Lens</package> </attributes> </class> <class> <name>DB2LensContext</name> <environment>Smalltalk</environment> <super>Lens.LensDatabaseContext</super> <private>false</private> none <imports></imports> <category>Lens-Private-DB2</category> <attributes> <package>DB2Lens</package> </attributes> </class> <class> <name>DB2LensTableColumn</name> <environment>Smalltalk</environment> <super>Lens.LensDatabaseTableColumn</super> <private>false</private> none table notNil type name maxColumnConstraint isKey dataType <imports></imports> <category>Lens-Private-DB2</category> <attributes> <package>DB2Lens</package> </attributes> </class> <class> <name>DB2LensTable</name> <environment>Smalltalk</environment> <super>Lens.LensDatabaseTable</super> <private>false</private> none name owner tableType columns <imports></imports> <category>Lens-Private-DB2</category> <attributes> <package>DB2Lens</package> </attributes> </class> <methods> DB2LensTransporter <category>accessing</category>
nextVariableName ^'?'
update: object withId: externalId andMask: updatedInstVarsMask withOldObject: oldObject "Update the record associated with object with externalId. If oldObject notNil check for optimistic lock conflicts using oldObject as the reference." | dbSession rc cmd cmdStream extBindTemplate | updateCommand == nil ifTrue: [ self initUpdateCommand ]. self startCommand. cmd := updateCommand copy. "copy the command as template" cmdStream := commandStream. variableIndex := numberOfIdVariables. cmdStream nextPutAll: 'UPDATE '. type tableNameOn: cmdStream. cmdStream nextPutAll: ' SET '. extBindTemplate:= cmd bindTemplate. cmd bindTemplate: nil. "add later, fix improper order of bind var" "cmd addBinding: externalId." type mappedVariablesDo: [ :var | | index value modified| index := var instVarIndex. modified := (updatedInstVarsMask bitAnd: (1 bitShift: index - 1)) > 0. "Check for versionNumber field. If this is one and it has not been modified - increment it." (var valueType isRowVersion and: [modified not]) ifTrue: [object globalDescriptor update: object instVarAt: index put: ((object instVarAt: index) + 1). modified := true]. modified ifTrue: [ value := object instVarAt: index. var checkShallowIncludes: value. (self bindVariable: var tableName: nil withUpdateMask: updatedInstVarsMask) ifTrue: [cmd addTemplate: (var fieldTemplateForUpdate: true withUpdateMask: updatedInstVarsMask); addBinding: (var encodeVariableOf: object in: session withUpdateMask: updatedInstVarsMask). cmdStream nextPut: $,]]]. cmdStream skip: -1. cmdStream nextPutAll: cmd body. "append where clause" cmd addBinding: externalId. "restore externalId part" cmd bindTemplate addAll: extBindTemplate. "restore externalId part" oldObject notNil ifTrue: [self addOptimisticConflictCheckOn: cmd against: oldObject andMask: updatedInstVarsMask]. cmd commandString: cmdStream contents. (dbSession := self doCommand: cmd) answerAfterCommand. (rc := dbSession rowCount) == 0 ifTrue: [ oldObject notNil ifTrue: [LensSession optimisticConflictDetectedSignal raise ] ifFalse: [LensSession rowForObjectNotFoundSignal raise ] ]. rc > 1 ifTrue: [ LensSession objectNotUniquelyIdentifiedSignal raise ]
</methods> <methods> DB2LensTransporter class <category>class initialization</category>
initialize super initialize
</methods> <methods> DB2LensContext <category>data dictionary manipulation</category>
getTableNamed: tableName in: session | t | ^(t := self listTablesLike: tableName in: session) isEmpty ifFalse: [t first]
listTablesLike: aPattern in: aLens "Answer a collection of tables which are accessible using aLens. If aPattern is not nil, limit the search to only those tables with names matching." | exdiSession tables | exdiSession := aLens connection getSession. tables := (exdiSession listTablesLike: aPattern) collect: [:each | self class tableClass new initializeFrom: each]. tables do: [:each | each columns: ((exdiSession getColumnsOfTable: each name owner: each owner ) collect: [:c | self class tableColumnClass new initializeFrom: c])]. exdiSession dismiss. ^tables
</methods> <methods> DB2LensContext class <category>lens data model specs</category>
catalogDataModelSpec "LensEditor new openOnClass: self andSelector: #catalogDataModelSpec" ^#(#LensDataModel #setDatabaseContext: #(#DB2LensContext #username: '' #environment: '') #structureTypes: #() #lensPolicyName: #Mixed #lensTransactionPolicyName: #PessimisticRR #validity: #installed )
</methods> <methods> DB2LensContext class <category>accessing</category>
connectionClass "Answer the class of connections opened by instances of self." ^DB2Connection
kind "symbol representing the type of the d'ase " ^#DB2
tableClass "Answer the class of tables for the receiver." ^DB2LensTable
tableColumnClass "Answer the class of table columns in receiver's data dictionary." ^DB2LensTableColumn
transporterClass ^DB2LensTransporter
</methods> <methods> DB2LensContext class <category>private</category>
encodedAspects ^#()
</methods> <methods> DB2LensContext class <category>class initialization</category>
initialize "self initialize" self initializeBasicTypes. self initializeDataTypeMappings. maxNameSize := 30. "column name size -30, table name size -128, schema - 18 " maxColumnSize := 2 ** 20 - 1. reservedWords := #(). shortSize := 32700. "for 32K page/ long varchar" transactionPolicies := IdentitySet new. LensCompiler isNil ifFalse: [self initializeCatalogDataModel].
initializeBasicTypes "self initializeBasicTypes" basicTypes := IdentityDictionary new. #(Object SmallInteger Integer LargeInteger Character Float Double ByteArray String Timestamp Date Time Symbol FixedPoint ) do: [ :className | self addBasicType: ((LensDataType new) name: className; memberClass: (className asQualifiedReference valueOrDo: [nil])) ]. self addBasicType: (LensDataType new memberClass: Integer; name: #RowVersion); addBasicType: (LensDataType new memberClass: Integer; name: #SerialNumber); addBasicType: (LensDataType new memberClass: DB2BLOBLocator; name: #BlobLocator); addBasicType: (LensDataType new memberClass: DB2CLOBLocator; name: #ClobLocator); addBasicType: (LensDataType new memberClass: DB2DataLink; name: #Datalink); addBasicType: (LensEncodedType new memberClass: String; name: #TrimString; fieldType: (self typeNamed: #String); encodeSelector: #asString; decodeSelector: #avbTrimBlanks); "addBasicType: (LensEncodedType new memberClass: FixedPoint; name: #ScaledDecimal; fieldType: (self typeNamed: #String); encodeSelector: #avbAsString; decodeSelector: #avbAsFixedPoint);" addBasicType: (LensEncodedType new name: #Boolean; memberClass: Boolean; fieldType: ((self typeNamed: #String) copy maxColumnConstraint: 1); encodeSelector: #printStringForDB2; decodeSelector: #asBooleanForDB2). ^self
initializeDataTypeMappings "self initializeDataTypeMappings" dataTypeMappings := OrderedCollection new. (self mapFieldOf: #String to: #varchar) maxSize: 32672. (self mapFieldOf: #String to: #'long varchar') maxSize: 32700. (self mapFieldOf: #String to: #character) maxSize: 254. (self mapFieldOf: #Boolean to: #character) maxSize: 1. (self mapFieldOf: #TrimString to: #varchar) maxSize: 32672. (self mapFieldOf: #TrimString to: #'long varchar') maxSize: 32700. (self mapFieldOf: #TrimString to: #character) maxSize: 254. (self mapFieldOf: #ClobLocator to: #clob) makeLong. (self mapFieldOf: #BlobLocator to: #blob ) makeLong . (self mapFieldOf: #ByteArray to: #'varchar () for bit data') maxSize: 32672. (self mapFieldOf: #ByteArray to: #'character () for bit data') maxSize: 254. (self mapFieldOf: #ByteArray to: #'long varchar for bit data') maxSize: 32700. self mapFieldOf: #Integer to: #'smallint'. self mapFieldOf: #Integer to: #'integer'. self mapFieldOf: #LargeInteger to: #'bigint'. self mapFieldOf: #SmallInteger to: #'smallint'. self mapFieldOf: #SmallInteger to: #'integer'. self mapFieldOf: #Float to: #'float'. self mapFieldOf: #Double to: #'double'. self mapFieldOf: #SerialNumber to: #'integer'. self mapFieldOf: #Timestamp to: #'timestamp'. self mapFieldOf: #Date to: #'date'. self mapFieldOf: #Time to: #'time'. self mapFieldOf: #FixedPoint to: #'decimal'. self mapFieldOf: #Datalink to: #'datalink'.
</methods> <methods> DB2LensTableColumn <category>accessing</category>
dataType ^dataType asSymbol
dataType: aValue dataType := aValue
isKey ^isKey
isKey: aValue isKey := aValue
isNotNil ^notNil
isNotNil: aValue notNil := aValue
maxColumnConstraint ^maxColumnConstraint
maxColumnConstraint: aValue maxColumnConstraint := aValue
name ^name
name: aValue name := aValue
table ^table
table: aValue table := aValue
type ^type
type: aValue type := aValue
</methods> <methods> DB2LensTableColumn <category>initialize-release</category>
initializeFrom: aDictionary name := aDictionary at: #name. type := DB2CLIInterface fSqlTypeToConversionMap at: (aDictionary at: #type). dataType := (aDictionary at: #nativeType) asLowercase "asSymbol". notNil := ((aDictionary at: #nullable) == 1) not. maxColumnConstraint := (#('character' 'varchar' 'long varchar' 'varchar () for bit data' 'long varchar for bit data' 'character () for bit data' " 'clob' 'blob' ") includes: dataType) ifTrue:[ aDictionary at: #maxLength]. table := aDictionary at: #table.
</methods> <methods> DB2LensTableColumn class <category>accessing</category>
contextClass ^DB2LensContext
</methods> <methods> DB2LensTableColumn class <category>private</category>
encodedAspects ^#(isNotNil dataType name maxColumnConstraint )
</methods> <methods> DB2LensTable <category>comparing</category>
<= aDB2Table "Answer whether aDB2Table collates after the receiver." | so oo | ^(so := self owner) < (oo := aDB2Table owner) or: [ so = oo and: [ self name <= aDB2Table name ] ]
= aDB2Table "Answer whether aDB2Table has the same owner and name as the receiver." ^self species == aDB2Table species and: [ self owner = aDB2Table owner and: [ self name = aDB2Table name ] ]
hash "Modify the hash method to be based on the owner and name combined." ^(self owner hash bitShift: 3) bitXor: self name hash
</methods> <methods> DB2LensTable <category>DDL generation</category>
alterColumnCommand: column operation: operation "Answer a command to add a column to a table." LensSession complain: 'Currently doesn''t supported'
</methods> <methods> DB2LensTable <category>accessing</category>
columns ^columns
columns: aValue columns := aValue
name ^name
name: aValue name := aValue
owner ^owner
owner: aValue owner := aValue
qualify: ldm owner := ldm databaseContext username asUppercase
tableType ^tableType
tableType: aValue tableType := aValue
unqualify owner:=nil
</methods> <methods> DB2LensTable <category>printing</category>
displayString ^self qualifiedName
</methods> <methods> DB2LensTable <category>key detection</category>
getPrimaryKeyIn: aLensSession "Answer the primary key for this table by looking it up in the database catalogs. Answer an instance of LensTableKey or nil." | keys | keys := (aLensSession connection getSession getPrimaryKeysFor: self name owner: self owner) collect: [:s | self columns detect: [:c | c name = s]]. ^keys isEmpty ifFalse: [LensTableKey table: self columns: keys keyType: #primary]
inferReferencesIn: aLensSession | cons res | cons := aLensSession connection getSession getForeignKeysFor: self name owner: self owner. res := OrderedCollection new. [cons size > 0] whileTrue: [| others con | con := cons first. others := SortedCollection sortBlock: [:c1 :c2 | (c1 at: 9) "position" <= (c2 at: 9) "position"]. cons do: [:c | (c at: 12) "constraint" = (con at: 12) "constraint" ifTrue: [others add: c]]. res add: (Array with: self with: (others collect: [ :c | c at: 8 "columnName" ]) with: (Array with: (con at: 3) with: (con at: 2 ) ) "constraint referencedConstraint table tableNameArray"). cons removeAll: others]. ^res
</methods> <methods> DB2LensTable <category>initialize-release</category>
initializeFrom: aDictionary name := aDictionary at: #name. owner := aDictionary at: #owner. tableType := aDictionary at: #tableType.
</methods> <methods> DB2LensTable class <category>accessing</category>
contextClass ^DB2LensContext
</methods> <methods> DB2LensTable class <category>private</category>
encodedAspects ^#(#owner)
</methods> <methods> Core.LargeInteger class <category>type semantics</category>
isVariableSize "Answer whether the receiver has variable-sized members." ^false
</methods> <initialize> DB2LensTransporter </initialize> <initialize> DB2LensContext </initialize> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>LensDatabaseTableColumn</name> <environment>Lens</environment> <super>Lens.LensMetadata</super> <private>false</private> none <imports></imports> <category>Lens-Private-Database Context</category> <attributes> <package>Lens-Runtime</package> </attributes> </class> <class> <name>LensDatabaseTable</name> <environment>Lens</environment> <super>Lens.LensMetadata</super> <private>false</private> none <imports></imports> <category>Lens-Private-Database Context</category> <attributes> <package>Lens-Runtime</package> </attributes> </class> <class> <name>LensSQLTransporter</name> <environment>Lens</environment> <super>Lens.LensBasicTransporter</super> <private>false</private> none selectFieldList whereCondition commandStream command objectSurrogateIndices joinLinks variableIndex numberOfIdVariables itemSurrogate variableBindings functions <imports></imports> <category>Lens-Private-Transporter</category> <attributes> <package>Lens-Runtime</package> </attributes> </class> <class> <name>LensDatabaseContext</name> <environment>Lens</environment> <super>Lens.LensMetadata</super> <private>false</private> none username environment catalogDataModel dataTypeMappings maxColumnSize maxNameSize reservedWords basicTypes shortSize transactionPolicies <imports></imports> <category>Lens-Private-Database Context</category> <attributes> <package>Lens-Runtime</package> </attributes> </class>