當前位置: 首頁>>代碼示例>>Java>>正文


Java HibernateProxy類代碼示例

本文整理匯總了Java中org.hibernate.proxy.HibernateProxy的典型用法代碼示例。如果您正苦於以下問題:Java HibernateProxy類的具體用法?Java HibernateProxy怎麽用?Java HibernateProxy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HibernateProxy類屬於org.hibernate.proxy包,在下文中一共展示了HibernateProxy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: unproxyAndReassociate

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public Object unproxyAndReassociate(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();
		reassociateProxy( li, proxy );
		//initialize + unwrap the object and return it
		return li.getImplementation();
	}
	else {
		return maybeProxy;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:StatefulPersistenceContext.java

示例2: unproxyEntity

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
protected <T> T unproxyEntity(T template) {
    if (template instanceof HibernateProxy) {
        Hibernate.initialize(template);
        template = (T) ((HibernateProxy) template)
                .getHibernateLazyInitializer()
                .getImplementation();
    }
    return template;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:10,代碼來源:EJBTestBase.java

示例3: read

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public Object read(ResultSet resultSet, ResultSetProcessingContext context) throws SQLException {
	final EntityReferenceProcessingState processingState = getIdentifierResolutionContext( context );

	final EntityKey entityKey = processingState.getEntityKey();
	final Object entityInstance = context.getProcessingState( entityReturn ).getEntityInstance();

	if ( context.shouldReturnProxies() ) {
		final Object proxy = context.getSession().getPersistenceContext().proxyFor(
				entityReturn.getEntityPersister(),
				entityKey,
				entityInstance
		);
		if ( proxy != entityInstance ) {
			( (HibernateProxy) proxy ).getHibernateLazyInitializer().setImplementation( proxy );
			return proxy;
		}
	}

	return entityInstance;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:EntityReturnReader.java

示例4: reassociateIfUninitializedProxy

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public boolean reassociateIfUninitializedProxy(Object value) throws MappingException {
	if ( value instanceof ElementWrapper ) {
		value = ( (ElementWrapper) value ).getElement();
	}

	if ( !Hibernate.isInitialized( value ) ) {
		final HibernateProxy proxy = (HibernateProxy) value;
		final LazyInitializer li = proxy.getHibernateLazyInitializer();
		reassociateProxy( li, proxy );
		return true;
	}
	else {
		return false;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:StatefulPersistenceContext.java

示例5: unproxy

import org.hibernate.proxy.HibernateProxy; //導入依賴的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;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:StatefulPersistenceContext.java

示例6: getProxy

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public HibernateProxy getProxy(
		Serializable id,
		SessionImplementor session) throws HibernateException {
	return JavassistLazyInitializer.getProxy(
			factory,
			entityName,
			persistentClass,
			interfaces,
			getIdentifierMethod,
			setIdentifierMethod,
			componentIdType,
			id,
			session,
			overridesEquals
	);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:JavassistProxyFactory.java

示例7: readResolve

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
private Object readResolve() {
	try {
		HibernateProxy proxy = JavassistLazyInitializer.getProxy(
			getEntityName(),
			persistentClass,
			interfaces,
			getIdentifierMethodName==null
					? null
					: getIdentifierMethodClass.getDeclaredMethod( getIdentifierMethodName, (Class[]) null ),
			setIdentifierMethodName==null
					? null 
					: setIdentifierMethodClass.getDeclaredMethod(setIdentifierMethodName, setIdentifierMethodParams),
			componentIdType,
			getId(),
			null
		);
		setReadOnlyBeforeAttachedToSession( ( JavassistLazyInitializer ) proxy.getHibernateLazyInitializer() );
		return proxy;
	}
	catch (NoSuchMethodException nsme) {
		throw new HibernateException("could not create proxy for entity: " + getEntityName(), nsme);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:SerializableProxy.java

示例8: isPropertyInitialized

import org.hibernate.proxy.HibernateProxy; //導入依賴的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;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:Hibernate.java

示例9: getCurrentLockMode

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public LockMode getCurrentLockMode(Object object) throws HibernateException {
	errorIfClosed();
	checkTransactionSynchStatus();
	if ( object == null ) {
		throw new NullPointerException( "null object passed to getCurrentLockMode()" );
	}
	if ( object instanceof HibernateProxy ) {
		object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(this);
		if ( object == null ) {
			return LockMode.NONE;
		}
	}
	EntityEntry e = persistenceContext.getEntry(object);
	if ( e == null ) {
		throw new TransientObjectException( "Given object not associated with the session" );
	}
	if ( e.getStatus() != Status.MANAGED ) {
		throw new ObjectDeletedException(
				"The given object was deleted",
				e.getId(),
				e.getPersister().getEntityName()
			);
	}
	return e.getLockMode();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:SessionImpl.java

示例10: getIdentifier

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public Serializable getIdentifier(Object object) throws HibernateException {
	errorIfClosed();
	checkTransactionSynchStatus();
	if ( object instanceof HibernateProxy ) {
		LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
		if ( li.getSession() != this ) {
			throw new TransientObjectException( "The proxy was not associated with this session" );
		}
		return li.getIdentifier();
	}
	else {
		EntityEntry entry = persistenceContext.getEntry(object);
		if ( entry == null ) {
			throw new TransientObjectException( "The instance was not associated with this session" );
		}
		return entry.getId();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:SessionImpl.java

示例11: bestGuessEntityName

import org.hibernate.proxy.HibernateProxy; //導入依賴的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();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:SessionImpl.java

示例12: getEntityName

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public String getEntityName(Object object) {
	errorIfClosed();
	checkTransactionSynchStatus();
	if (object instanceof HibernateProxy) {
		if ( !persistenceContext.containsProxy( object ) ) {
			throw new TransientObjectException("proxy was not associated with the session");
		}
		object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation();
	}

	EntityEntry entry = persistenceContext.getEntry(object);
	if ( entry == null ) {
		throwTransientObjectException( object );
	}
	return entry.getPersister().getEntityName();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:SessionImpl.java

示例13: returnNarrowedProxy

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
/**
 * Given a proxy, initialize it and/or narrow it provided either
 * is necessary.
 *
 * @param event The initiating load request event
 * @param persister The persister corresponding to the entity to be loaded
 * @param keyToLoad The key of the entity to be loaded
 * @param options The defined load options
 * @param persistenceContext The originating session
 * @param proxy The proxy to narrow
 *
 * @return The created/existing proxy
 */
private Object returnNarrowedProxy(
		final LoadEvent event,
		final EntityPersister persister,
		final EntityKey keyToLoad,
		final LoadEventListener.LoadType options,
		final PersistenceContext persistenceContext,
		final Object proxy) {
	LOG.trace( "Entity proxy found in session cache" );
	LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
	if ( li.isUnwrap() ) {
		return li.getImplementation();
	}
	Object impl = null;
	if ( !options.isAllowProxyCreation() ) {
		impl = load( event, persister, keyToLoad, options );
		if ( impl == null ) {
			event.getSession()
					.getFactory()
					.getEntityNotFoundDelegate()
					.handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier() );
		}
	}
	return persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:38,代碼來源:DefaultLoadEventListener.java

示例14: resolveIdentifier

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
/**
 * Resolve an identifier via a load.
 *
 * @param id The entity id to resolve
 * @param session The orginating session.
 * @return The resolved identifier (i.e., loaded entity).
 * @throws org.hibernate.HibernateException Indicates problems performing the load.
 */
protected final Object resolveIdentifier(Serializable id, SessionImplementor session) throws HibernateException {
	boolean isProxyUnwrapEnabled = unwrapProxy &&
			getAssociatedEntityPersister( session.getFactory() )
					.isInstrumented();

	Object proxyOrEntity = session.internalLoad(
			getAssociatedEntityName(),
			id,
			eager,
			isNullable() && !isProxyUnwrapEnabled
	);

	if ( proxyOrEntity instanceof HibernateProxy ) {
		( ( HibernateProxy ) proxyOrEntity ).getHibernateLazyInitializer()
				.setUnwrap( isProxyUnwrapEnabled );
	}

	return proxyOrEntity;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:EntityType.java

示例15: serializeWithType

import org.hibernate.proxy.HibernateProxy; //導入依賴的package包/類
@Override
public void serializeWithType(HibernateProxy value, JsonGenerator jgen,
		SerializerProvider provider, TypeSerializer typeSer)
		throws IOException, JsonProcessingException {
	Object proxiedValue = findProxied(value);
	if (proxiedValue == null) {
		provider.defaultSerializeNull(jgen);
		return;
	}
	/*
	 * This isn't exactly right, since type serializer really refers to
	 * proxy object, not value. And we really don't either know static type
	 * (necessary to know how to apply additional type info) or other
	 * things; so it's not going to work well. But... we'll do out best.
	 */
	findSerializer(provider, proxiedValue).serializeWithType(proxiedValue,
			jgen, provider, typeSer);
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:19,代碼來源:HibernateProxySerializer.java


注:本文中的org.hibernate.proxy.HibernateProxy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。