List of usage examples for org.hibernate Session clear
void clear();
From source file:com.advdb.footballclub.FootBallClub.java
private void createFactMatch(Session session) { Transaction transaction = null;//from ww w .j av a 2s. c o m try { System.out.println("start createFactMatch."); transaction = session.beginTransaction(); String hqlDC = "from DimCompetition dc"; List result = session.createQuery(hqlDC).list(); result.forEach((object) -> { DimCompetition dimCompetition = (DimCompetition) object; int startYear = dimCompetition.getSeasonStartYear(); int endYear = dimCompetition.getSeasonEndYear(); GregorianCalendar cal = randomYear(startYear, endYear); // createDate(session, gregorianCalendar); if (dimCompetition.getCompetiotionName().equals(COMPETITION_NAME_ARR[0]) || dimCompetition.getCompetiotionName().equals(COMPETITION_NAME_ARR[1])) { int times = randomWithRange(1, 7); //Random opponent String hqlDO = "from DimOpponent do"; List resultDO = session.createQuery(hqlDO).list(); HashMap<Integer, Integer> opponentMap = new HashMap<Integer, Integer>(); int opponentIndex; do { opponentIndex = randBetween(0, resultDO.size()); if (!opponentMap.containsKey(opponentIndex)) { opponentMap.put(opponentIndex, opponentIndex); generateFactMatch(opponentIndex, cal, dimCompetition.getCompetitionKy(), session); //Random tactic //Random player } } while (opponentMap.size() != times); } else if (dimCompetition.getCompetiotionName().equals(COMPETITION_NAME_ARR[2]) || dimCompetition.getCompetiotionName().equals(COMPETITION_NAME_ARR[3])) { //Random opponent String hqlDO = "from DimOpponent do"; List resultDO = session.createQuery(hqlDO).list(); HashMap<Integer, Integer> opponentMap = new HashMap<Integer, Integer>(); int opponentIndex; do { opponentIndex = randBetween(0, resultDO.size()); if (!opponentMap.containsKey(opponentIndex)) { opponentMap.put(opponentIndex, opponentIndex); generateFactMatch(opponentIndex, cal, dimCompetition.getCompetitionKy(), session); } } while (opponentMap.size() != 38); } else { } }); session.flush(); session.clear(); // } transaction.commit(); System.out.println("finish createFactMatch."); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ajar.Controller.GoogleStockDownload.java
public GoogleStockDownload(String symbol, Date start, Date end) { dates = new ArrayList<Date>(); opens = new ArrayList<Double>(); highs = new ArrayList<Double>(); lows = new ArrayList<Double>(); closes = new ArrayList<Double>(); volumes = new ArrayList<Integer>(); // adjcloses = new ArrayList<Double>(); //// https://www.google.com/finance/historical?q=IDX:ABBA&startdate=01+01,+2016&enddate=03+14,+2016&output=csv String url = "https://www.google.com/finance/historical?q=IDX:" + symbol + "&startdate=" + formatter.format(start.getTime()) + "&enddate=" + formatter.format(end.getTime()) + "&output=csv"; try {/*from w w w . j a va2 s .c om*/ URL googlefin = new URL(url); URLConnection data = googlefin.openConnection(); Scanner input = new Scanner(data.getInputStream()); if (input.hasNext()) //Skip line, its just header { input.nextLine(); } // Save to DB Session session = HibernateSessionManager.getSessionFactory().openSession(); session.beginTransaction(); // Start read line while (input.hasNextLine()) { String line = input.nextLine(); // TODO - Correct data to the correct arraylist // Print all result directly to prompt // System.out.println(symbol+","+line); // Afif's property to save into Table DB String str = symbol + "," + line; String strArray[] = str.split(","); TrxStock trx = new TrxStock(); String dtq = strArray[1]; Date dtTrx = df.parse(dtq); trx.setTicklerID(strArray[0]); trx.setTicklerDT(dtTrx); trx.setTicklerOpen(Float.valueOf(strArray[2] + 0)); trx.setTicklerHigh(Float.valueOf(strArray[3] + 0)); trx.setTicklerLow(Float.valueOf(strArray[4] + 0)); trx.setTicklerClose(Float.valueOf(strArray[5] + 0)); trx.setTicklerVol(Float.valueOf(strArray[6])); // trx.setTicklerInt(Float.valueOf(strArray[7])); session.save(trx); for (int i = 0; i < 100000; i++) { if (i % 50 == 0) { //20, same as the JDBC batch size //flush a batch of inserts and release memory: session.flush(); session.clear(); } } } session.getTransaction().commit(); System.out.println("Save to DB Success"); session.close(); } catch (Exception e) { System.err.println(e); } }
From source file:com.ajar.StockDownloader.java
public StockDownloader(String symbol, GregorianCalendar start, GregorianCalendar end) { dates = new ArrayList<GregorianCalendar>(); opens = new ArrayList<Double>(); highs = new ArrayList<Double>(); lows = new ArrayList<Double>(); closes = new ArrayList<Double>(); volumes = new ArrayList<Integer>(); adjcloses = new ArrayList<Double>(); //http://finance.yahoo.com/q/hp?s=ASII.JK&a=09&b=17&c=2000&d=01&e=7&f=2016&g=d //http://real-chart.finance.yahoo.com/table.csv?s=ASII.JK&a=09&b=17&c=2000&d=01&e=7&f=2016&g=d&ignore=.csv // http://real-chart.finance.yahoo.com/table.csv?s=ASII.JK&d=2&e=7&f=2016&g=d&a=9&b=17&c=2000&ignore=.csv // String url = "http://ichart.finance.yahoo.com/table.csv?s=" + symbol String url = "http://real-chart.finance.yahoo.com/table.csv?s=" + symbol + "&a=" + start.get(Calendar.MONTH) + "&b=" + start.get(Calendar.DAY_OF_MONTH) + "&c=" + start.get(Calendar.YEAR) + "&d=" + end.get(Calendar.MONTH) + "&e=" + end.get(Calendar.DAY_OF_MONTH) + "&f=" + end.get(Calendar.YEAR) // + "&g=d&ignore=.csv"; + "&g=d"; try {/* w w w. j a va 2s . c o m*/ URL yahoofinn = new URL(url); URLConnection data = yahoofinn.openConnection(); Scanner input = new Scanner(data.getInputStream()); if (input.hasNext()) //Skip line, its just header { input.nextLine(); } // Save to DB Session session = HibernateSessionManager.getSessionFactory().openSession(); session.beginTransaction(); // Start read line while (input.hasNextLine()) { String line = input.nextLine(); // TODO - Correct data to the correct arraylist // Print all result directly to prompt // System.out.println(symbol+","+line); // Afif's property to save into Table DB String str = symbol + "," + line; String strArray[] = str.split(","); // System.out.println("Save to DB"); TrxStock trx = new TrxStock(); trx.setTicklerID(strArray[0]); trx.setTicklerDT(formatter.parse(strArray[1])); trx.setTicklerOpen(Float.valueOf(strArray[2])); trx.setTicklerHigh(Float.valueOf(strArray[3])); trx.setTicklerLow(Float.valueOf(strArray[4])); trx.setTicklerClose(Float.valueOf(strArray[5])); trx.setTicklerVol(Float.valueOf(strArray[6])); trx.setTicklerInt(Float.valueOf(strArray[7])); session.save(trx); for (int i = 0; i < 100000; i++) { if (i % 50 == 0) { //20, same as the JDBC batch size //flush a batch of inserts and release memory: session.flush(); session.clear(); } } } session.getTransaction().commit(); System.out.println("Save to DB Success"); session.close(); } catch (Exception e) { System.err.println(e); } }
From source file:com.atlanta.educati.daoImp.ApoderadoDaoImp.java
@Override public int update(Apoderado x) { Session sesion = sesionFactory.openSession(); Transaction tx = sesion.beginTransaction(); //Variable de respuesta int r = 0;// ww w . j av a 2 s. c o m try { sesion.clear(); sesion.update(x); tx.commit(); r++; } catch (Exception e) { System.out.println("" + e.getMessage()); tx.rollback(); } finally { sesion.close(); } return r; }
From source file:com.atlanta.educati.daoImp.CursoDaoImp.java
@Override public int update(Curso x) { Session sesion = sesionFactory.openSession(); Transaction tx = sesion.beginTransaction(); //Variable de respuesta int r = 0;/*w ww .jav a 2 s . co m*/ try { sesion.clear(); sesion.update(x); tx.commit(); r++; } catch (Exception e) { System.out.println("" + e.getMessage()); tx.rollback(); } finally { sesion.close(); } return r; }
From source file:com.atlanta.educati.daoImp.DocenteDaoImp.java
@Override public int update(Docente x) { Session sesion = sesionFactory.openSession(); Transaction tx = sesion.beginTransaction(); //Variable de respuesta int r = 0;/*from w ww .j a v a2 s . co m*/ try { sesion.clear(); sesion.update(x); tx.commit(); r++; } catch (Exception e) { System.out.println("" + e.getMessage()); tx.rollback(); } finally { sesion.close(); } return r; }
From source file:com.atlanta.educati.daoImp.EstudianteDaoImp.java
@Override public int update(Estudiante x) { Session sesion = sesionFactory.openSession(); Transaction tx = sesion.beginTransaction(); //Variable de respuesta int r = 0;// w w w . ja va 2 s. co m try { sesion.clear(); sesion.update(x); tx.commit(); r++; } catch (Exception e) { System.out.println("" + e.getMessage()); tx.rollback(); } finally { sesion.close(); } return r; }
From source file:com.atlanta.educati.daoImp.HorarioDaoImp.java
@Override public int update(Horario x) { Session sesion = sesionFactory.openSession(); Transaction tx = sesion.beginTransaction(); //Variable de respuesta int r = 0;// w w w . j a v a2 s . co m try { sesion.clear(); sesion.update(x); tx.commit(); r++; } catch (Exception e) { System.out.println("" + e.getMessage()); tx.rollback(); } finally { sesion.close(); } return r; }
From source file:com.atlanta.educati.daoImp.InstitucionDaoImp.java
@Override public int update(Institucion x) { Session sesion = sesionFactory.openSession(); Transaction tx = sesion.beginTransaction(); //Variable de respuesta int r = 0;/*from w ww .j ava2 s.c o m*/ try { sesion.clear(); sesion.update(x); tx.commit(); r++; } catch (Exception e) { System.out.println("" + e.getMessage()); tx.rollback(); } finally { sesion.close(); } return r; }
From source file:com.atlanta.educati.daoImp.MatriculaDaoImp.java
@Override public int update(Matricula x) { Session sesion = sesionFactory.openSession(); Transaction tx = sesion.beginTransaction(); //Variable de respuesta int r = 0;/*ww w. ja va 2 s. c o m*/ try { sesion.clear(); sesion.update(x); tx.commit(); r++; } catch (Exception e) { System.out.println("" + e.getMessage()); tx.rollback(); } finally { sesion.close(); } return r; }