java - Suggestions on solving a JPA persistence issue -
i'm building persistence tester. project responsible creating , populating (with random values) other object might have. object (obj1) persisted in db , read , stored (obj2), i'll compare them (obj1 == obj2). test if data persisted correctly. (up point simple objects, working)
however, since i'm populating objects random values have problem because id's random... makes impossible persist because fk's aren't corresponding id's.
to fix this, thinking of building factory each object (and there lot of objects) , save id's later, when persisting id value , use accordingly. have no guarantee work, guys think so?
have guys had kind of problem? how did solved it? have other suggestions? appreciated.
thanks
tl;dr: first approach process textual description of whatever dependency constraints need data conform testing script or script-driving data. generate data in required order.
a "test" seems example persistence api client: has runtime state based on declarations in language in call persistence api; emulates multiple persistence calls of typical client. such runtime state of typical api client involve kind of dependencies between objects. since refer fks, presumably clients emulating have @ least part of state involved orm.
those orm declarations involve fk , other constraints. may have description of same information, database ddl or database runtime metadata, either generated or generates declarations. maybe such info part of persistence api. don't make clear. dbms form info more have dependencies explicit.
process declaration or ddl or metadata query output text extract relevant declaration parts. eg awk, sed, grep. produce dependency graph nodes object class + fields pairs , directed edge dependent class + fields pair. (a fk class + set-of-fields class + set-of-fields keys might overlap unit of dependency field.) find partial ordering of these. may able put edges in database table , transitive closure and/or partial ordering query. or find library this. (eg jgrapht library.) declarations may required in such order. generate data in order of increasing dependency. might repeatedly generate groups of dependent objects start over. of course should automated.
(more generally: in orm table of set of objects forming tree representing ordered list there fk next field oid field. tiny part of overall constraint (called representation invariant) if follow next references form tree! maybe sorted or balance one! when walked produces ordered list! 1 described calls built tree! presumably persistence-tester requirements state sort of properties test client data/objects/state should have. maybe ormish stuff. eg pks, unique, fks, through:. maybe fks.)
(be sure set test project can regression test api , tester. eg store seeds. , although might not able store example generated data can check sum , parts tables can check same previous times.)
(beware of random test data. know expected input-output relation. involved in project multi-million-dollar bug (not mine!) using random test data.)
Comments
Post a Comment