List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(Class entityType);
From source file:com.tysanclan.site.projectewok.util.forum.ShadowForumViewContext.java
License:Open Source License
@Override public List<ForumCategory> getCategories(Session sess, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMCATEGORY FC "); q.append("WHERE EXISTS ("); q.append("SELECT * FROM FORUM f "); q.append("WHERE f.DTYPE!='GroupForum' AND f.MEMBERSONLY=false AND f.category_id = FC.id"); q.append(") ORDER BY id ASC LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("count", count); query.setLong("offset", offset); query.addEntity(ForumCategory.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.ShadowForumViewContext.java
License:Open Source License
@Override public List<ForumThread> getThreads(Session sess, Forum context, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMTHREAD FT WHERE ft.forum_id = :forum AND "); q.append(/*from w w w .j a v a 2s . c om*/ "EXISTS (SELECT * FROM FORUMPOST FP WHERE (fp.shadow = false OR fp.poster_id = :viewer ) AND fp.thread_id = ft.id) "); q.append("AND NOT EXISTS (SELECT * FROM trial WHERE trialthread_id = ft.id) "); q.append("ORDER BY STICKY DESC, lastPost DESC "); q.append("LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("forum", context.getId()); query.setLong("count", count); query.setLong("offset", offset); query.setLong("viewer", viewer.getId()); query.setLong("viewer2", viewer.getId()); query.addEntity(ForumThread.class); return listOf(query); }
From source file:com.tysanclan.site.projectewok.util.forum.ShadowForumViewContext.java
License:Open Source License
@Override public List<ForumPost> getPosts(Session sess, ForumThread context, User viewer, long offset, long count) { StringBuilder q = new StringBuilder(); q.append("SELECT * FROM FORUMPOST FP WHERE (fp.shadow = false OR fp.poster_id = :viewer)"); q.append(" AND fp.thread_id = :thread "); q.append("ORDER BY time ASC LIMIT :count OFFSET :offset"); SQLQuery query = sess.createSQLQuery(q.toString()); query.setLong("thread", context.getId()); query.setLong("count", count); query.setLong("offset", offset); query.setLong("viewer", viewer.getId()); query.addEntity(ForumPost.class); return listOf(query); }
From source file:com.ulcs.dao.CustomerDAO.java
public List<Customer> getMemberInfo() { try {/*from ww w . j a v a 2 s .c o m*/ List<Customer> customer = new ArrayList<Customer>(); // Connection con=Teledbc.connector(); String qry = "Select * from customer"; AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Customer.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery(qry); query.addEntity(Customer.class); List rs = query.list(); session.getTransaction().commit(); return (List<Customer>) rs; // PreparedStatement pst= con.prepareStatement(qry); // ResultSet rs=pst.executeQuery(); // // while(rs.next()){ // Customer m=new Customer(); // m.setCustomerName(rs.getString("customerName")); // m.setCustomerNumber(rs.getString("customerNumber")); // m.setCustomerAddress(rs.getString("customerAddress")); // m.setCustomerID(rs.getInt("CsID")); // customer.add(m); // } // con.close(); // return customer; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.ulcs.dao.CustomerDAO.java
public Customer getCustomer(int customerID) { try {/*from ww w .j a v a 2s . c o m*/ // Connection con=Teledbc.connector(); String qry = "Select * from customer where customerID=:CsID"; AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Customer.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery(qry); query.addEntity(Customer.class); query.setParameter("CsID", customerID); List queryList = query.list(); session.getTransaction().commit(); if (queryList != null && queryList.isEmpty()) { return null; } else { return (Customer) queryList.get(0); } // PreparedStatement pst= con.prepareStatement(qry); // pst.setInt(1, customerID); // ResultSet rs=pst.executeQuery(); // // while(rs.next()){ // Customer m=new Customer(); // m.setCustomerName(rs.getString("customerName")); // m.setCustomerNumber(rs.getString("customerNumber")); // m.setCustomerAddress(rs.getString("customerAddress")); // m.setCustomerID(rs.getInt("CsID")); // return m; // } // con.close(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.ulcs.dao.CustomerDAO.java
public void deleteCustomer(int customerID) { try {//ww w . ja va 2s . c o m String qry = "delete from customer where customerID=:CsID"; AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Customer.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery(qry); query.addEntity(Customer.class); query.setParameter("CsID", customerID); query.executeUpdate(); session.getTransaction().commit(); // Connection con=Teledbc.connector(); // String qry="delete from customer where CsID=?"; // PreparedStatement pst=con.prepareStatement(qry); // pst.setInt(1,customerID); // pst.executeUpdate(); // con.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ulcs.dao.CustomerDAO.java
public void updateCustomer(Customer customer) { try {//from w w w .j ava 2 s . co m String qry = "update customer set customerName=:customerName ,customerAddress=:customerAddress,customerNumber=:customerNumber where customerID=:CsID"; AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Customer.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery(qry); query.addEntity(Customer.class); query.setParameter("CsID", customer.getCustomerID()); query.setParameter("customerName", customer.getCustomerName()); query.setParameter("customerAddress", customer.getCustomerAddress()); query.setParameter("customerNumber", customer.getCustomerNumber()); query.executeUpdate(); session.getTransaction().commit(); // Connection con=Teledbc.connector(); // String qry="update customer set customerName=? ,customerAddress=?,customerNumber=? where CsID=?"; // PreparedStatement pst=con.prepareStatement(qry); // pst.setString(1,customer.getCustomerName()); // pst.setString(2,customer.getCustomerAddress()); // pst.setString(3,customer.getCustomerNumber()); // pst.setInt(4,customer.getCustomerID()); // pst.executeUpdate(); // con.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ulcs.dao.UserDAO.java
public User ValidUser(User user) { try {/*from w ww . j a v a 2 s . com*/ String qry = "Select * from user where userName =:userName and userPassword =:userPassword"; AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(User.class); config.configure("hibernate.cfg.xml"); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery(qry); query.addEntity(User.class); query.setParameter("userName", user.getUserName()); query.setParameter("userPassword", user.getUserPassword()); List rs = query.list(); session.getTransaction().commit(); if (rs != null) { return user; // return (User) rs; } else return null; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.waveerp.registrySystem.java
License:Open Source License
public boolean checkRegistry(String pEntity, String pAppId, String pUserId, String pVarname) { List<Tblregistry> myList = null; boolean bResult = false; try {/*from w w w. java 2s. c om*/ dbServices.begin(); Session session = dbServices.getDataServiceManager().getSession(); String sQuery = "select * from Tblregistry where" + " entity = '" + pEntity + "' and" + " appid = '" + pAppId + "' and" + " userid = '" + pUserId + "' and" + " varname = '" + pVarname + "';"; SQLQuery query = session.createSQLQuery(sQuery); query.addEntity(Tblregistry.class); myList = query.list(); dbServices.commit(); if (myList.size() > 0 && myList != null) { bResult = true; } } catch (Exception e) { dbServices.rollback(); return bResult; } return bResult; }
From source file:com.waveerp.registrySystem.java
License:Open Source License
public String readRegistryDefault(String pEntity, String pAppId, String pUserId, String pVarname, String pDefa) {/*ww w . ja v a 2 s . c o m*/ List<Tblregistry> myList = null; Iterator<Tblregistry> iterator = null; String result = null; if (pDefa == null) { } else { result = pDefa; } try { dbServices.begin(); Session session = dbServices.getDataServiceManager().getSession(); String sQuery = "select * from Tblregistry where" + " entity = '" + pEntity + "' and appid = '" + pAppId + "' and" + " userid = '" + pUserId + "' and varname = '" + pVarname + "';"; SQLQuery query = session.createSQLQuery(sQuery); query.addEntity(Tblregistry.class); myList = query.list(); dbServices.commit(); iterator = myList.iterator(); while (iterator.hasNext()) { Tblregistry registry = (Tblregistry) iterator.next(); String varvalue = (String) registry.getVarvalue(); result = varvalue; } } catch (Exception e) { dbServices.rollback(); result = "FAIL"; } return result; }