List of usage examples for org.hibernate Session createSQLQuery
@Override NativeQuery createSQLQuery(String queryString);
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.PhysicalMachineDAOHibernate.java
License:Open Source License
@Override public void updateUsedResourcesByPhysicalMachine(final Integer idPhysicalMachine) { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final String update = "update physicalmachine p, " + "(SELECT hy.idPhysicalMachine, IFNULL(SUM(vm.ram),0) ram, IFNULL(SUM(vm.cpu),0) cpu" + "FROM virtualmachine vm right join hypervisor hy on vm.idHypervisor = hy.id, " + "physicalmachine pm " + "WHERE (vm.state is null or vm.state != 'NOT_DEPLOYED') AND pm.idPhysicalMachine = hy.idPhysicalMachine " + "AND pm.idPhysicalMachine = :idPhysicalMachine " + "group by hy.idPhysicalMachine) x " + "set p.ramused = x.ram, p.cpuused = x.cpu where p.idPhysicalMachine = x.idPhysicalMachine "; final Query pmQuery = session.createSQLQuery(update); pmQuery.setInteger("idPhysicalMachine", idPhysicalMachine); pmQuery.executeUpdate();/*from www.jav a 2s.c o m*/ }
From source file:com.abiquo.abiserver.persistence.dao.user.hibernate.UserDAOHibernate.java
License:Open Source License
@Override public Object[] getCurrentUserCredentials(String user, String auth) { Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); Query query = session .createSQLQuery("select user, password from user where user = :name and authType = :auth"); query.setString("name", user); query.setString("auth", auth); return (Object[]) query.uniqueResult(); }
From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualDataCenterDAOHibernate.java
License:Open Source License
public long getCurrentStorageAllocated(int virtualDatacenterId) { Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); BigDecimal storage = (BigDecimal) session.createSQLQuery(SUM_VOLUMES_RESOURCES) .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult(); return storage == null ? 0 : storage.longValue() * MB_TO_BYTES; }
From source file:com.abiquo.abiserver.persistence.dao.virtualappliance.hibernate.VirtualDataCenterDAOHibernate.java
License:Open Source License
public long getCurrentPublicIpAllocated(int virtualDatacenterId) { Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); BigInteger publicIps = (BigInteger) session.createSQLQuery(COUNT_PUBLIC_IP_RESOURCES) .setParameter("virtualDatacenterId", virtualDatacenterId).uniqueResult(); return publicIps == null ? 0 : publicIps.longValue(); }
From source file:com.action.ExportAction.java
public void beforeExport() throws IOException { String sql = "select distinct(table_code),table_name from jq_zhibiao_table"; Session session = sessionFactory.getCurrentSession(); List<Object[]> list = session.createSQLQuery(sql).list(); Map map = null;/*from w w w . jav a 2s . co m*/ ArrayList rsList = new ArrayList(); for (Object[] object : list) { map = new HashMap(); map.put("table_code", (String) object[0]); map.put("table_name", (String) object[1]); rsList.add(map); } JSONArray jo = JSONArray.fromObject(rsList); json = jo.toString(); ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8"); ServletActionContext.getResponse().getWriter().print(json); }
From source file:com.action.JsonAction.java
public void getDuizhaoJson() throws Exception { String sql = ""; if (jq_table_code != null && !("".equals(jq_table_code))) { sql = "select table_name,col_name,iufoTbName,iufoColName from jq_zhibiao_table where table_code='" + jq_table_code + "'"; } else {/*from w w w . j ava 2s. com*/ sql = "select table_name,col_name,iufoTbName,iufoColName from jq_zhibiao_table"; } Session session = sessionFactory.getCurrentSession(); List<Object[]> list = session.createSQLQuery(sql).list(); Map map = null; ArrayList rsList = new ArrayList(); for (Object[] object : list) { map = new HashMap(); map.put("table_name", (String) object[0]); map.put("col_name", (String) object[1]); map.put("iufoTbName", (String) object[2]); map.put("iufoColName", (String) object[3]); rsList.add(map); } JSONArray jo = JSONArray.fromObject(rsList); String json = jo.toString(); ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8"); ServletActionContext.getResponse().getWriter().print(json); }
From source file:com.action.JsonAction.java
public void iufoGetDropdownData() throws IOException { Session session = sessionFactory.getCurrentSession(); String sql = ""; Map map = null;// w w w. j av a2 s .co m ArrayList rsList = new ArrayList(); String json = ""; if ("0".equals(iufo_table_code)) { sql = "select distinct(table_code),table_name from iufo_zhibiao_table"; List<Object[]> list = session.createSQLQuery(sql).list(); rsList = new ArrayList(); for (Object[] object : list) { map = new HashMap(); map.put("table_code", (String) object[0]); map.put("table_name", (String) object[1]); rsList.add(map); } System.out.println("count:" + rsList.size()); JSONArray jo = JSONArray.fromObject(rsList); json = jo.toString(); } else { sql = "select * from iufo_zhibiao_table where table_code='" + iufo_table_code + "'"; List<Object[]> list = session.createSQLQuery(sql).list(); rsList = new ArrayList(); for (Object[] object : list) { map = new HashMap(); map.put("id", (BigDecimal) object[0]); map.put("table_code", (String) object[1]); map.put("table_name", (String) object[2]); map.put("col_code", (String) object[3]); map.put("col_name", (String) object[4]); map.put("col_index", (BigDecimal) object[5]); map.put("col_type", (String) object[6]); rsList.add(map); } JSONArray jo = JSONArray.fromObject(rsList); json = jo.toString(); } ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8"); ServletActionContext.getResponse().getWriter().print(json); }
From source file:com.action.JsonAction.java
public void jqGetDropdownData() throws IOException { if (jq_table_code == null || "".equals(jq_table_code)) { jq_table_code = "0"; }// ww w . ja v a 2 s . co m Session session = sessionFactory.getCurrentSession(); String sql = ""; Map map = null; ArrayList rsList = null; String json = ""; if ("0".equals(jq_table_code)) { sql = "select distinct(table_code),table_name from jq_zhibiao_table"; List<Object[]> list = session.createSQLQuery(sql).list(); rsList = new ArrayList(); for (Object[] object : list) { map = new HashMap(); map.put("table_code", (String) object[0]); map.put("table_name", (String) object[1]); rsList.add(map); } Gson gson = new Gson(); json = gson.toJson(rsList); System.out.println("json=" + json); } else { sql = "select * from jq_zhibiao_table where table_code='" + jq_table_code + "'"; List<Object[]> list = session.createSQLQuery(sql).list(); rsList = new ArrayList(); for (Object[] object : list) { map = new HashMap(); map.put("id", (BigDecimal) object[0]); map.put("table_code", (String) object[1]); map.put("table_name", (String) object[2]); map.put("col_code", (String) object[3]); map.put("col_name", (String) object[4]); map.put("col_index", (BigDecimal) object[5]); map.put("col_type", (String) object[6]); rsList.add(map); } Gson gson = new Gson(); json = gson.toJson(rsList); } ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8"); ServletActionContext.getResponse().getWriter().print(json); }
From source file:com.admin.product.Bars.java
@Override public List get() { Session s = HibernateUtil.currentSession(); HibernateUtil.beginTransaction();/*from w w w . j a v a2 s . c o m*/ String sql = "select * from bar"; List<bar> list = s.createSQLQuery(sql).addEntity(bar.class).list(); //System.out.println(hql); HibernateUtil.commitTransaction();//?? HibernateUtil.closeSession(); return list; }
From source file:com.admin.product.Bars.java
@Override public boolean changeStatus(String status, String id) { Session s = HibernateUtil.currentSession(); HibernateUtil.beginTransaction();/*from ww w . ja v a 2 s . co m*/ //String hql = "insert into user(user_name,password,mail,register_date,pic_id) " + "values('?','?','?',SYSDATE(),?)"; //List<user> list = s.createQuery(hql).setString(0, name).setString(1, pass).setString(2, mail).setString(3, pic_id).list(); String sql = "update bar set available = ? where bar_id = ?"; int back = s.createSQLQuery(sql).setString(0, status).setString(1, id).executeUpdate(); HibernateUtil.commitTransaction();//?? HibernateUtil.closeSession(); return back > 0; }