-
Notifications
You must be signed in to change notification settings - Fork 4
Refs
Tadeas Kriz edited this page Apr 8, 2014
·
1 revision
class ProxyList<T> extends List<T> {
final Class<T> backingClass;
Map<Long, T> cache = new HashMap<Long, T>();
public ProxyList(Class<T> backingClass, List<Long> ids) {
this.backingClass = backingClass;
for(Long id : ids) {
cache.put(id, null);
}
}
public T get(int i) {
Long id = cache.keySet().get(i);
T cachedObject = cache.get(id);
if(cachedObject == null) {
cachedObject = torch().load().type(backingClass).id(id);
cache.put(id, cachedObject);
}
return cachedObject;
}
}
@Entity
class User {
@Id
Long id;
String name;
UserDetails details;
@Load
List<Email> emails;
List<User> friends;
List<String> test;
User mother;
@Load
User father;
}
// When concrete implementation of List<?> is used, @Load has to be present, otherwise fail in compile time
User
----------------------------------------------------------------------------------------------------------
Long id | String name | Long UserDetails_details_customIdName | Long User_mother_id | Long User_father_id
User__test
-------------------------------------
Long id | Long User_id | String test
User_Email_BindTable
------------------------------------------------
Long id | Long User_id | Long Email
if(@Load is present) {
SELECT User.*, Email.* FROM User WHERE
} else {
}
@Entity
class UserDetails {
@Id
Long customIdName;
String something;
}
UserDetails
----------------------------------------
Long customIdName | String something
@Entity
class Email {
@Id
Long id;
String email;
}
@Entity
class Profile {
@Id
Long id;
}
Development of Torch ORM is sponsored by Brightify