List of usage examples for org.hibernate Query list
List<R> list();
From source file:Albaran.java
public static List queryAlbaran(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From Albaran as Albaran"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {//from ww w . j ava 2 s .com Query query = session.createQuery(sb.toString()); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:Albaran.java
public static List queryAlbaran(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From Albaran as Albaran"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try {/*from ww w . j a v a2 s.c o m*/ Query query = session.createQuery(sb.toString()); query.setLockMode("Albaran", lockMode); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } }
From source file:NewJFrame.java
private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed String pass = new String(passField.getPassword()); if (!logField.getText().trim().equals("") && pass.length() > 0) { loginError.setVisible(false);/*from ww w .java2 s . c o m*/ try { session = NewHibernateUtil.getSessionFactory().openSession(); List uzytkownicy; session.beginTransaction(); Query query = session.createQuery( "from Klient where login is '" + logField.getText() + "' and haslo is '" + pass + "'"); uzytkownicy = query.list(); session.getTransaction().commit(); if (!uzytkownicy.isEmpty()) { ROLE = 0; loggedId = ((Klient) uzytkownicy.get(0)).getIdKlienta(); loginPanel.setVisible(false); showMovies(); moviesPanel.setVisible(true); } else { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); query = session.createQuery("from Pracownik where login is '" + logField.getText() + "' and haslo is '" + pass + "'"); uzytkownicy = query.list(); if (!uzytkownicy.isEmpty()) { Pracownik p = (Pracownik) uzytkownicy.get(0); if (p.getIdStanowiska() == 1) { ROLE = 1; showMovies(); moviesPanel.setVisible(true); } else { ROLE = 2; setVisibilities(); showTransactions(); transactionPanel.setVisible(true); } loggedId = ((Pracownik) uzytkownicy.get(0)).getIdPracownika(); loginPanel.setVisible(false); } loginError.setVisible(true); } } catch (HibernateException he) { he.printStackTrace(); } } setVisibilities(); }
From source file:NewJFrame.java
private void addMovieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMovieActionPerformed // TODO add your handling code here: if (!addMoviePanel.isVisible()) { hideAll();//ww w. ja v a 2 s.c om addMoviePanel.setVisible(true); List carriers = null, directors = null, genres = null; newMovieCarrier.removeAllItems(); session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query q = session.createQuery("from Nosnik order by idNosnika"); carriers = q.list(); session.getTransaction().commit(); for (Object nosnik : carriers) { newMovieCarrier.addItem(((Nosnik) nosnik).getTyp()); } newMovieDirector.removeAllItems(); session.beginTransaction(); q = session.createQuery("from Rezyser order by idRezysera"); directors = q.list(); session.getTransaction().commit(); for (Object rezyser : directors) { newMovieDirector.addItem(((Rezyser) rezyser).getImie() + " " + ((Rezyser) rezyser).getNazwisko()); } newMovieGenre.setListData(new String[0]); DefaultListModel listModel = new DefaultListModel(); listModel.removeAllElements(); session.beginTransaction(); q = session.createQuery("from Gatunek order by idGatunku"); genres = q.list(); session.getTransaction().commit(); for (Object gatunek : genres) { listModel.addElement(((Gatunek) gatunek).getIdGatunku() + ". " + ((Gatunek) gatunek).getNazwa()); } newMovieGenre.setModel(listModel); session.close(); } }
From source file:NewJFrame.java
private void reloadRemoveMoviesTable() { removeMoviePanel.setVisible(true);/*from w w w. j a v a2 s . co m*/ session = NewHibernateUtil.getSessionFactory().openSession(); List moviesList = null, directorList = null; removeMovieTable.removeAll(); try { session.beginTransaction(); Query q = session.createQuery("from Film"); moviesList = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); } finally { session.close(); } Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Tytu"); tableHeaders.add("Rok Produkcji"); tableHeaders.add("Reyser"); tableHeaders.add("Nonik"); tableHeaders.add("Dostpno"); if (!moviesList.isEmpty()) { session = NewHibernateUtil.getSessionFactory().openSession(); Film film; session.beginTransaction(); Query q; for (Object o : moviesList) { film = (Film) o; Vector<Object> oneRow = new Vector<>(); q = session.createQuery("from Rezyser a where a.idRezysera IS " + film.getIdRezysera().toString()); directorList = q.list(); q = session.createQuery("from Nosnik a where a.idNosnika IS " + film.getIdNosnika().toString()); oneRow.add(film.getIdFilmu()); oneRow.add(film.getTytul()); oneRow.add(film.getRokProdukcji()); oneRow.add(((Rezyser) (directorList.get(0))).getNazwisko()); oneRow.add(((Nosnik) q.list().get(0)).getTyp()); if (film.getIlosc() > 0) { oneRow.add("Dostpny"); } else { oneRow.add("Niedostpny"); } tableData.add(oneRow); } session.getTransaction().commit(); removeMovieTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); removeMovieTable.removeColumn(removeMovieTable.getColumnModel().getColumn(0)); session.close(); } }
From source file:NewJFrame.java
private void showTransactions() { List transactionList = null, filmList = null; session = NewHibernateUtil.getSessionFactory().openSession(); try {/* ww w . ja v a 2 s . co m*/ session.beginTransaction(); Query q = session.createQuery("from Transakcja where idPracownika is NULL"); transactionList = q.list(); session.getTransaction().commit(); Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Id Klienta"); tableHeaders.add("Tytu Filmu"); tableHeaders.add("Data Transakcji"); tableHeaders.add("Typ"); if (!transactionList.isEmpty()) { session = NewHibernateUtil.getSessionFactory().openSession(); Transakcja transakcja; session.beginTransaction(); for (Object o : transactionList) { transakcja = (Transakcja) o; Vector<Object> oneRow = new Vector<>(); q = session.createQuery("from Film a where a.idFilmu IS " + transakcja.getIdFilmu().toString()); filmList = q.list(); oneRow.add(transakcja.getIdTransakcji()); oneRow.add(transakcja.getIdKlienta()); oneRow.add(((Film) filmList.get(0)).getTytul()); oneRow.add(transakcja.getDataTransakcji()); if (transakcja.getTyp().equals("WYP")) { oneRow.add("Wypoyczenie"); } else { oneRow.add("Zwrot"); } tableData.add(oneRow); } } transactionTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); transactionTable.removeColumn(transactionTable.getColumnModel().getColumn(0)); session.close(); } catch (HibernateException he) { he.printStackTrace(); } }
From source file:NewJFrame.java
private void reloadRemoveGenresTable() { removeGenrePanel.setVisible(true);//from w w w. j a v a 2 s . c o m session = NewHibernateUtil.getSessionFactory().openSession(); List genres = null; removeGenreTable.removeAll(); try { session.beginTransaction(); Query q = session.createQuery("from Gatunek"); genres = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { } finally { session.close(); } Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Gatunek"); if (!genres.isEmpty()) { Gatunek gatunek; for (Object o : genres) { gatunek = (Gatunek) o; Vector<Object> oneRow = new Vector<>(); oneRow.add(gatunek.getIdGatunku()); oneRow.add(gatunek.getNazwa()); tableData.add(oneRow); } removeGenreTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); } }
From source file:NewJFrame.java
private void moviesTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_moviesTableMouseClicked if (evt.getClickCount() == 2 && !evt.isConsumed()) { evt.consume();// w ww .j a va2 s. c o m Film film = new Film(); Rezyser rezyser = new Rezyser(); List gatunki = null; int id = Integer .parseInt(moviesTable.getModel().getValueAt(moviesTable.getSelectedRow(), 0).toString()); try { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query q = session.createQuery("from Film where idFilmu IS " + id); film = (Film) q.list().get(0); q = session.createQuery("from Rezyser where idRezysera IS " + film.getIdRezysera()); rezyser = (Rezyser) q.list().get(0); q = session.createQuery( "from Gatunek a where a.idGatunku IN (select id.idGatunku from GatunekFilm where id.idFilmu is " + film.getIdFilmu() + ")"); gatunki = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); } finally { session.close(); } Informacje info = new Informacje(); for (Object o : gatunki) { Gatunek gatunek = (Gatunek) o; info.gatunek.setText(info.gatunek.getText() + " | " + gatunek.getNazwa()); } info.gatunek.setText(info.gatunek.getText() + " |"); info.jLabel3.setText(film.getTytul()); info.rezyser.setText(rezyser.getNazwisko() + " " + rezyser.getImie()); info.rok.setText(film.getRokProdukcji().toString()); info.setVisible(true); } }
From source file:NewJFrame.java
private void showMovies() { if (ROLE != 0) { orderButton.setVisible(false);/* w ww.j a v a 2s . co m*/ } else { orderButton.setVisible(true); } moviesTable.removeAll(); List moviesList = null, directorList = null; try { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query q = session.createQuery("from Film"); moviesList = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); } Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Tytu"); tableHeaders.add("Rok Produkcji"); tableHeaders.add("Reyser"); tableHeaders.add("Nonik"); tableHeaders.add("Dostpno"); if (!moviesList.isEmpty()) { Film film; session.beginTransaction(); Query q; for (Object o : moviesList) { film = (Film) o; Vector<Object> oneRow = new Vector<>(); q = session.createQuery("from Rezyser a where a.idRezysera IS " + film.getIdRezysera().toString()); directorList = q.list(); q = session.createQuery("from Nosnik a where a.idNosnika IS " + film.getIdNosnika().toString()); oneRow.add(film.getIdFilmu()); oneRow.add(film.getTytul()); oneRow.add(film.getRokProdukcji()); oneRow.add(((Rezyser) (directorList.get(0))).getNazwisko()); oneRow.add(((Nosnik) q.list().get(0)).getTyp()); if (film.getIlosc() > 0) { oneRow.add("Dostpny"); } else { oneRow.add("Niedostpny"); } tableData.add(oneRow); } session.getTransaction().commit(); moviesTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); moviesTable.removeColumn(moviesTable.getColumnModel().getColumn(0)); session.close(); } }
From source file:CitySearch.java
public City[] SearchNearestCities(double lat, double lng) { City[] cities = new City[5]; Session sess = null;//from www. j a v a 2 s .com try { sess = NewHibernateUtil.currentSession(); Transaction tx = sess.beginTransaction(); //sql query to order the cities by the hypoteneus distance between given lat and lng // and then select the nearest 5 cities by using limit query String hql = "SELECT * FROM `Country`\n" + "\n" + "ORDER BY (SQRT(POWER((lat-" + String.valueOf(lat) + "),2)+" + "POWER((lng-" + String.valueOf(lng) + "),2))) \n" + " limit 5;"; Query query = sess.createSQLQuery(hql).addEntity(City.class); List results = query.list(); System.out.println(String.valueOf(results.size())); cities = new City[5]; for (int i = 0; i < results.size(); i++) { //adding results into the array to be returned cities[i] = ((City) results.get(i)); System.out.println(((City) results.get(i)).country); } tx.commit(); // sess.close(); } catch (Exception e) { e.printStackTrace(); } return cities; }