当前位置: 首页>>代码示例>>Java>>正文


Java Session.clear方法代码示例

本文整理汇总了Java中org.hibernate.Session.clear方法的典型用法代码示例。如果您正苦于以下问题:Java Session.clear方法的具体用法?Java Session.clear怎么用?Java Session.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.Session的用法示例。


在下文中一共展示了Session.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public Integer save(App entity) {
    Session session = null;
    Integer pkId = null;
    try {
        session = sessionFactory.openSession();
        pkId = (Integer) session.save(entity);
    } catch (Exception e) {
        logger.error("error:", e);
    } finally {
        session.flush();
        session.clear();
        session.close();
    }

    return pkId;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:18,代码来源:AppDaoImpl.java

示例2: batchIn1TransactionToApp

import org.hibernate.Session; //导入方法依赖的package包/类
private Transaction batchIn1TransactionToApp(Session session, List<MarketApp> marketApps) {
    Transaction tx = null;
    try {
        session.setDefaultReadOnly(false);
        tx = session.beginTransaction();
        long start = System.currentTimeMillis();
        mergePaginationToApp(session, marketApps);
        session.flush();
        session.clear();
        logger.info("mergePaginationToApp耗时:{}", (System.currentTimeMillis() - start) + " ms!");
        tx.commit();
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        logger.error("Exception", e);
    }
    return tx;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:20,代码来源:MergeServiceImpl.java

示例3: save

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public Integer save(BigGamePack entity) {
    Session session = null;
    Integer pkId = null;
    try {
        session = sessionFactory.openSession();
        pkId = (Integer) session.save(entity);
    } catch (Exception e) {
        logger.error("error:", e);
    } finally {
        session.flush();
        session.clear();
        session.close();
    }

    return pkId;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:18,代码来源:BigGamePackDaoImpl.java

示例4: update

import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public void update(App entity) {
    Session session = null;
    try {
        session = sessionFactory.openSession();
        session.update(entity);
    } finally {
        session.flush();
        session.clear();
        session.close();
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:13,代码来源:AppDaoImpl.java

示例5: exportData

import org.hibernate.Session; //导入方法依赖的package包/类
@Sessional
@Override
public void exportData(File exportDir, int batchSize) {
	Session session = sessionFactory.openSession();
	for (Class<?> entityType: getEntityTypes(sessionFactory)) {
		logger.info("Exporting table '" + entityType.getSimpleName() + "'...");
		
		logger.info("Querying table ids...");
		
		Criteria criteria = session.createCriteria(entityType, "entity")
				.setProjection(Projections.property("entity.id")).addOrder(Order.asc("id"));
		@SuppressWarnings("unchecked")
		List<Long> ids = criteria.list();
		int count = ids.size();
		
		for (int i=0; i<count/batchSize; i++) {
			exportEntity(session, entityType, ids, i*batchSize, batchSize, batchSize, exportDir);
			// clear session to free memory
			session.clear();
		}
		
		if (count%batchSize != 0) {
			exportEntity(session, entityType, ids, count/batchSize*batchSize, count%batchSize, batchSize, exportDir);
		}
		logger.info("");
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:28,代码来源:DefaultPersistManager.java

示例6: importData

import org.hibernate.Session; //导入方法依赖的package包/类
@Sessional
@Override
public void importData(Metadata metadata, File dataDir) {
	Session session = dao.getSession();
	List<Class<?>> entityTypes = getEntityTypes(sessionFactory);
	Collections.reverse(entityTypes);
	for (Class<?> entityType: entityTypes) {
		File[] dataFiles = dataDir.listFiles(new FilenameFilter() {

			@Override
			public boolean accept(File dir, String name) {
				return name.startsWith(entityType.getSimpleName() + "s.xml");
			}
			
		});
		for (File file: dataFiles) {
			try {
				logger.info("Importing from data file '" + file.getName() + "'...");
				session.beginTransaction();
				VersionedDocument dom = VersionedDocument.fromFile(file);
				
				for (Element element: dom.getRootElement().elements()) {
					element.detach();
					AbstractEntity entity = (AbstractEntity) new VersionedDocument(DocumentHelper.createDocument(element)).toBean();
					session.replicate(entity, ReplicationMode.EXCEPTION);
				}
				session.flush();
				session.clear();
				session.getTransaction().commit();
			} catch (Throwable e) {
				session.getTransaction().rollback();
				throw Throwables.propagate(e);
			}
		}
	}	
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:37,代码来源:DefaultPersistManager.java

示例7: isUserExists

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static String isUserExists(String uidoreml, String passw)
{
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         List<Object []> lst=new ArrayList<Object []> ();
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("select usr_id, pass, email_id from UserDetails ud where (ud.usr_id=:urid or ud.email_id=:eml) and ud.pass=:passd");
                qry.setParameter("urid", uidoreml);
                qry.setParameter("eml", uidoreml);
                qry.setParameter("passd",passw);
                lst=qry.getResultList();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                  if (lst.isEmpty())
                  {
                        return (null);
                  }
                  else
                  {
                       if ( ( (uidoreml.equals((lst.get(0))[0].toString())) || (uidoreml.equals((lst.get(0))[2].toString())) ) && (passw.equals((lst.get(0))[1].toString())))
                       {
                            return ((lst.get(0))[0].toString());
                       }
                       else
                       {
                            return (null);
                       }
                  }
            }
            else
            {
                 return (null);
            }
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:53,代码来源:Validate.java

示例8: canPersistAssociationToDetachedEntity

import org.hibernate.Session; //导入方法依赖的package包/类
@Test
@TestForIssue(jiraKey = "OGM-931")
public void canPersistAssociationToDetachedEntity() throws Exception {
	Session session = openSession();
	Transaction transaction = session.beginTransaction();

	// Persist employer
	Employer employer = new Employer();
	employer.setId( "employer-1" );
	employer.setName( "Hibernate" );
	session.save( employer );

	transaction.commit();
	session.clear();

	transaction = session.beginTransaction();

	// Create employee and associate it with detached employer
	Employee employee = new Employee();
	employee.setId( "employee-1" );
	employee.setName( "DNadar" );
	employee.setEmployer( employer );
	session.save( employee );

	transaction.commit();
	session.clear();

	transaction = session.beginTransaction();

	// Load association from main side
	Employee loadedEmployee = session.get( Employee.class, "employee-1" );
	assertThat( loadedEmployee.getEmployer().getName() ).isEqualTo( "Hibernate" );

	transaction.commit();
	session.clear();

	transaction = session.beginTransaction();

	// Load association from inverse side
	Employer loadedEmployer = session.get( Employer.class, "employer-1" );
	assertThat( loadedEmployer.getEmployees() ).onProperty( "name" ).containsOnly( "DNadar" );

	// Clean up
	session.delete( loadedEmployer.getEmployees().iterator().next() );
	session.delete( loadedEmployer );

	transaction.commit();
	session.close();
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-ignite,代码行数:50,代码来源:ManyToOneTest.java

示例9: isUserPasswordExists

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean isUserPasswordExists(String pass)
{
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         List<Object> lst=new ArrayList<Object> ();
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("select usr_id from UserDetails ud where ud.pass=:pss");
                qry.setParameter("pss", pass);
                lst=qry.getResultList();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                  if (lst.isEmpty())
                  {
                        return (false);
                  }
                  else
                  {
                        return (true);
                  }
            }
            else
            {
                 return (true);
            }
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:44,代码来源:Validate.java

示例10: updateUserPhone

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean updateUserPhone(String ... vals)
{
         int chk=0;
         int nor=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("update UserDetails ud set ud.mob_no=:mobno where ud.usr_id=:uid");
                qry.setParameter("uid", vals[0]);
                qry.setParameter("mobno", vals[1]);
                nor=qry.executeUpdate();
                System.out.println("No. Of rows updated="+nor);
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                 if(nor!=0)
                 {
                      return (true);
                 }
                 else
                 {
                      return (false);
                 }
            }
            else
            {
                 return (false);
            }
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:46,代码来源:Update.java

示例11: isPlaceExists

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean isPlaceExists(String desc)
{
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         List<Object> lst=new ArrayList<Object> ();
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("select pl_id from Places pl where pl.pl_desc=:pldesc");
                qry.setParameter("pldesc", desc);
                lst=qry.getResultList();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                  if (lst.isEmpty())
                  {
                        return (false);
                  }
                  else
                  {
                       return (true);
                  }
            }
            else
            {
                 return (true);
            }
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:44,代码来源:Validate.java

示例12: setPlace

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized private static Places setPlace(String ... vals)
{
         UserDetails ud=null;
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         try{
               s=sf.openSession();
               s.beginTransaction();
               Query qry=s.createQuery("from UserDetails ud where ud.usr_id=:uid");
               qry.setParameter("uid", vals[0]);
               ud=(UserDetails)qry.getSingleResult();
               s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
                
           if(chk==0)
           {
                   Places pl=new Places ();
                   Address addr = pl.getAddr();
                   pl.setPname(vals[1]);
                   pl.setPl_type(vals[2]);
                   pl.setPl_id(generatePLACE_ID());
                   addr.setLocality(vals[3]);
                   addr.setCity(vals[4]);
                   addr.setPincode(vals[5]);
                   addr.setState(vals[6]);
                   addr.setCountry(vals[7]);
                   pl.setAddr(addr);
                   pl.setPl_desc(vals[8]);
                   pl.setUd(ud);
                   return (pl);
           }
           else
           {
                return (null);
           }
 }
 
开发者ID:Tejas07PSK,项目名称:EBwn2_ForOpenShift,代码行数:51,代码来源:Insert.java

示例13: isUserPhoneExists

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean isUserPhoneExists(String pno)
{
         int chk=0;
         sf=Logic.getSf();
         Session s = null;
         List<Object> lst=new ArrayList<Object> ();
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("select usr_id from UserDetails ud where ud.mob_no=:mobno");
                qry.setParameter("mobno", pno);
                lst=qry.getResultList();
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                         System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                  if (lst.isEmpty())
                  {
                        return (false);
                  }
                  else
                  {
                        return (true);
                  }
            }
            else
            {
                 return (true);
            }
}
 
开发者ID:Tejas07PSK,项目名称:maven_EWorld_OpenShift,代码行数:44,代码来源:Validate.java

示例14: updateUserEmail

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean updateUserEmail(String ... vals)
{
         int chk=0;
         int nor=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("update UserDetails ud set ud.email_id=:email where ud.usr_id=:uid");
                qry.setParameter("uid", vals[0]);
                qry.setParameter("email", vals[1]);
                nor=qry.executeUpdate();
                System.out.println("No. Of rows updated="+nor);
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                if(nor!=0) 
                {
                     return (true);
                }
                else
                {
                     return (false);
                }
            }
            else
            {
                 return (false);
            }
}
 
开发者ID:Tejas07PSK,项目名称:EBwn2_ForOpenShift,代码行数:46,代码来源:Update.java

示例15: updateUserPhone

import org.hibernate.Session; //导入方法依赖的package包/类
synchronized public static boolean updateUserPhone(String ... vals)
{
         int chk=0;
         int nor=0;
         sf=Logic.getSf();
         Session s = null;
         try{
                s=sf.openSession();
                s.beginTransaction();
                Query qry=s.createQuery("update UserDetails ud set ud.mob_no=:mobno where ud.usr_id=:uid");
                qry.setParameter("uid", vals[0]);
                qry.setParameter("mobno", vals[1]);
                nor=qry.executeUpdate();
                System.out.println("No. Of rows updated="+nor);
                s.getTransaction().commit();
            }catch (Exception e)
                 {
                         chk=-1;
                          System.out.println("HibernateException Occured!!"+e);
                         e.printStackTrace();
                 }
            finally
                 {
                         if(s!=null)
                         {
                              s.clear();
                              s.close();
                         }
                 }
            if(chk==0)
            {
                 if(nor!=0)
                 {
                      return (true);
                 }
                 else
                 {
                      return (false);
                 }
            }
            else
            {
                 return (false);
            }
}
 
开发者ID:Tejas07PSK,项目名称:EBwn2_ForOpenShift,代码行数:46,代码来源:Update.java


注:本文中的org.hibernate.Session.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。