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.

  1. i'd extend dao , override dao.create(...) method assigns id entity , calls super.create(...). id field @databasefield(id = true) , not generatedid = true.

  2. you use getid() , setid(...) method , use usegetset = true on entity field. inside of getid() in entity, test if id field null , generation of id value @ moment. when ormlite interrogating object set id field on entity, generated , inserted database.

  3. you have utility class and/or method created entities you. doesn't unless remember use of time of course.

  4. could id creation in entity constructor? suspect no thought i'd add consideration.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -