loading from view, saving to table (soft delete)

40 views
Skip to first unread message

007design

unread,
May 17, 2012, 11:01:52 AM5/17/12
to ORMLite Users
is there a way that i can specify that a class have it's data loaded
from a view but saved to a table? that is, any query operations would
be run against a view and any insert/update operations would be run
against a table.
i ask as this would enable me to "soft delete" records by marking a
flag column in the table and having a view configured to pull only
records which do not have this flag field. there could perhaps be a
"viewName" property on the @DatabaseTable annotation which, if
supplied, would use that view for read operations.
is this just a silly idea?

thanks,
007

007design

unread,
May 17, 2012, 12:59:26 PM5/17/12
to ORMLite Users
i managed to implement this and it appears to be working. i added a
viewName field to @DatabaseTable which, if specified, is where the
data is read from. if it's not specified it just uses the tableName
field.
anyone see any potential issues with this approach?

thanks,
007

jc

unread,
May 17, 2012, 2:52:46 PM5/17/12
to ORMLite Users
If your database supports updateable views, then why not just include
the flag field in your view and use the view for both reads and
writes? This would still give you the benefit of a view that only
includes non-deleted records for reads and no risk of issues from
swapping the read/write logic within your custom Dao.
Reply all
Reply to author
Forward
0 new messages