List of usage examples for org.hibernate Query setCharacter
@Deprecated @SuppressWarnings("unchecked") default Query<R> setCharacter(String name, char val)
From source file:br.com.ln.hibernate.Postgress.java
public static List<LnMenu> grabMenu(Character menChAtivo) { Session session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); Transaction tx = session.beginTransaction(); List<LnMenu> listMenu = null; try {/*from w w w .j a va2 s. c o m*/ Query query = session.getNamedQuery("LnMenu.findAllAtivo"); query.setCharacter("menChAtivo", 'S'); listMenu = (List<LnMenu>) query.list(); } finally { if (session != null && session.isOpen()) { session.close(); } } return listMenu; }
From source file:br.com.ln.hibernate.Postgress.java
public static LnPerfil grabPerfil(Integer perInCodigo, Character perChAtivo) { Session session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); Transaction tx = session.beginTransaction(); LnPerfil lnPerfil = null;//from www . j av a 2s .c om try { Query query = session.getNamedQuery("LnPerfil.findByPerInCodigoPerChAtivo"); query.setInteger("perInCodigo", perInCodigo); query.setCharacter("perChAtivo", perChAtivo); List l = query.list(); if (l != null && !l.isEmpty()) { lnPerfil = (LnPerfil) l.get(0); } } finally { if (session != null && session.isOpen()) { session.close(); } } return lnPerfil; }
From source file:br.com.ln.hibernate.Postgress.java
public static List<LnPerfil> grabListPerfilAtivo(Character perChAtivo) { Session session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); Transaction tx = session.beginTransaction(); List<LnPerfil> listPerfil; try {/*w w w.j av a 2 s . c om*/ Query query = session.getNamedQuery("LnPerfil.findByPerChAtivo"); query.setCharacter("perChAtivo", perChAtivo); listPerfil = query.list(); tx.commit(); } finally { if (session != null && session.isOpen()) { session.close(); } } return listPerfil; }
From source file:br.com.ln.hibernate.Postgress.java
public static List<LnModulo> grabListModuloAtivo(Character modChAtivo) { Session session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); Transaction tx = session.beginTransaction(); List<LnModulo> listlnModulo = null; try {/*w w w .j av a 2s. co m*/ Query query = session.getNamedQuery("LnModulo.findAllAtivo"); query.setCharacter("modChAtivo", modChAtivo); List l = query.list(); if (l != null && !l.isEmpty()) { listlnModulo = l; } } finally { if (session != null && session.isOpen()) { session.close(); } } return listlnModulo; }
From source file:br.com.ln.hibernate.Postgress.java
public static List<LnCliente> grabListCliente(Character sTipo) { Session session = null;// w w w . j a v a 2s .c om Transaction tx = null; List<LnCliente> listCliente = null; try { session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); tx = session.beginTransaction(); Query query = session.getNamedQuery("LnCliente.findByCliChTipo"); query.setCharacter("cliChTipo", sTipo); listCliente = query.list(); tx.commit(); } finally { if (session != null && session.isOpen()) { session.close(); } } return listCliente; }
From source file:celepsa.rrcc.da.DocumentoDA.java
public boolean eliminarDocumento(Tmdocumento objDocumento) throws Exception { // eliminar con hibernate try {//from ww w. j ava 2 s.c om Query query = session.createQuery(" update Tmdocumento set eliminado= :eliminado where id = :id "); query.setCharacter("eliminado", objDocumento.getEliminado()); query.setInteger("id", objDocumento.getId()); return query.executeUpdate() > 0; } catch (NumberFormatException | HibernateException e) { logger.error(e.getMessage()); e.printStackTrace(); throw e; } }
From source file:com.cloud.bridge.util.QueryHelper.java
License:Open Source License
public static void bindParameters(Query query, Object[] params) { int pos = 0;/*w w w. j a v a 2s.co m*/ if (params != null && params.length > 0) { for (Object param : params) { if (param instanceof Byte) query.setByte(pos++, ((Byte) param).byteValue()); else if (param instanceof Short) query.setShort(pos++, ((Short) param).shortValue()); else if (param instanceof Integer) query.setInteger(pos++, ((Integer) param).intValue()); else if (param instanceof Long) query.setLong(pos++, ((Long) param).longValue()); else if (param instanceof Float) query.setFloat(pos++, ((Float) param).floatValue()); else if (param instanceof Double) query.setDouble(pos++, ((Double) param).doubleValue()); else if (param instanceof Boolean) query.setBoolean(pos++, ((Boolean) param).booleanValue()); else if (param instanceof Character) query.setCharacter(pos++, ((Character) param).charValue()); else if (param instanceof Date) query.setDate(pos++, (Date) param); else if (param instanceof Calendar) query.setCalendar(pos++, (Calendar) param); else if (param instanceof CalendarDateParam) query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue()); else if (param instanceof TimestampParam) query.setTimestamp(pos++, ((TimestampParam) param).timestampValue()); else if (param instanceof TimeParam) query.setTime(pos++, ((TimeParam) param).timeValue()); else if (param instanceof String) query.setString(pos++, (String) param); else if (param instanceof TextParam) query.setText(pos++, ((TextParam) param).textValue()); else if (param instanceof byte[]) query.setBinary(pos++, (byte[]) param); else if (param instanceof BigDecimal) query.setBigDecimal(pos++, (BigDecimal) param); else if (param instanceof BigInteger) query.setBigInteger(pos++, (BigInteger) param); else if (param instanceof Locale) query.setLocale(pos++, (Locale) param); else if (param instanceof EntityParam) query.setEntity(pos++, ((EntityParam) param).entityValue()); else if (param instanceof Serializable) query.setSerializable(pos++, (Serializable) param); else query.setEntity(pos++, param); } } }
From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java
License:Open Source License
public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters, final boolean cacheable) { return executeListResult(ContentKey.class, new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query compiled = session.createQuery(hqlQuery); compiled.setCacheable(cacheable); for (String key : parameters.keySet()) { Object value = parameters.get(key); if (value instanceof Date) { compiled.setTimestamp(key, (Date) value); } else if (value instanceof String) { compiled.setString(key, (String) value); } else if (value instanceof Boolean) { compiled.setBoolean(key, (Boolean) value); } else if (value instanceof Long) { compiled.setLong(key, (Long) value); } else if (value instanceof Integer) { compiled.setInteger(key, (Integer) value); } else if (value instanceof Byte) { compiled.setByte(key, (Byte) value); } else if (value instanceof byte[]) { compiled.setBinary(key, (byte[]) value); } else if (value instanceof Float) { compiled.setFloat(key, (Float) value); } else if (value instanceof Double) { compiled.setDouble(key, (Double) value); } else if (value instanceof BigDecimal) { compiled.setBigDecimal(key, (BigDecimal) value); } else if (value instanceof Short) { compiled.setShort(key, (Short) value); } else if (value instanceof BigInteger) { compiled.setBigInteger(key, (BigInteger) value); } else if (value instanceof Character) { compiled.setCharacter(key, (Character) value); } else { compiled.setParameter(key, value); }//ww w .j av a2s.com } final List result = compiled.list(); LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size()); for (Object value : result) { if (value instanceof ContentKey) { distinctContentKeySet.add((ContentKey) value); } else { Object[] valueList = (Object[]) value; distinctContentKeySet.add(((ContentKey) valueList[0])); } } List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size()); distinctContentKeyList.addAll(distinctContentKeySet); return distinctContentKeyList; } }); }
From source file:com.netsteadfast.greenstep.base.dao.BaseDAO.java
License:Apache License
/** * for public QueryResult getList... doInHibernate * @param query JPA-Style : from TB_ACCOUNT where account = ?0 * @param position JPA-Style : "0", "1" ..... * @param params//from ww w . j a va2 s .c om */ @SuppressWarnings("rawtypes") private void setQueryParams(Query query, String position, Object params) { if (params instanceof java.lang.String) { query.setString(position, (java.lang.String) params); return; } if (params instanceof java.lang.Character) { query.setCharacter(position, (java.lang.Character) params); return; } if (params instanceof java.lang.Double) { query.setDouble(position, (java.lang.Double) params); return; } if (params instanceof java.lang.Byte) { query.setByte(position, (java.lang.Byte) params); return; } if (params instanceof java.lang.Integer) { query.setInteger(position, (java.lang.Integer) params); return; } if (params instanceof java.lang.Long) { query.setLong(position, (java.lang.Long) params); return; } if (params instanceof java.lang.Boolean) { query.setBoolean(position, (java.lang.Boolean) params); return; } if (params instanceof java.math.BigDecimal) { query.setBigDecimal(position, (java.math.BigDecimal) params); return; } if (params instanceof java.util.Date) { query.setDate(position, (java.util.Date) params); return; } if (params instanceof java.util.List) { List listParams = (List) params; this.setQueryParamsOfList(query, position, listParams); return; } }
From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java
License:Apache License
/** * Get a list of items for a specified repository by first character of the name * /* w ww . j a v a 2 s. c om*/ * @param rowStart - Start row to fetch the data from * @param maxResulsts - maximum number of results to fetch * @param repositoryId - id of the repository to get items * @param firstChar - first character that the name should have * @param orderType - The order to sort by (asc/desc) * * @return List of institutional items */ @SuppressWarnings("unchecked") public List<InstitutionalItem> getRepositoryItemsByChar(final int rowStart, final int maxResults, final Long repositoryId, final char firstChar, final OrderType orderType) { Session session = hbCrudDAO.getSessionFactory().getCurrentSession(); Query q = null; if (orderType.equals(OrderType.DESCENDING_ORDER)) { q = session.getNamedQuery("getRepositoryItemsByCharOrderDesc"); } else { q = session.getNamedQuery("getRepositoryItemsByCharOrderAsc"); } q.setLong("repositoryId", repositoryId); q.setCharacter("firstChar", Character.toLowerCase(firstChar)); q.setFirstResult(rowStart); q.setMaxResults(maxResults); q.setFetchSize(maxResults); return q.list(); }