Copyright (c) 2012 Jesse Rosalia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
to deal in the Sof...
If you think the Android project ormada listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.ormada.entity;
/*www.java2s.com*/import org.ormada.reflect.Reflector;
/**
* A wrapper around an Entity class or object, which exposes entity related information
* such as ID.
*
* @author Jesse Rosalia
*
*/publicclass Entity {
//NOTE: this assumes that the default value for a "long" in Java is 0
privatestaticfinalint UNSAVED_ID = 0;
private EntityMetaData metaData;
private Object entity;
public Entity(Reflector reflector, Object entity) {
this.metaData = new EntityMetaData(reflector, entity.getClass());
this.entity = entity;
}
publiclong getId() {
try {
return (Long) metaData.getIdGetter().invoke(this.entity);
} catch (Exception e) {
thrownew RuntimeException(e);
}
}
publicvoid setId(long id) {
try {
metaData.getIdSetter().invoke(this.entity, id);
} catch (Exception e) {
thrownew RuntimeException(e);
}
}
publicboolean isSaved() {
return getId() != UNSAVED_ID;
}
publicstaticboolean isSaved(long id) {
return id != UNSAVED_ID;
}
}