List of usage examples for org.hibernate Session clear
void clear();
From source file:com.sigaf.dao.EmpleadoDao.java
@Override public void update(TEmpleado empleado) { Session session = this.sessionFactory.openSession(); session.beginTransaction();/*from w w w . j a va 2s . c om*/ session.update(empleado); session.getTransaction().commit(); session.clear(); }
From source file:com.sigaf.dao.EntidadProyectoDao.java
@Override public void update(TEntidadProyecto entidad) { Session session = this.sessionFactory.openSession(); session.beginTransaction();/*from www.j a v a2s . c om*/ session.update(entidad); session.getTransaction().commit(); session.clear(); }
From source file:com.sigaf.dao.GarantiaDao.java
@Override public void update(TGarantia entidad) { Session session = this.sessionFactory.openSession(); session.beginTransaction();//w w w .j a va 2 s .c o m session.update(entidad); session.getTransaction().commit(); session.clear(); }
From source file:com.sigaf.dao.MunicipioEmpleadoDao.java
@Override public void update(TMunicipioEmpleado municipioEmpleado) { Session session = sessionFactory.openSession(); session.beginTransaction();/* ww w. ja va 2 s . co m*/ session.update(municipioEmpleado); session.getTransaction().commit(); session.clear(); session.close(); }
From source file:com.springskeleton.dao.impl.BaseDaoImpl.java
@Override @Transactional(value = "springSkeletonTransactionManager", propagation = Propagation.REQUIRED) public void clear() { Session session = sessionFactory.getCurrentSession(); session.clear(); }
From source file:com.tecnoven.notify.ui.NotifyBulkNotificationDispatch.java
@SuppressWarnings("unchecked") private void bulk() { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.outputText.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Set<String> processedIds = new HashSet<String>(); ArrayList<String[]> listError = new ArrayList<String[]>(); int cont = 0; if (fileSelected != null) { Session session = ConnectionDB.getInstance().getSession(); this.outputText.setText("Iniciando proceso de carga masiva..."); try {//from w ww .j a v a2 s. com FileUtil util = new FileUtil(this.fileSelected); String token = util.readFromFile(); TemplateData template = (TemplateData) session.get(TemplateData.class, new Long(((TemplateData) this.catalogObject).getId())); Transaction tx = (Transaction) session.beginTransaction(); NotificationData newNotification = new NotificationData(); newNotification.setCreated(new java.util.Date()); newNotification.setTemplate(template); String[] services = LicenseManager.getInstance().getLicense().getListSupportedServices(); if (services.length > 1) { newNotification.setType((String) typeList.getSelectedItem()); } else { newNotification.setType(services[0]); } session.save(newNotification); session.flush(); this.outputText.append("\n"); Criteria criteria = session.createCriteria(TagData.class); criteria.add(Expression.eq("templateDefinition", template.getDefinition())); criteria.add(Expression.eq("pk", true)); List<TagData> results = criteria.list(); TagData pk = results.iterator().next(); int sizeTags = template.getDefinition().getTags().size(); ArrayList<TagData> unsorted = new ArrayList<TagData>(template.getDefinition().getTags()); Collections.sort(unsorted, new TagComparator()); while (token != null) { String[] tokens = FileUtil.split(token, Constants.TOKEN_SEPARATOR); if (sizeTags == tokens.length) { String pkValue = null; if (newNotification.getType().equals(Constants.EMAIL_SERVICE)) { pkValue = this.appendDomainToId(tokens[pk.getTagOrder() - 1]); } else { pkValue = tokens[pk.getTagOrder() - 1]; } if (!processedIds.contains(pkValue)) { Iterator<TagData> tags = unsorted.iterator(); try { boolean inserted = false; for (; tags.hasNext();) { TagData tag = tags.next(); RecordData record = new RecordData(); String value = tokens[tag.getTagOrder() - 1]; if (tag.getTagId() == pk.getTagId()) { value = pkValue; } record.setPKValue(pkValue); record.setTag(tag); record.setValue(value); record.setNotification(newNotification); session.save(record); inserted = true; } if (inserted) { cont++; session.flush(); processedIds.add(pkValue); } } catch (Exception e) { listError.add(this.addMessageError(tokens, e.getMessage())); } } else { listError.add(this.addMessageError(tokens, "Registro Duplicado")); } } else { if (tokens.length > 0) listError.add(this.addMessageError(tokens, "Nro. de columnas invalido")); } token = util.readFromFile(); String number = "[" + (cont) + "]"; if (cont > 1) { number = "[" + (cont - 1) + "]"; if (outputText.getText().contains(number)) { int start = outputText.getText().indexOf(number); int length = number.length(); if (start >= 0) { number = "[" + cont + "]"; outputText.replaceRange(number, start, start + length); } } } else { String processingMessage = "Procesando " + number + " registros"; if (this.outputText.getText().contains(processingMessage)) { this.outputText.append(processingMessage); } } } if (cont > 0) { this.outputText.append("\n Finalizando proceso de carga masiva..."); tx.commit(); Thread.sleep(5000); this.outputText.setText("Fueron procesados (" + cont + ") registros" + '\n'); } else { tx.rollback(); } if (listError.size() > 0) { this.outputText.append("El(Los) siguiente(s) registro(s) no fue(ron) procesado(s) " + '\n'); for (String[] rec : listError) { this.outputText .append("'" + ((rec.length > 0) ? rec[0] + "'" + " causa = " + rec[rec.length - 1] : "[registro en blanco]") + '\n'); } } } catch (Exception e) { JOptionPane.showConfirmDialog( this, "Ha ocurrido un error en el procesamiento del archivo :[" + e.getLocalizedMessage() + "] " + e.getMessage(), "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } finally { session.flush(); session.clear(); } } else { JOptionPane.showConfirmDialog(this, "Debe seleccionar un archivo para procesar", "Selecci\u00f3n Inv\u00e1lida", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } this.executeProcess.setEnabled(true); this.setCursor(Cursor.getDefaultCursor()); this.outputText.setCursor(Cursor.getDefaultCursor()); }
From source file:com.timesheet.data.SqlUtilsImp.java
@Override public void insetIntoProjectUserAss(Integer projectId, String userList) { Session session = sessionFactory.getCurrentSession(); //Transaction tx = session.beginTransaction(); String[] userListArr = userList.split(","); if (userListArr.length > 0) { for (String userId : userListArr) { if (StringUtils.isNumeric(userId)) { String sql = "INSERT INTO ProjectUser(projectId, userId) VALUES(:projectId, :userId)"; //System.out.println("Inide manual sql @@@@@@@@@@@@"+projectId); Query query = session.createSQLQuery(sql); query.setInteger("projectId", projectId); query.setInteger("userId", Integer.parseInt(userId)); query.executeUpdate();/* www .jav a 2 s .co m*/ session.flush(); session.clear(); } } } //tx.commit(); //session.close(); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.timesoft.kaitoo.ws.hibernate.TransactionalProcessor.java
/** * DOCUMENT ME!// w w w. ja va 2 s .c om * */ public final void process() { SessionFactory factory = new Configuration().configure().buildSessionFactory(); Session session = factory.openSession(); /** * Session::beginTransaction() can be called twice or more, so no need * to check whether this is the ROOT context or not. */ Transaction tx = session.beginTransaction(); try { if (logger.isDebugEnabled()) { logger.debug("About to process user transaction."); } if (CONTEXT.get().size() == 1) { logger.debug("Current transaction is ROOT context, clean it up before using."); session.clear(); } process(session, tx); if (logger.isDebugEnabled()) { logger.debug("About to commit transaction."); } session.flush(); if (CONTEXT.get().size() == 1) { tx.commit(); if (logger.isDebugEnabled()) { logger.debug("Transaction committed successfully."); } } else { logger.debug("Current transaction is not the ROOT one, commit pending."); } } catch (final Exception e) { List<TransactionalProcessor> stack = CONTEXT.get(); logger.error(e.getMessage(), e); if (stack.size() == 1) { tx.rollback(); logger.debug("It's ROOT context, transaction rolled back."); } // if (e instanceof JDBCException) { // JDBCException x = (JDBCException) e; // // throw x.getSQLException(); // } // // throw e; } finally { List<TransactionalProcessor> stack = CONTEXT.get(); if (stack.remove(this)) { if (logger.isDebugEnabled()) { logger.debug(String.format("Total %1$s left on the stack: %2$d", getClass().toString(), stack.size())); } } else { logger.warn(String.format("%1$s not found on the stack (total: %2$d).", getClass().toString(), stack.size())); } if (stack.isEmpty()) { session.clear(); session.close(); logger.debug("It's ROOT context, Hibernate session cleaned up."); } else { logger.debug("Not a ROOT context, Hibernate session cleanup ignored."); } } }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
License:Open Source License
@Override public int addTransactionDetails(Motransaction theMotransaction, Session aTransactionSession, String insertStatus) throws BankingException { Transaction aTransaction;/* ww w .j ava2 s.c om*/ int motransid = 0; MoAccount aMoaccount = new MoAccount(); Motransaction amot = new Motransaction(); try { if (insertStatus.equals("rollback")) { amot = (Motransaction) aTransactionSession.get(Motransaction.class, theMotransaction.getMoTransactionId()); theMotransaction.setRxMasterId(amot.getRxMasterId()); theMotransaction.setDescription(amot.getDescription()); theMotransaction.setReference(amot.getReference()); motransid = (Integer) aTransactionSession.save(theMotransaction); } else if (insertStatus.equals("rollbackfromvoid")) { amot = (Motransaction) aTransactionSession.get(Motransaction.class, theMotransaction.getMoTransactionId()); theMotransaction.setRxMasterId(amot.getRxMasterId()); theMotransaction.setReference(amot.getReference()); motransid = (Integer) aTransactionSession.save(theMotransaction); } else { if (theMotransaction.getMoTransactionTypeId() == 2) { aMoaccount = (MoAccount) aTransactionSession.get(MoAccount.class, theMotransaction.getMoAccountId()); /*if(aMoaccount.getNextCheckNumber()!=Integer.parseInt(theMotransaction.getReference())) { aMoaccount.setNextCheckNumber(Integer.parseInt(theMotransaction.getReference())+1); theMotransaction.setReference(""+Integer.parseInt(theMotransaction.getReference())); } else { aMoaccount.setNextCheckNumber(Integer.parseInt(theMotransaction.getReference())+1); theMotransaction.setReference(""+Integer.parseInt(theMotransaction.getReference())); }*/ aMoaccount.setNextCheckNumber(Integer.parseInt(theMotransaction.getReference()) + 1); theMotransaction.setReference("" + Integer.parseInt(theMotransaction.getReference())); motransid = (Integer) aTransactionSession.save(theMotransaction); BigDecimal substractions = aMoaccount.getSubtractions(); substractions = substractions.add(theMotransaction.getAmount()); aMoaccount.setSubtractions(substractions); aTransactionSession.update(aMoaccount); } else { motransid = (Integer) aTransactionSession.save(theMotransaction); } } } catch (Exception excep) { itsLogger.error(excep.getMessage(), excep); BankingException aBankingException = new BankingException(excep.getMessage(), excep); throw aBankingException; } finally { aTransactionSession.flush(); aTransactionSession.clear(); } return motransid; }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
License:Open Source License
@Override public boolean updateTransactionDetails1(Motransaction theMotransaction, Session aSession) throws BankingException { Motransaction aMotransaction = null; try {// ww w . j a v a 2 s. c o m aMotransaction = (Motransaction) aSession.get(Motransaction.class, theMotransaction.getMoTransactionId()); aMotransaction.setStatus(theMotransaction.getStatus()); aSession.update(aMotransaction); } catch (Exception e) { itsLogger.error(e.getMessage(), e); BankingException aBankingException = new BankingException(e.getMessage(), e); throw aBankingException; } finally { aSession.flush(); aSession.clear(); } return true; }