OCL に変換したい SQL があります。SQLが苦手なのでこれでメンテナンス性を上げたい。Interbase 2009、Delphi 2007 を Bold およびモデル駆動型開発で使用しています。ここで誰かが SQL と OCL の両方を上手に話せることを願っています :-) 元の SQL:
Select Bold_Id, MessageId, ScaniaId, MessageType, MessageTime, Cancellation, ChassieNumber, UserFriendlyFormat, ReceivingOwner, Invalidated, InvalidationReason,
(Select Parcel.MCurrentStates From Parcel
Where ScaniaEdiSolMessage.ReceivingOwner = Parcel.Bold_Id) as ParcelState From ScaniaEdiSolMessage
Where MessageType = 'IFTMBP' and
not Exists (Select * From ScaniaEdiSolMessage EdiSolMsg
Where EdiSolMsg.ChassieNumber = ScaniaEdiSolMessage.ChassieNumber and EdiSolMsg.ShipFromFinland = ScaniaEdiSolMessage.ShipFromFinland and EdiSolMsg.MessageType = 'IFTMBF') and
invalidated = 0 Order By MessageTime desc
少し単純化した後:
Select Bold_Id, (Select Parcel.MCurrentStates From Parcel
where ScaniaEdiSolMessage.ReceivingOwner = Parcel.Bold_Id) From ScaniaEdiSolMessage
Where MessageType = 'IFTMBP' and not Exists (Select * From ScaniaEdiSolMessage
EdiSolMsg Where EdiSolMsg.ChassieNumber = ScaniaEdiSolMessage.ChassieNumber and
EdiSolMsg.ShipFromFinland = ScaniaEdiSolMessage.ShipFromFinland and
EdiSolMsg.MessageType = 'IFTMBF') and invalidated = 0
注: MessageType には、'IFTMBP' と 'IFTMBF' の 2 つのケースがあります。
したがって、リストされるテーブルは ScaniaEdiSolMessage です。次のような属性があります。
- MessageType: 文字列
- ChassiNumber: 文字列
- ShipFromFinland: ブール値
- 無効: ブール値
また、BoldId をキーとして RecomingOwner という名前のテーブル Parcel へのリンクもあります。
そのため、ScaniaEdiSolMessage のすべての行を一覧表示し、さらに ScaniaEdiSolMessage のすべての行を一覧表示して EdiSolMsg という名前のサブクエリを持っているようです。次に、ほぼすべての行を除外します。実際、上記のクエリは 28000 レコードから 1 つのヒットを返します。
OCL では、すべてのインスタンスを簡単にリストできます。
ScaniaEdiSolMessage.allinstances
たとえば、選択して行を簡単にフィルタリングすることもできます。
ScaniaEdiSolMessage.allinstances->select(shipFromFinland and not invalidated)
しかし、上記の SQL に一致する OCL を作成する方法がわかりません。