mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
cache the "tree"
This commit is contained in:
29
src/main/java/com/commafeed/backend/model/Models.java
Normal file
29
src/main/java/com/commafeed/backend/model/Models.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.commafeed.backend.model;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
|
||||
public class Models {
|
||||
|
||||
/**
|
||||
* initialize a proxy
|
||||
*/
|
||||
public static void initialize(Object proxy) throws HibernateException {
|
||||
Hibernate.initialize(proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* extract the id from the proxy without initializing it
|
||||
*/
|
||||
public static Long getId(AbstractModel model) {
|
||||
if (model instanceof HibernateProxy) {
|
||||
LazyInitializer lazyInitializer = ((HibernateProxy) model).getHibernateLazyInitializer();
|
||||
if (lazyInitializer.isUninitialized()) {
|
||||
return (Long) lazyInitializer.getIdentifier();
|
||||
}
|
||||
}
|
||||
return model.getId();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user