本文整理汇总了Java中org.hibernate.proxy.LazyInitializer.isUninitialized方法的典型用法代码示例。如果您正苦于以下问题:Java LazyInitializer.isUninitialized方法的具体用法?Java LazyInitializer.isUninitialized怎么用?Java LazyInitializer.isUninitialized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.proxy.LazyInitializer
的用法示例。
在下文中一共展示了LazyInitializer.isUninitialized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unproxy
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@Override
public Object unproxy(Object maybeProxy) throws HibernateException {
if ( maybeProxy instanceof ElementWrapper ) {
maybeProxy = ( (ElementWrapper) maybeProxy ).getElement();
}
if ( maybeProxy instanceof HibernateProxy ) {
final HibernateProxy proxy = (HibernateProxy) maybeProxy;
final LazyInitializer li = proxy.getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
throw new PersistentObjectException(
"object was an uninitialized proxy for " + li.getEntityName()
);
}
//unwrap the object and return
return li.getImplementation();
}
else {
return maybeProxy;
}
}
示例2: isPropertyInitialized
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Check if the property is initialized. If the named property does not exist
* or is not persistent, this method always returns <tt>true</tt>.
*
* @param proxy The potential proxy
* @param propertyName the name of a persistent attribute of the object
* @return true if the named property of the object is not listed as uninitialized; false otherwise
*/
public static boolean isPropertyInitialized(Object proxy, String propertyName) {
final Object entity;
if ( proxy instanceof HibernateProxy ) {
final LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
return false;
}
else {
entity = li.getImplementation();
}
}
else {
entity = proxy;
}
if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
final FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity );
return interceptor == null || interceptor.isInitialized( propertyName );
}
else {
return true;
}
}
示例3: bestGuessEntityName
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@Override
public String bestGuessEntityName(Object object) {
if (object instanceof HibernateProxy) {
LazyInitializer initializer = ( ( HibernateProxy ) object ).getHibernateLazyInitializer();
// it is possible for this method to be called during flush processing,
// so make certain that we do not accidentally initialize an uninitialized proxy
if ( initializer.isUninitialized() ) {
return initializer.getEntityName();
}
object = initializer.getImplementation();
}
EntityEntry entry = persistenceContext.getEntry(object);
if (entry==null) {
return guessEntityName(object);
}
else {
return entry.getPersister().getEntityName();
}
}
示例4: unproxy
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Get the entity instance underlying the given proxy, throwing
* an exception if the proxy is uninitialized. If the given object
* is not a proxy, simply return the argument.
*/
public Object unproxy(Object maybeProxy) throws HibernateException {
if ( maybeProxy instanceof ElementWrapper ) {
maybeProxy = ( (ElementWrapper) maybeProxy ).getElement();
}
if ( maybeProxy instanceof HibernateProxy ) {
HibernateProxy proxy = (HibernateProxy) maybeProxy;
LazyInitializer li = proxy.getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
throw new PersistentObjectException(
"object was an uninitialized proxy for " +
li.getEntityName()
);
}
return li.getImplementation(); //unwrap the object
}
else {
return maybeProxy;
}
}
示例5: isPropertyInitialized
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Check if the property is initialized. If the named property does not exist
* or is not persistent, this method always returns <tt>true</tt>.
*
* @param proxy The potential proxy
* @param propertyName the name of a persistent attribute of the object
* @return true if the named property of the object is not listed as uninitialized
* @return false if the object is an uninitialized proxy, or the named property is uninitialized
*/
public static boolean isPropertyInitialized(Object proxy, String propertyName) {
Object entity;
if ( proxy instanceof HibernateProxy ) {
LazyInitializer li = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
return false;
}
else {
entity = li.getImplementation();
}
}
else {
entity = proxy;
}
if ( FieldInterceptionHelper.isInstrumented( entity ) ) {
FieldInterceptor interceptor = FieldInterceptionHelper.extractFieldInterceptor( entity );
return interceptor == null || interceptor.isInitialized( propertyName );
}
else {
return true;
}
}
示例6: bestGuessEntityName
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
public String bestGuessEntityName(Object object) {
if (object instanceof HibernateProxy) {
LazyInitializer initializer = ( ( HibernateProxy ) object ).getHibernateLazyInitializer();
// it is possible for this method to be called during flush processing,
// so make certain that we do not accidently initialize an uninitialized proxy
if ( initializer.isUninitialized() ) {
return initializer.getEntityName();
}
object = initializer.getImplementation();
}
EntityEntry entry = persistenceContext.getEntry(object);
if (entry==null) {
return guessEntityName(object);
}
else {
return entry.getPersister().getEntityName();
}
}
示例7: write
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void write(JsonWriter out, HibernateProxy value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
LazyInitializer initializer = value.getHibernateLazyInitializer();
if (initializer.isUninitialized()) {
out.nullValue();
return;
} else {
// Retrieve the original (not proxy) class
Class<?> baseType = Hibernate.getClass(value);
// Get the TypeAdapter of the original class, to delegate the serialization
TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
// Get a filled instance of the original class
Object unproxiedValue = initializer.getImplementation();
// Serialize the value
delegate.write(out, unproxiedValue);
}
}
示例8: contains
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@Override
public boolean contains(Object object) {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
//do not use proxiesByKey, since not all
//proxies that point to this session's
//instances are in that collection!
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
//if it is an uninitialized proxy, pointing
//with this session, then when it is accessed,
//the underlying instance will be "contained"
return li.getSession()==this;
}
else {
//if it is initialized, see if the underlying
//instance is contained, since we need to
//account for the fact that it might have been
//evicted
object = li.getImplementation();
}
}
// A session is considered to contain an entity only if the entity has
// an entry in the session's persistence context and the entry reports
// that the entity has not been removed
EntityEntry entry = persistenceContext.getEntry( object );
delayedAfterCompletion();
return entry != null && entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
}
示例9: guessEntityPersister
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
private EntityPersister guessEntityPersister(Object object) {
if ( scope == null ) {
return null;
}
String entityName = null;
// this code is largely copied from Session's bestGuessEntityName
Object entity = object;
if ( entity instanceof HibernateProxy ) {
final LazyInitializer initializer = ( (HibernateProxy) entity ).getHibernateLazyInitializer();
if ( initializer.isUninitialized() ) {
entityName = initializer.getEntityName();
}
entity = initializer.getImplementation();
}
if ( entityName == null ) {
for ( EntityNameResolver resolver : scope.resolveFactory().iterateEntityNameResolvers() ) {
entityName = resolver.resolveEntityName( entity );
if ( entityName != null ) {
break;
}
}
}
if ( entityName == null ) {
// the old-time stand-by...
entityName = object.getClass().getName();
}
return scope.resolveFactory().getEntityPersister( entityName );
}
示例10: contains
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
public boolean contains(Object collection, Object childObject, SessionImplementor session) {
// we do not have to worry about queued additions to uninitialized
// collections, since they can only occur for inverse collections!
Iterator elems = getElementsIterator( collection, session );
while ( elems.hasNext() ) {
Object element = elems.next();
// worrying about proxies is perhaps a little bit of overkill here...
if ( element instanceof HibernateProxy ) {
LazyInitializer li = ( (HibernateProxy) element ).getHibernateLazyInitializer();
if ( !li.isUninitialized() ) element = li.getImplementation();
}
if ( element == childObject ) return true;
}
return false;
}
示例11: getClass
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Hibernate makes {@link Class#getClass()} diffficult ...
* @param example The class that we want to call {@link Class#getClass()} on
* @return The type of the given object
*/
public Class getClass(Object example)
{
if (example instanceof HibernateProxy)
{
HibernateProxy proxy = (HibernateProxy) example;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
SessionImplementor implementor = initializer.getSession();
if (initializer.isUninitialized())
{
try
{
// getImplementation is going to want to talk to a session
if (implementor.isClosed())
{
// Give up and return example.getClass();
return example.getClass();
}
}
catch (NoSuchMethodError ex)
{
// We must be using Hibernate 3.0/3.1 which doesn't have
// this method
}
}
return initializer.getImplementation().getClass();
}
else
{
return example.getClass();
}
}
示例12: getClass
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Hibernate makes {@link Class#getClass()} difficult ...
* @param example The class that we want to call {@link Class#getClass()} on
* @return The type of the given object
*/
public Class<?> getClass(Object example)
{
if (example instanceof HibernateProxy)
{
HibernateProxy proxy = (HibernateProxy) example;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
SessionImplementor implementor = initializer.getSession();
if (initializer.isUninitialized())
{
try
{
// getImplementation is going to want to talk to a session
if (implementor.isClosed())
{
// Give up and return example.getClass();
return example.getClass();
}
}
catch (NoSuchMethodError ex)
{
// We must be using Hibernate 3.0/3.1 which doesn't have
// this method
}
}
return initializer.getImplementation().getClass();
}
else
{
return example.getClass();
}
}
示例13: contains
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
public boolean contains(Object object) {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
//do not use proxiesByKey, since not all
//proxies that point to this session's
//instances are in that collection!
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
//if it is an uninitialized proxy, pointing
//with this session, then when it is accessed,
//the underlying instance will be "contained"
return li.getSession()==this;
}
else {
//if it is initialized, see if the underlying
//instance is contained, since we need to
//account for the fact that it might have been
//evicted
object = li.getImplementation();
}
}
// A session is considered to contain an entity only if the entity has
// an entry in the session's persistence context and the entry reports
// that the entity has not been removed
EntityEntry entry = persistenceContext.getEntry( object );
return entry != null && entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
}
示例14: findProxied
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Helper method for finding value being proxied, if it is available
* or if it is to be forced to be loaded.
*/
protected Object findProxied(HibernateProxy proxy)
{
LazyInitializer init = proxy.getHibernateLazyInitializer();
if (!_forceLazyLoading && init.isUninitialized()) {
return null;
}
return init.getImplementation();
}
示例15: getId
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* 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();
}