jonatasdaniel / andorm

Persistence framework for Android
23 stars 4 forks source link

@Type #40

Open mcasasola opened 13 years ago

mcasasola commented 13 years ago

Could implement @Type, same as hibernate. Class to convert cursor result to object.

jonatasdaniel commented 13 years ago

A Custom formatter specified to an attr solve the problem?

mcasasola commented 13 years ago

thats the idea.

jonatasdaniel commented 13 years ago

If you look at the sources, we have a class DateFormatter, implementing the interface Formatter. Then create a property called 'formatter' would receive a class that extends Formatter.

mcasasola commented 13 years ago

Don't figureted, i see Formatter property but where use it?

jonatasdaniel commented 13 years ago

Maybe in Property class. I'll prepare an example next week.

mcasasola commented 13 years ago

ok, maybe annotated attr and automagically apply formatter, transparently. Without touch property.

jonatasdaniel commented 13 years ago

I think something like this:

MyProperty {

public void set(Object in, Object value) { value = myCustomFormatter.parse(value); invoke(in, setMethod).withParams(value); }

public Object get(Object of) { object value = invoke(of, getMethod).withoutParams(); return myCustomFormatter.format(value); }

}

mcasasola commented 13 years ago

But properties are create by framework, how you make relation of entities that requiere formatter and property create in manager initialization?

jonatasdaniel commented 13 years ago

The format would be an attribute of the property, and if the entity attribute is not annotated with @Column, a standard format and defined

mcasasola commented 13 years ago

With a attr in @Column you defined a formatter implementation?

jonatasdaniel commented 13 years ago

Something like this:

@Column(formatter=MyCustomFormatter.class) private Integer myAttr;

mcasasola commented 13 years ago

ok, i like that way. great.