欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

dorado hibernate

程序员文章站 2022-09-03 21:18:48
@DataResolver @Transactionalpublic void saveCompany(Collection slCompanys) {/*for(SlCompany o: slCompanys) {System.out.println(EntityUtils.getState(o));System.out.println(o instanceof EnhanceableEntity);System.out.....

1.保存数据到数据库

	@DataResolver
    @Transactional
	public void saveCompany(Collection<SlCompany> slCompanys) {
		//修改,新建,移动就是save,删除为delete
		for(SlCompany o: slCompanys) {
			//从dorado前端传过来的数据可直接EntityUtils.getState(o),否则先把o变成Entity
			//o = EntityUtils.toEntity(o);EntityUtils.setState(o, EntityState.MODIFIED);
			if(EntityState.DELETED.equals(EntityUtils.getState(o))){
				slCompanyDao.delete(o);
			}
			slCompanyDao.save(o);
		}
		//先查看各对象的状态,再进行处理
//		slCompanyDao.persistEntities(slCompanys);

//HibernateDao.persistEntities
@SuppressWarnings("unchecked")
public int persistEntities(Collection<T> entities) {
    int i = 0;
    for (Object entity : EntityUtils.getIterable(entities,
            FilterType.DELETED)) {
        delete((T) entity);
        i++;
    }
    for (Object entity : EntityUtils.getIterable(entities,
            FilterType.MODIFIED)) {
        save((T) entity);
        i++;
    }
    for (Object entity : EntityUtils
            .getIterable(entities, FilterType.MOVED)) {
        save((T) entity);
        i++;
    }
    for (Object entity : EntityUtils.getIterable(entities, FilterType.NEW)) {
        save((T) entity);
        i++;
    }
    return i;
}
//
public static Iterator getIterator(Collection entities, FilterType filterType)
	{
		return new EntityIterator(entities, filterType);
	}
//
public EntityIterator(Collection entities, FilterType filterType)
	{
		iterator = entities.iterator();
		this.filterType = filterType;
		findNext();
	}

	protected void findNext()
	{
		if (iterator.hasNext())
		{
			currentEntity = iterator.next();
			if (currentEntity != null)
			{
				boolean visible = false;
				EntityState state = EntityUtils.getState(currentEntity);
				if (filterType == FilterType.NONE)
					visible = state == EntityState.NONE;
				else
				if (filterType == FilterType.NEW)
					visible = state == EntityState.NEW;
				else
				if (filterType == FilterType.MODIFIED)
					visible = state == EntityState.MODIFIED;
				else
				if (filterType == FilterType.DELETED)
					visible = state == EntityState.DELETED;
				else
				if (filterType == FilterType.MOVED)
					visible = state == EntityState.MOVED;
				else
				if (filterType == FilterType.VISIBLE)
					visible = state != EntityState.DELETED;
				else
				if (filterType == FilterType.DIRTY)
					visible = state == EntityState.NEW || state == EntityState.MODIFIED || state == EntityState.DELETED || state == EntityState.MOVED;
				else
				if (filterType == FilterType.VISIBLE)
					visible = state == EntityState.NEW || state == EntityState.MODIFIED || state == EntityState.MOVED;
				else
				if (filterType == FilterType.ALL)
					visible = true;
				if (visible)
					hasNext = true;
				else
					findNext();
			} else
			{
				hasNext = false;
			}
		} else
		{
			hasNext = false;
		}
	}

//
	public static EntityState getState(Object entity)
	{
		EntityEnhancer entityEnhancer = getEntityEnhancer(entity);
		if (entityEnhancer != null)
			return entityEnhancer.getState();
		else
			return EntityState.NONE;
	}
	//
public static EntityEnhancer getEntityEnhancer(Object entity)
	{
	//从dorado前端传过来的如果没有经过任何处理,不是EnhanceableEntity
		if (entity instanceof EnhanceableEntity)
		{
			EnhanceableEntity enhanceableEntity = (EnhanceableEntity)entity;
			return enhanceableEntity.getEntityEnhancer();
		}
		//从dorado前端传过来的如果没有经过任何处理,是ProxyBeanUtils
		if (ProxyBeanUtils.isProxy(entity))
		{
			MethodInterceptorDispatcher dispatcher = ProxyBeanUtils.getMethodInterceptorDispatcher(entity);
			if (dispatcher != null)
			{
				org.aopalliance.intercept.MethodInterceptor mis[] = dispatcher.getSubMethodInterceptors();
				org.aopalliance.intercept.MethodInterceptor arr$[] = mis;
				int len$ = arr$.length;
				for (int i$ = 0; i$ < len$; i$++)
				{
					org.aopalliance.intercept.MethodInterceptor mi = arr$[i$];
					if (mi instanceof EntityEnhancer)
						return (EntityEnhancer)mi;
						//mi.getState()
				}

			}
		}
		return null;
	}

2.查找

slEmployeeDao.find(page, " from SlEmployee where 1=1 " + " AND name like '%li%' ");

本文地址:https://blog.csdn.net/puspos/article/details/107310752