[ZODB-Dev] AdaptableStorage and OR mapping strategy (was: AdaptableStorage
and ZClass instances)
Shane Hathaway
shane@zope.com
Tue, 25 Feb 2003 16:18:19 -0500
Roch=E9 Compaan wrote:
> I have started rewriting SQLGatewayBase to do more work. So far it's
> going well but I wanted to bounce some ideas off you wrt the state that
> the load method should return.
>=20
> Here's my thinking at the moment:
>=20
> If the schema is of type FieldSchema then the state returned should
> be a single value eg.:
>=20
> items =3D self.execute(self.readsql(key))
> if items:
> state =3D items[0][0]
> else:
> state =3D ''
> return state, state
>=20
> If the schema is of type RowSchema then the state returned should b=
e
> a sequence and we assert that a single row is returned:
>=20
> items =3D self.execute(self.readsql(key))
> if items:
> assert len(items) =3D 1
> state =3D items[0]
> else:
> state =3D ''
> return state, state
>=20
> If the schema is of type RowSequenceSchema then the state returned
> should be a sequence:
>=20
> items =3D self.execute(self.readsql(key))
> if items:
> state =3D items
> # to ensure a hash of the state stays the same
> state.sort()
> else:
> state =3D []
> return state, tuple(state)
Right on. In the last case, it returns a sequence of tuples. The=20
store() method follows the same rules.
> If a subclass needs to do something special when computing state it can
> simply override the load method.
Right.
I originally decided that all gateways would load and store tuples of=20
tuples, but that quickly became cumbersome and error-prone. So although=20
you now have to code for three cases instead of one, it's worth the=20
complexity. :-)
Shane