is it bug with orderBy+writeTheOrderField or my fault ??

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

is it bug with orderBy+writeTheOrderField or my fault ??

Micael Alastor
I'm using VW7.7 with builtin glorp.

I have ManyToMany relationship between AosPlan and AosSubject objects:

descriptorForAosPlan: aDescriptor

| table |
table := self tableNamed: 'AOSPLAN'.
aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #id to: (table fieldNamed: 'ID').
(aDescriptor newMapping: DirectMapping) from: #name to: (table fieldNamed: 'NAME').
(aDescriptor newMapping: ManyToManyMapping)
attributeName: #subjects;
referenceClass: AosSubject;
collectionType: OrderedCollection;
orderBy: [:each | (each getTable: 'AOSPLAN_AOSTREEELEMENT') getField: 'SUBJ_POSITION'];
writeTheOrderField.


descriptorForAosSubject: aDescriptor

| directoryField table |
table := self tableNamed: 'AOSTREEELEMENT'.
aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #id to: (table fieldNamed: 'ID').
(aDescriptor newMapping: DirectMapping) from: #name to: (table fieldNamed: 'NAME').
(aDescriptor newMapping: ManyToManyMapping)
attributeName: #plans;
referenceClass: AosPlan

tableForAOSPLAN: aTable

(aTable createFieldNamed: 'ID' type: (platform varchar: 36)) bePrimaryKey.
aTable createFieldNamed: 'NAME' type: (platform varchar: 500).

tableForAOSTREEELEMENT: aTable

(aTable createFieldNamed: 'ID' type: (platform varchar: 36)) bePrimaryKey.
aTable createFieldNamed: 'NAME' type: (platform varchar: 500).



tableForAOSPLAN_AOSTREEELEMENT: aTable

| plan subject |
plan := aTable createFieldNamed: 'PLANID' type: (platform varchar: 36).
aTable addForeignKeyFrom: plan to: ((self tableNamed: 'AOSPLAN') fieldNamed: 'ID').
subject := aTable createFieldNamed: 'SUBJECTID' type: (platform varchar: 36).
aTable addForeignKeyFrom: subject to: ((self tableNamed: 'AOSTREEELEMENT') fieldNamed: 'ID').
aTable createFieldNamed: 'SUBJ_POSITION' type: platform int4



I just want to reorder collection of AosSubject in AosPlan in UnitOfWork using #swap or smth similar.

In case of 2 AosSubject's in 1 AosPlan: instead of updating 2 link table rows glorp creates 2 new rows and not deletes 2 old.

After some digging I think the problem is in following code:

additiveDifferencesFrom: aRowMap into: differencesMap
"Add everything which is in us, but not in aRowMap into differencesMap"
| newRow |
self objectsAndRowsDo: [:object :row |
| correspondingRow |
correspondingRow := aRowMap
rowForTable: row table
withKey: object
ifAbsent: [DatabaseRow new].
(row equals: correspondingRow)
ifFalse:
[newRow := differencesMap
addRow: (row withAllFieldsIn: correspondingRow)
forTable: row table
withKey: object.
newRow forDeletion: row forDeletion]].



subtractiveDifferencesFrom: aRowMap into: differencesMap
"Figure out which things are in aRowMap but not in us. These should be flagged as delete rows. Since we have no further use for aRowMap after this, we can compute this destructively by removing everything that's in us"

self objectsAndRowsDo: [:object :row |
aRowMap
deleteRowForTable: row table
withKey: object
ifAbsent: []].
aRowMap
objectsAndRowsDo:
[:object :row | 
| adjustedObject |
adjustedObject := (aRowMap reverseLookup: object).
row forDeletion: true.
differencesMap
addRow: row
forTable: row table
withKey: adjustedObject].

With writed by glorp orderField this test  (row equals: correspondingRow)  failed after reordering => we have 2 new additive difference, but when we execute 
#subtractiveDifferencesFrom:into:   we have no subtractive differences because of this code: 

aRowMap
deleteRowForTable: row table
withKey: object
ifAbsent: []

Primitive solution like:

subtractiveDifferencesFrom: aRowMap into: differencesMap
self objectsAndRowsDo: 
[:object :row |
| correspondingRow |
correspondingRow := aRowMap
rowForTable: row table
withKey: object
ifAbsent: [DatabaseRow new].
(row equals: correspondingRow)
ifTrue: 
[aRowMap
deleteRowForTable: row table
withKey: object
ifAbsent: []]].
aRowMap objectsAndRowsDo: 
[:object :row |
| adjustedObject |
adjustedObject := aRowMap reverseLookup: object.
row forDeletion: true.
differencesMap
addRow: row
forTable: row table
withKey: adjustedObject]

is useless because we can't add 2 RowMapKey's with similar key1 and key2 to difference map.




--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/glorp-group/-/yiuJcYPhM-wJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: is it bug with orderBy+writeTheOrderField or my fault ??

Alan Knight-2
On first examination, it does look like this is a bug. I definitely get the same type of symptom, and this is something that is (oops) not exercised in the test suite. I haven't looked into the details of the reasons yet, but I can confirm it looks like a bug.



[hidden email]
9 August, 2011 9:45 AM


I'm using VW7.7 with builtin glorp.

I have ManyToMany relationship between AosPlan and AosSubject objects:

descriptorForAosPlan: aDescriptor

| table |
table := self tableNamed: 'AOSPLAN'.
aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #id to: (table fieldNamed: 'ID').
(aDescriptor newMapping: DirectMapping) from: #name to: (table fieldNamed: 'NAME').
(aDescriptor newMapping: ManyToManyMapping)
attributeName: #subjects;
referenceClass: AosSubject;
collectionType: OrderedCollection;
orderBy: [:each | (each getTable: 'AOSPLAN_AOSTREEELEMENT') getField: 'SUBJ_POSITION'];
writeTheOrderField.


descriptorForAosSubject: aDescriptor

| directoryField table |
table := self tableNamed: 'AOSTREEELEMENT'.
aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #id to: (table fieldNamed: 'ID').
(aDescriptor newMapping: DirectMapping) from: #name to: (table fieldNamed: 'NAME').
(aDescriptor newMapping: ManyToManyMapping)
attributeName: #plans;
referenceClass: AosPlan

tableForAOSPLAN: aTable

(aTable createFieldNamed: 'ID' type: (platform varchar: 36)) bePrimaryKey.
aTable createFieldNamed: 'NAME' type: (platform varchar: 500).

tableForAOSTREEELEMENT: aTable

(aTable createFieldNamed: 'ID' type: (platform varchar: 36)) bePrimaryKey.
aTable createFieldNamed: 'NAME' type: (platform varchar: 500).



tableForAOSPLAN_AOSTREEELEMENT: aTable

| plan subject |
plan := aTable createFieldNamed: 'PLANID' type: (platform varchar: 36).
aTable addForeignKeyFrom: plan to: ((self tableNamed: 'AOSPLAN') fieldNamed: 'ID').
subject := aTable createFieldNamed: 'SUBJECTID' type: (platform varchar: 36).
aTable addForeignKeyFrom: subject to: ((self tableNamed: 'AOSTREEELEMENT') fieldNamed: 'ID').
aTable createFieldNamed: 'SUBJ_POSITION' type: platform int4



I just want to reorder collection of AosSubject in AosPlan in UnitOfWork using #swap or smth similar.

In case of 2 AosSubject's in 1 AosPlan: instead of updating 2 link table rows glorp creates 2 new rows and not deletes 2 old.

After some digging I think the problem is in following code:

additiveDifferencesFrom: aRowMap into: differencesMap
"Add everything which is in us, but not in aRowMap into differencesMap"
| newRow |
self objectsAndRowsDo: [:object :row |
| correspondingRow |
correspondingRow := aRowMap
rowForTable: row table
withKey: object
ifAbsent: [DatabaseRow new].
(row equals: correspondingRow)
ifFalse:
[newRow := differencesMap
addRow: (row withAllFieldsIn: correspondingRow)
forTable: row table
withKey: object.
newRow forDeletion: row forDeletion]].



subtractiveDifferencesFrom: aRowMap into: differencesMap
"Figure out which things are in aRowMap but not in us. These should be flagged as delete rows. Since we have no further use for aRowMap after this, we can compute this destructively by removing everything that's in us"

self objectsAndRowsDo: [:object :row |
aRowMap
deleteRowForTable: row table
withKey: object
ifAbsent: []].
aRowMap
objectsAndRowsDo:
[:object :row | 
| adjustedObject |
adjustedObject := (aRowMap reverseLookup: object).
row forDeletion: true.
differencesMap
addRow: row
forTable: row table
withKey: adjustedObject].

With writed by glorp orderField this test  (row equals: correspondingRow)  failed after reordering => we have 2 new additive difference, but when we execute 
#subtractiveDifferencesFrom:into:   we have no subtractive differences because of this code: 

aRowMap
deleteRowForTable: row table
withKey: object
ifAbsent: []

Primitive solution like:

subtractiveDifferencesFrom: aRowMap into: differencesMap
self objectsAndRowsDo: 
[:object :row |
| correspondingRow |
correspondingRow := aRowMap
rowForTable: row table
withKey: object
ifAbsent: [DatabaseRow new].
(row equals: correspondingRow)
ifTrue: 
[aRowMap
deleteRowForTable: row table
withKey: object
ifAbsent: []]].
aRowMap objectsAndRowsDo: 
[:object :row |
| adjustedObject |
adjustedObject := aRowMap reverseLookup: object.
row forDeletion: true.
differencesMap
addRow: row
forTable: row table
withKey: adjustedObject]

is useless because we can't add 2 RowMapKey's with similar key1 and key2 to difference map.




--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/glorp-group/-/yiuJcYPhM-wJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.