270 likes | 419 Views
Incremental Checking of OCL Constraints through SQL queries. Xavier Oriol and Ernest Teniente {xoriol,teniente}@essi.upc.edu. Motivation. IsSentTo. 1. receiver. {disjoint, complete}. Group. User. Message. Pair. ConversationGroup. phone: String state: String lastConnect : Date.
E N D
Incremental Checking of OCL Constraints through SQL queries Xavier Oriol andErnest Teniente {xoriol,teniente}@essi.upc.edu
Motivation IsSentTo 1 receiver {disjoint, complete} Group User Message Pair ConversationGroup phone: String state: String lastConnect: Date body: String creationT: Date creationT: Date * IsFormedBy 2 msg * Member 2..* * group user Sends 1 * Owner * 1 sender msg owned owner
Motivation IsSentTo 1 receiver {disjoint, complete} ConversationGroup Pair Group User Message phone: String state: String lastConnect: Date body: String creationT: Date creationT: Date * IsFormedBy 2 msg * Member 2..* * group user Sends 1 * Owner * 1 sender msg owned owner contextUserinvMemberOfOwned: self.group->includesAll(self.owned)
Motivation IsSentTo 1 receiver {disjoint, complete} Message Group User ConversationGroup Pair phone: String state: String lastConnect: Date body: String creationT: Date creationT: Date * IsFormedBy 2 msg * Member 2..* * group user Sends 1 * Owner * 1 sender msg owned owner contextUserinvMemberOfOwned: self.group->includesAll(self.owned) context Group invMessagesAfterCreation: self.msg->forAll(e| e.creationT > self.creationT)
Motivation contextUserinvMemberOfOwned: self.group->includesAll(self.owned) context Group invMessagesAfterCreation: self.msg->forAll(e| e.creationT > self.creationT)
Motivation How can wecheck OCL constraints? contextUserinvMemberOfOwned: self.group->includesAll(self.owned) context Group invMessagesAfterCreation: self.msg->forAll(e| e.creationT > self.creationT) Translating OCL constraints to SQL queries Idea: Query for theinstancesviolatingtheconstraint SELECT * FROM Group JOINIsSentToJOINMessage WHERE Group.createT>=Message.creationT
Motivation There are some automatic OCL to SQL translators: • OCL2SQL fromOCLDresden • MySQL4OCL None of them is incremental
Motivation IsSentTo 1 SELECT * FROM OwnerEXCEPTMember receiver {disjoint, complete} SELECT * FROM Group JOINIsSentToJOINMessage WHERE Group.createT<=Message.creationT ConversationGroup Message Pair User Group phone: String state: String lastConn: Date body: String creationT: Date creationT: Date * IsFormedBy 2 msg * 2..* Member * Hello! group user Sends 1 * Owner 1 * sender msg owned owner INSERT INTO Messages VALUES(‘Hello!’, ...) DATA Weneed to computethewholequeriesagain
Our approach Goal Translate OCL constraintsinto incremental SQL queries
Our approach Incremental Onlycheckthepotentiallyviolatedconstraints contextUserinvMemberOfOwned: self.group->includesAll(self.owned) context Group invMessagesAfterCreation: self.msg->forAll(e| e.creationT > self.creationT) Hello! New Message Onlycheck for thenewupdatedvalues Onlycheckwhetherthenewmessage “Hello!” has beencreatedafterthereceiver’sgroupcreation
Our approach Ourapproach Translate OCL constraintsintoEDCs andEDCs to incremental SQL queries
Our approach Translate OCL intoEDCs An EDC is a logicrulethat tells when a data update maycausetheviolation of someintegrityconstraint contextUserinvMemberOfOwned: self.group->includesAll(self.owned) ¬Owner(u, g) ∧ins_Owner(u, g) ∧ ¬Member(u, g) ∧ ¬ins_Member(u,g) → ⏊ ¬Owner(u, g) ∧ ins_Owner(u, g) ∧ Member(u, g) ∧ del_Member(u,g) → ⏊ Owner(u, g) ∧ ¬del_Owner(u, g) ∧ Member(u, g) ∧ del_Member(u,g) → ⏊
Our approach TranslateEDCsinto SQL Idea: Jointhecolumns of thebound variables ins_Owner(u, g) ∧ ¬Owner(u, g) ∧ Member(u, g) ∧del_Member(u,g) → ⏊ SELECT * FROM ins_Owner ANTI JOINOwnerON (user,group) JOINMemberON (user,group) JOINdel_MemberON (user,group)
Our approach TranslateEDCsinto SQL SELECT * FROM ins_Owner ANTI JOINOwnerON (user,group) JOINMemberON (user,group) JOINdel_MemberON (user,group)
Our approach contextUserinvMemberOfOwned: self.group->includesAll(self.owned) TranslateEDCsinto SQL SELECT * FROM ins_Owner ANTI JOINOwnerON (user,group) JOINMemberON (user,group) JOINdel_MemberON (user,group) Hello! Thetranslationnever uses subqueries DBMS queryplanners can fullyoptimizethequery New Message Queryreturns empty set practically in constant time || ins_Owner || = 0
Our approach context Group invMssgsAfterCreation: self.msg->forAll(e| e.cT > self.cT) TranslateEDCsinto SQL SELECT * FROM Group ANTI JOINdel_GroupON (group) JOINins_SendsToON (group) ANTI JOIN SendsTo ON (group) JOIN ins_Message ON (message) ANTI JOIN Message ON (message) WHERE Group.creationT>=ins_Message.creationT Hello! New Message Queryonlylooks for data joiningtheuniquenewmessage || ins_Message || = 1
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Our approach Someexperiments N = #Messages N/10 = #Users N/100 = #ins_Messages MemberOfOwned MsgsAfterCreation
Conclusions Wetranslate OCL into incremental SQL Translatefrom OCL to EDCs TranslatefromEDCs to SQL Ourtranslation is incremental Whenanupdate is performed: Onlyconstraintsthatmight be violatedarechecked Only for the rellevant values FutureWork Enhancethesubset of OCL translatable to EDCs Usetriggers to avoid auxiliar tables
Thank you Questions?
Incremental Checking of OCL Constraints through SQL queries Xavier Oriol andErnest Teniente {xoriol,teniente}@essi.upc.edu