类org.hibernate.proxy.HibernateProxyHelper源码实例Demo

下面列出了怎么用org.hibernate.proxy.HibernateProxyHelper的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: onedev   文件: BeanContext.java
public static BeanEditor edit(String componentId, Serializable bean, Collection<String> properties, boolean excluded) {
	IModel<Serializable> beanModel = new IModel<Serializable>() {

		@Override
		public void detach() {
		}

		@Override
		public Serializable getObject() {
			return bean;
		}

		@Override
		public void setObject(Serializable object) {
			throw new IllegalStateException();
		}
		
	};
	Class<?> beanClass = HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject());
	BeanContext beanContext = new BeanContext(beanClass, properties, excluded);
	beanModel = beanContext.wrapAsSelfUpdating(beanModel);
	return beanContext.renderForEdit(componentId, beanModel);
}
 
源代码2 项目: onedev   文件: PropertyContext.java
public static PropertyEditor<Serializable> editModel(String componentId, IModel<Serializable> beanModel, String propertyName) {
	
	PropertyContext<Serializable> editContext = of(HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject()), propertyName);
	return editContext.renderForEdit(componentId, new IModel<Serializable>() {

		@Override
		public void detach() {
			beanModel.detach();
		}

		@Override
		public Serializable getObject() {
			return (Serializable) editContext.getDescriptor().getPropertyValue(beanModel.getObject());
		}

		@Override
		public void setObject(Serializable object) {
			editContext.getDescriptor().setPropertyValue(beanModel.getObject(), object);
		}
		
	});
}
 
源代码3 项目: onedev   文件: BeanContext.java
@SuppressWarnings("unchecked")
public static BeanEditor editModel(String componentId, 
		IModel<? extends Serializable> beanModel, Collection<String> properties, boolean excluded) {
	Class<?> beanClass = HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject());
	BeanContext beanContext = new BeanContext(beanClass, properties, excluded);
	return beanContext.renderForEdit(componentId, (IModel<Serializable>)beanModel);
}
 
源代码4 项目: onedev   文件: PropertyContext.java
public static Component viewModel(String componentId, IModel<Serializable> beanModel, String propertyName) {
	PropertyContext<Serializable> editContext = of(HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject()), propertyName);
	return editContext.renderForView(componentId, new LoadableDetachableModel<Serializable>() {

		@Override
		protected Serializable load() {
			return (Serializable) editContext.getDescriptor().getPropertyValue(beanModel.getObject());
		}
		
	});
}
 
源代码5 项目: onedev   文件: VersionedXmlDoc.java
public static VersionedXmlDoc fromBean(@Nullable Object bean) {
	Document dom = DocumentHelper.createDocument();
	AppLoader.getInstance(XStream.class).marshal(bean, new Dom4JWriter(dom));
	VersionedXmlDoc versionedDom = new VersionedXmlDoc(dom);
	if (bean != null) {
		versionedDom.setVersion(MigrationHelper.getVersion(HibernateProxyHelper.getClassWithoutInitializingProxy(bean)));
	}
	return versionedDom;
}
 
源代码6 项目: lams   文件: SessionFactoryImpl.java
@Override
public Type resolveParameterBindType(Object bindValue) {
	if ( bindValue == null ) {
		// we can't guess
		return null;
	}

	return resolveParameterBindType( HibernateProxyHelper.getClassWithoutInitializingProxy( bindValue ) );
}
 
源代码7 项目: lams   文件: AnyType.java
@Override
public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
	//TODO: terrible implementation!
	if ( value == null ) {
		return "null";
	}
	if ( value == LazyPropertyInitializer.UNFETCHED_PROPERTY || !Hibernate.isInitialized( value ) ) {
		return  "<uninitialized>";
	}
	Class valueClass = HibernateProxyHelper.getClassWithoutInitializingProxy( value );
	return factory.getTypeHelper().entity( valueClass ).toLoggableString( value, factory );
}
 
public Class<?> getProxiedClass(Object o) {
    if(o instanceof HibernateProxy) {
        return HibernateProxyHelper.getClassWithoutInitializingProxy(o);
    }
    else {
        return super.getProxiedClass(o);
    }
}
 
源代码9 项目: cacheonix-core   文件: AnyType.java
public String toLoggableString(Object value, SessionFactoryImplementor factory) 
throws HibernateException {
	//TODO: terrible implementation!
	return value==null ?
			"null" :
			Hibernate.entity( HibernateProxyHelper.getClassWithoutInitializingProxy(value) )
					.toLoggableString(value, factory);
}
 
源代码10 项目: webanno   文件: EntityModel.java
private void analyze(T aObject)
{
    if (aObject != null) {
        entityClass = HibernateProxyHelper.getClassWithoutInitializingProxy(aObject);

        String idProperty = null;
        Metamodel metamodel = getEntityManager().getMetamodel();
        EntityType entity = metamodel.entity(entityClass);
        Set<SingularAttribute> singularAttributes = entity.getSingularAttributes();
        for (SingularAttribute singularAttribute : singularAttributes) {
            if (singularAttribute.isId()) {
                idProperty = singularAttribute.getName();
                break;
            }
        }
        if (idProperty == null) {
            throw new RuntimeException("id field not found");
        }

        DirectFieldAccessor accessor = new DirectFieldAccessor(aObject);
        id = (Number) accessor.getPropertyValue(idProperty);
    }
    else {
        entityClass = null;
        id = null;
    }
}
 
源代码11 项目: onedev   文件: BeanContext.java
public static Component viewModel(String componentId, IModel<Serializable> beanModel, 
		Set<String> properties, boolean excluded) {
	Class<?> beanClass = HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject());
	BeanContext editContext = new BeanContext(beanClass, properties, excluded);
	return editContext.renderForView(componentId, beanModel);
}
 
源代码12 项目: onedev   文件: VersionedYamlDoc.java
public static VersionedYamlDoc fromBean(Object bean) {
	VersionedYamlDoc doc = new VersionedYamlDoc((MappingNode) new OneYaml().represent(bean));
	doc.setVersion(MigrationHelper.getVersion(HibernateProxyHelper.getClassWithoutInitializingProxy(bean)));
	return doc;
}
 
源代码13 项目: cacheonix-core   文件: AbstractQueryImpl.java
private Type guessType(Object param) throws HibernateException {
	Class clazz = HibernateProxyHelper.getClassWithoutInitializingProxy( param );
	return guessType( clazz );
}
 
/**
 * @param writer
 * @param includeHistory
 * @param session
 * @throws DataAccessException
 * @throws HibernateException
 */
private void writeObjects(final Writer writer, final boolean includeHistory, final Session session, final boolean preserveIds)
    throws DataAccessException, HibernateException
    {
  // Container für die Objekte
  final List<Object> all = new ArrayList<Object>();
  final XStream stream = initXStream(session, true);
  final XStream defaultXStream = initXStream(session, false);

  session.flush();
  // Alles laden
  final List<Class< ? >> entities = new ArrayList<Class< ? >>();
  entities.addAll(HibernateEntities.instance().getOrderedEntities());
  entities.addAll(HibernateEntities.instance().getOrderedHistoryEntities());
  for (final Class< ? > entityClass : entities) {
    final String entitySimpleName = entityClass.getSimpleName();
    final String entityType = entityClass.getName();
    if (includeHistory == false && entityType.startsWith("de.micromata.hibernate.history.") == true) {
      // Skip history entries.
      continue;
    }
    List< ? > list = session.createQuery("select o from " + entityType + " o").setReadOnly(true).list();
    list = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate());
    final int size = list.size();
    log.info("Writing " + size + " objects");
    for (final Iterator< ? > it = list.iterator(); it.hasNext();) {
      final Object obj = it.next();
      if (log.isDebugEnabled()) {
        log.debug("loaded object " + obj);
      }
      Hibernate.initialize(obj);
      final Class< ? > targetClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
      final ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(targetClass);
      if (classMetadata == null) {
        log.fatal("Can't init " + obj + " of type " + targetClass);
        continue;
      }
      // initalisierung des Objekts...
      defaultXStream.marshal(obj, new CompactWriter(new NullWriter()));

      if (preserveIds == false) {
        // Nun kann die ID gelöscht werden
        classMetadata.setIdentifier(obj, null, EntityMode.POJO);
      }
      if (log.isDebugEnabled()) {
        log.debug("loading evicted object " + obj);
      }
      if (this.ignoreFromTopLevelListing.contains(targetClass) == false) {
        all.add(obj);
      }
    }
  }
  // und schreiben
  try {
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
  } catch (final IOException ex) {
    // ignore, will fail on stream.marshal()
  }
  log.info("Wrote " + all.size() + " objects");
  final MarshallingStrategy marshallingStrategy = new ProxyIdRefMarshallingStrategy();
  stream.setMarshallingStrategy(marshallingStrategy);
  stream.marshal(all, new PrettyPrintWriter(writer));
    }
 
源代码15 项目: development   文件: DomainObject.java
/**
 * Returns the domain class of this entity (e.g. Subscription.class).
 * WARNING: Never use the method entity.getClass(), because JPA might create
 * dynamic proxy classes during runtime (byte code injection). Always, use
 * this method instead.
 */
public static Class<?> getDomainClass(Object entityOrProxy) {
    return HibernateProxyHelper
            .getClassWithoutInitializingProxy(entityOrProxy);
}
 
 类所在包
 同包方法