android - Custom ID generation with OrmLite -
i'm working on android app has it's own way generate unique identifiers entities.
before every entity creation assign new id our objects. we're doing that:
idgenerator.assigncodefor(entity); dao.create(entity);
i know ormlite has sort of generateid id scheme, seems feature designed working database sequences(eg: postgresql serial datatype , mysql's auto_increment).
i looked customized datapersister, came sort of workarround don't feel confortable with.
tldr;
so question is: how can programmatically generate custom id entities ormlite?
i'm looking interceptor or strategy pattern.
how can programmatically generate custom id entities ormlite?
i think example code doing it, right? question is:
how can have ormlite custom generate id entities.
the short answer doesn't have way this. ormlite not generating id, database is. however, there ways can better in own code.
i'd extend dao , override
dao.create(...)
method assigns id entity , callssuper.create(...)
.id
field@databasefield(id = true)
, notgeneratedid = true
.you use
getid()
,setid(...)
method , useusegetset = true
on entity field. inside ofgetid()
in entity, test if id fieldnull
, generation of id value @ moment. when ormlite interrogating object set id field on entity, generated , inserted database.you have utility class and/or method created entities you. doesn't unless remember use of time of course.
could id creation in entity constructor? suspect no thought i'd add consideration.
Comments
Post a Comment