370 likes | 466 Views
Refactoring Information Systems. Michael Löwe, FHDW Hannover Oldenburg, January 9, 2007. Contents. Motivating Example State-of-the-Art in (German) Industry Abstract Graph Model Refactorisations and Migrations From Pullback-Complements to Abstract Foldings Formal Treatment of the Examples
E N D
Refactoring Information Systems Michael Löwe, FHDW Hannover Oldenburg, January 9, 2007
Contents Motivating Example State-of-the-Art in (German) Industry Abstract Graph Model Refactorisations and Migrations From Pullback-Complements to Abstract Foldings Formal Treatment of the Examples Sequential Composition Further Research and Development Oldenburg
Refactoring Information Systems Information Systems Refactoring
inAcc. partner BankAcc. inAcc. outAcc. partner * Contract Role Claim Person Claim Contract outAcc. * Address claimant claimant Refactoring Example • Splitting Classes(for example: Person >>> Person / Role) • Redirecting Associations(for example: partner : Person >>> Role) Oldenburg
partner Person Role Partner Claimant {abs} * inAcc. Contract inAcc. partner BankAcc. outAcc. * Claim Address claimant outAcc. claimant Refactoring Example (cont.) • Introducing Inheritance(for example: Role >>> Partner/Claimant) • Redirecting Associations(for example: inAcc and outAcc) Oldenburg
Claimant Partner account inAcc. outAcc. Refactoring Example (cont.) Person * Role BankAcc. {abs} partner * Contract Address Claim claimant • Shifting Associations(for example: up the inheritance hierarchy) • Abstracting Associations(for ex.: inAcc and outAcc into account) Oldenburg
Partner PostalAddr. E-Mail Refactoring Example (cont.) Person * account Role BankAcc. {abs} * Address partner Contract Claimant Claim claimant • Splitting Classes(for example: Address >>> Address/PostalAddress) • Adding Classes and Associations (for example.: E-Mail) Oldenburg
Person Role Claimant Partner {abs} * account BankAcc. PostalAddr. Contract E-Mail partner partner Role * Address Claim claimant Refactoring Example (cont.) • Removing Classes and Associations (for example: Claim, Claimant) • Gluing Classes (for example: Partner/Role >>> Role) Oldenburg
Refactoring Information Systems Information Systems Refactoring
partner inAcc partner BankAcc. inAcc outAcc * Claim Contract Role Contract Person Claim outAcc * Address claimant claimant :inAcc :partner :Role :BankAcc. :Person :Contract :BankAcc. :outAcc Information System Example :inAcc :partner :BankAcc. :Person :Contract :outAcc :BankAcc. Oldenburg
* partner Person Role Claimant Partner {abs} * * inAcc. Contract inAcc. partner BankAcc. * outAcc. * Claim Address * outAcc. claimant claimant :BankAcc. :BankAcc. :Person :Person :Role :Role :Contract :Clai. :Partner :Contract :partner :outAcc :BankAcc. :inAcc Informations Sys. Example (cont.) :outAcc :partner :Role :inAcc :BankAcc. Oldenburg
Person * Role BankAcc. Partner Claimant {abs} account partner * Contract Address inAcc. Claim claimant outAcc. :BankAcc. :BankAcc. :Person :Person :Contract :Clai. :Partner :Role :Clai. :Contract :Role :Role :Partner :Role :account :partner :BankAcc. :account Informations Sys. Example (cont.) :partner :outAcc :BankAcc. :inAcc Oldenburg
Partner E-Mail PostalAddr. : PostalAddr. :PostalAddr. :Address :Address :Person :Person :Address :Address :Address : PostalAddr. :Address Informations Sys. Example (cont.) Person * account Role BankAcc. {abs} * Address partner Contract Claimant Claim claimant Oldenburg
Person Role Claimant Partner {abs} * account BankAcc. E-Mail PostalAddr. Contract partner partner Role * Address Claim claimant :Role :Partner :BankAcc :Person :Role :Role :Contract :Claim :Claimant :Person Informations Sys. Example (cont.) Oldenburg
Summary Refactoring Semantics preserving change of system structures Information Systems Software Systems with (huge) Databases Refactoring Information Systems Semantics preserving change of a system structure together with the structure of the existing data (Agile Database Development, Agile Maintenance, ...) Oldenburg
Comparable Situations Class Model and Object World Meta-Model and Model Instances Database Schema and Database Tables XML-Schema and XML-Documents Business Process Models and (Running) Processes Programms and (Running) Threads (Software-) Products and (Sold) Instances ...... Oldenburg
Current Situation Tactics in the running system: Don‘t touch the data! • Changes above the persistence level only • Usage of mapping tools (z. B. Hibernate) • Sometimes reinterpretation of the data in the old model (usage of comment fields, change of field types, several information encode in same field, ...) Strategy for new Systems: Hand-Programmed Migration • Complete migration of data from the old to the new application • Cost: 1/3 Development, 1/3 Migration und 1/3 Introduction & Teaching • Production break Quality of data structures worse than expected, development cost higher than expected Oldenburg
System: V1 System: V1 System: V2 System: V2 System: V3 System: V3 System: V4 System: V4 Database 1 Database 1 Database 3 Delta 2 Delta 3 Agile DB-Development Database 2 Meta-Model Oldenburg
What do we need? Adding Classes and Associations Deleting Classes and Associations Splitting Classes and Associations (copy) Gluing Classes and Associations Redirecting and Distributing Associations Oldenburg
Partner Claimant Role Role Meta-Model Graphs „live“ in the algebraic categorie: Sorts : Object Opns : source, target: Object → Object . A Model M is a Graph. A (typed) Database is a morphisms i: I M {abs} Oldenburg
Person * acc. BankAcc. Claimant Partner {abs} Role partner * Contract Address Claim clai. b1 p5 c2 b2 p1 p3 c1 p2 a1 a2 o1 o2 p4 Model and Database Oldenburg
le ri M R N i x j (PB) (PB) I X J le' ri' Refactorisation A Refactorisation is a pair: (le:R M, ri:R N), that deletes objects not in the image of le, adds nothing (!!!) (Defaults ???), renames preserved objects along le and ri, splits objects with several preimages under le, glues objects that are identified by ri. A Migration of a typed database along a Refactorisation (le: R M, ri: R N): Oldenburg
Pullback-Complement • (g, f1*) PB of (f, g1*), • (g, f2*) PB of (f, g2*), and • D1* D2* implies • (g, f) without unique PBC • ----------------------------------- • But: f is surjective • compare: • Meisen 1973 • Bauderon 2001 Oldenburg
„Archaic“ Form f 12 1234 i1 ::= 13 14, 24 23 i2 ::= 13 23, 24 14 ----------------------------- i1 f2* f1* i2 f2* f1* 34 g2* g g1* 13 f2* 24 1 2 3 f1* 4 14 23 Oldenburg
1 a 1,2,a b 2 b c c 3 g: G G d 3,4,5,d,e 4 5 e g f,g f 6 6,7,8,h h 7 8 Component-Graphs CG (Component-)Graph ::= g: G G(g generates components on G) Morphisms ::= t : (i: I I) (m: M M) = (t: I M, t: I M) with t i = m t Model ::= (Component) Graph m: M M Database ::= (Component Graph) Morphisms t: i m Such that t is bijective on i-1(p) to m-1(t(p)) for all p I. Refactorisation ::= (l: k m, r: k n) Such that l and r injective. Refactorisations are injective where databases are not and vice versa Oldenburg
l r m k n t w v (PB) (PB) i x j l' r' CG-Migration • Migration : Double-Pullback, such that vis Database ! • Pullbacks preserve Databases! • Let x be short for x : X X! • r‘ ::= idX; J = X • v ::= rw • ::= ker(x) ker (r w) • J = X| • r‘ ::= • j and v as diagram completions, since ker(r w) and ker(x) Oldenburg
Model Instance Class A objA:A objA:A objA:A Class B Class C Class D objB:B objC:C objC:C objD:D Class E Class F objE:E objF:F Inheritance Partial Components Oldenburg
Pullback Complement Defect • Morphisms f and g are given. • g* f* = f g implies, that there is a node 1 with: • f*(1) = 1 and • g*(1) = 3 • f(1) = f(2) = g*(1) and (g, f*) pullback of (f, g*) implies: • Pullback contains at least 2 elements • No pullback complement !!! PB Oldenburg
f a b v w g c d a x t u y b (Abstract) Folding • A database v:c a satisfies: c(x) = c(y) v(x) = v(y) x = y • The pair(w, g) is Folding of database v • and refactorisation f, if • w is database, • w g = f v, • (g, g) is epimorphism, and • g = kern(f v) kern(c). • It is Abstract Folding, if for all • (a: c x, b: c y, t: y x), such that • t is database and a f v = t b, • there is unique u: d y with • (1) u g = b und (2) t u = a w. f a b v w g c d Oldenburg
l r m k n t w v (PB) (AF) i x j l' r' Results Foldings are abstract Foldings. Abstract Foldings are unique up to isomorphism. Abstract Foldings • can be composed and • decomposed as pushouts. A refactorisation induces an unique migration, if • left side is pullback and • right side is abstract Folding. Oldenburg
partner BankAcc. BankAcc. * Person Claim Contract Claim Role Person Contract * Address claimant Formalized Examples inAcc. outAcc. Left: inAcc. partner outAcc. * Middle: * ID Address claimant Right: Oldenburg
Formalized Examples Shift of Associations Left Middle Right inAcc Role Role Role inAcc HELPER inAcc Partner Partner Partner Oldenburg
Formalized Examples Cloning of Objects Left Middle Right claimant claimant partner partner partner claimant Role Role Role Role Role Partner Claimant Partner Claimant person person outAcc person outAcc person outAcc inAcc inAcc inAcc Oldenburg
Sequential Composition The sequential composition (l1, r1) (l2, r2) = (l1 l2‘, r2 r1‘) is given by the pullback of r1 and l2. The sequential composition is well-defined, since pullbacks preserve refactorisation-morphisms. Oldenburg
R2(R1(t)) = R2 R1(t) Oldenburg
Additional Results All constructions work for arbitrary refactorisations. (Non-injective component mapping. Already used in the examples above!) The database property is preserved by pullbacks. The (abstr.) folding along refactorisation r: K R is a free construction wrt. the pullback functor P: DR DK from the R-typed databases to the K-typed databases. It is the composition of the (trivial) free construction wrt. the pullback functor and the free construction from all arrows under R into the subcategory of all databases under R. A whole migration step is a single free construction. Oldenburg
Current Work More practical examples Providing constructions for default values (null) Finding atomic refactorisation steps for Decomposition of refactorisations Parallel execution of refactorisations Development of a prototype system (meta model) Checking practical examples Migration-on-demand Transformations into concrete RDBMS (Oracle) Schema extraction Trigger and Stored Procedures for lazy migration Migration of the behaviour given by graph transformations Oldenburg