List of usage examples for org.hibernate Criteria scroll
public ScrollableResults scroll() throws HibernateException;
From source file:com.duroty.task.DeleteMessagesTask.java
License:Open Source License
/** * DOCUMENT ME!//from w w w . j av a 2 s. com */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Criteria crit = hsession.createCriteria(Message.class); crit.add(Restrictions.eq("mesBox", folderDelete)); ScrollableResults scroll = crit.scroll(); while (scroll.next()) { Message message = (Message) scroll.get(0); Users user = message.getUsers(); String mid = message.getMesName(); hsession.delete(message); hsession.flush(); this.messageable.deleteMimeMessage(mid, user); /*try { } catch (HibernateException e) { } catch (OutOfMemoryError e) { System.gc(); } catch (Exception e) { } catch (Throwable e) { }*/ Thread.sleep(100); } } catch (Exception e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (OutOfMemoryError e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (Throwable e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
From source file:com.duroty.task.PurgeTrashAndSpam.java
License:Open Source License
/** * DOCUMENT ME!// w w w . j a v a 2s .c o m */ private void flush() { setInit(true); SessionFactory hfactory = null; Session hsession = null; try { hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory); hsession = hfactory.openSession(); Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); // 2002 int month = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ... int day = cal.get(Calendar.DAY_OF_MONTH); // 1... Calendar cal1 = new GregorianCalendar(year, month - 1, day, 0, 0, 0); Date date = new Date(cal1.getTimeInMillis()); Criteria criteria = hsession.createCriteria(Message.class); criteria.add(Restrictions.in("mesBox", new String[] { this.folderSpam, this.folderTrash })); criteria.add(Restrictions.le("mesDate", date)); criteria.addOrder(Order.asc("mesDate")); ScrollableResults scroll = criteria.scroll(); while (scroll.next()) { Message message = (Message) scroll.get(0); Users user = message.getUsers(); try { messageable.deleteMimeMessage(message.getMesName(), user); } catch (Exception e) { DLog.log(DLog.INFO, this.getClass(), e.getMessage() + " for user " + user.getUseUsername()); } hsession.delete(message); hsession.flush(); Thread.sleep(100); } } catch (Exception e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (OutOfMemoryError e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } catch (Throwable e) { System.gc(); DLog.log(DLog.WARN, this.getClass(), e.getMessage()); } finally { GeneralOperations.closeHibernateSession(hsession); setInit(false); } }
From source file:com.ibm.asset.trails.dao.jpa.VSoftwareLparDAOJpa.java
public void paginatedList(DisplayTagList data, Account account, ReconSetting reconSetting, int startIndex, int objectsPerPage, String sort, String dir) { Criteria criteria = getHibernateSessionCriteria(); criteria.createAlias("hardwareLpar", "hl") .createAlias("hl.hardwareLparEff", "hle", CriteriaSpecification.LEFT_JOIN) .createAlias("hl.hardware", "h").createAlias("h.machineType", "mt") .createAlias("installedSoftwares", "is") .createAlias("is.scheduleF", "sf", CriteriaSpecification.LEFT_JOIN) .createAlias("sf.scope", "scope", CriteriaSpecification.LEFT_JOIN) .createAlias("is.softwareLpar", "sl").createAlias("is.alert", "aus") .createAlias("aus.reconcile", "r", CriteriaSpecification.LEFT_JOIN) .createAlias("r.usedLicenses", "ul", CriteriaSpecification.LEFT_JOIN) .createAlias("ul.license", "license", CriteriaSpecification.LEFT_JOIN) .createAlias("r.reconcileType", "rt", CriteriaSpecification.LEFT_JOIN) .createAlias("is.software", "sw") .createAlias("sw.manufacturer", "mf", CriteriaSpecification.LEFT_JOIN) .add(Restrictions.eq("account", account)); if (reconSetting.getReconcileType() != null) { criteria.add(Restrictions.eq("rt.id", reconSetting.getReconcileType())); }/*from www . java2s . co m*/ if (StringUtils.isNotBlank(reconSetting.getAlertStatus())) { boolean open = false; if (reconSetting.getAlertStatus().equals("OPEN")) { open = true; criteria.add(Restrictions.eq("aus.open", open)); } else { criteria.add(Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id"))); } } else { criteria.add(Restrictions.or(Restrictions.eq("aus.open", true), Restrictions.and(Restrictions.eq("aus.open", false), Restrictions.eqProperty("is.id", "r.installedSoftware.id")))); } if (null != reconSetting.getAlertFrom() && reconSetting.getAlertFrom().intValue() >= 0) { criteria.add(Restrictions.ge("aus.alertAge", reconSetting.getAlertFrom())); } if (null != reconSetting.getAlertTo() && reconSetting.getAlertTo().intValue() >= 0) { criteria.add(Restrictions.le("aus.alertAge", reconSetting.getAlertTo())); } if (StringUtils.isNotBlank(reconSetting.getAssigned())) { if (reconSetting.getAssigned().equals("Assigned")) { criteria.add(Restrictions.ne("aus.remoteUser", "STAGING")); } if (reconSetting.getAssigned().equals("Unassigned")) { criteria.add(Restrictions.eq("aus.remoteUser", "STAGING")); } } if (StringUtils.isNotBlank(reconSetting.getAssignee())) { criteria.add(Restrictions.eq("aus.remoteUser", reconSetting.getAssignee()).ignoreCase()); } if (StringUtils.isNotBlank(reconSetting.getOwner())) { if (reconSetting.getOwner().equalsIgnoreCase("IBM")) { criteria.add(Restrictions.eq("h.owner", reconSetting.getOwner()).ignoreCase()); } else if (reconSetting.getOwner().equalsIgnoreCase("Customer")) { ArrayList<String> lalOwner = new ArrayList<String>(); lalOwner.add("CUST"); lalOwner.add("CUSTO"); criteria.add(Restrictions.in("h.owner", lalOwner)); } } // I'm not sure why the heck we aren't just getting a list of strings? if (reconSetting.getCountries().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getCountries().length; i++) { if (StringUtils.isNotBlank(reconSetting.getCountries()[i])) { list.add(reconSetting.getCountries()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.country", list)); } } if (reconSetting.getNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getNames()[i])) { list.add(reconSetting.getNames()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("hl.name", list)); } } if (reconSetting.getSwcmIDs().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSwcmIDs().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSwcmIDs()[i])) { list.add(reconSetting.getSwcmIDs()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("license.extSrcId", list)); } } if (reconSetting.getSerialNumbers().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getSerialNumbers().length; i++) { if (StringUtils.isNotBlank(reconSetting.getSerialNumbers()[i])) { list.add(reconSetting.getSerialNumbers()[i].toUpperCase()); } } if (list.size() > 0) { criteria.add(Restrictions.in("h.serial", list)); } } if (reconSetting.getProductInfoNames().length > 0) { List<String> list = new ArrayList<String>(); for (int i = 0; i < reconSetting.getProductInfoNames().length; i++) { if (StringUtils.isNotBlank(reconSetting.getProductInfoNames()[i])) { list.add(reconSetting.getProductInfoNames()[i]); } } if (list.size() > 0) { criteria.add(Restrictions.in("sw.softwareName", list)); } } if (StringUtils.isNotBlank(reconSetting.getScope())) { if ("Not specified".equalsIgnoreCase(reconSetting.getScope())) { criteria.add(Restrictions.isNull("scope.description")); } else { criteria.add(Restrictions.eq("scope.description", reconSetting.getScope())); } } if (StringUtils.isNotBlank(reconSetting.getFinanResp())) { if ("Not Specified".trim().equalsIgnoreCase(reconSetting.getFinanResp())) { criteria.add(Restrictions.isNull("sf.SWFinanceResp")); } else { criteria.add(Restrictions.eq("sf.SWFinanceResp", reconSetting.getFinanResp())); } } criteria.setProjection(Projections.projectionList().add(Projections.property("aus.id").as("alertId")) .add(Projections.property("r.id").as("reconcileId")) .add(Projections.property("aus.alertAge").as("alertAgeI")) .add(Projections.property("is.id").as("installedSoftwareId")) .add(Projections.property("hl.name").as("hostname")) .add(Projections.property("sl.name").as("sl_hostname")) .add(Projections.property("hl.spla").as("spla")) .add(Projections.property("hl.sysplex").as("sysplex")) .add(Projections.property("hl.internetIccFlag").as("internetIccFlag")) .add(Projections.property("h.serial").as("serial")) .add(Projections.property("h.country").as("country")) .add(Projections.property("h.owner").as("owner")) .add(Projections.property("h.mastProcessorType").as("mastProcessorType")) .add(Projections.property("h.processorManufacturer").as("processorManufacturer")) .add(Projections.property("h.mastProcessorModel").as("mastProcessorModel")) .add(Projections.property("h.nbrCoresPerChip").as("nbrCoresPerChip")) .add(Projections.property("h.nbrOfChipsMax").as("nbrOfChipsMax")) .add(Projections.property("h.cpuLsprMips").as("cpuLsprMips")) .add(Projections.property("h.cpuIfl").as("cpuIFL")) .add(Projections.property("hl.partLsprMips").as("partLsprMips")) .add(Projections.property("h.cpuGartnerMips").as("cpuGartnerMips")) .add(Projections.property("hl.partGartnerMips").as("partGartnerMips")) .add(Projections.property("hl.effectiveThreads").as("effectiveThreads")) .add(Projections.property("hl.vcpu").as("vcpu")).add(Projections.property("h.cpuMsu").as("cpuMsu")) .add(Projections.property("hl.partMsu").as("partMsu")) .add(Projections.property("hl.serverType").as("lparServerType")) .add(Projections.property("h.shared").as("shared")) .add(Projections.property("h.multi_tenant").as("multi_tenant")) .add(Projections.property("mt.type").as("assetType")) .add(Projections.property("mt.name").as("assetName")) .add(Projections.property("h.hardwareStatus").as("hardwareStatus")) .add(Projections.property("hl.lparStatus").as("lparStatus")) .add(Projections.property("processorCount").as("processorCount")) .add(Projections.property("sw.softwareName").as("productInfoName")) .add(Projections.property("sw.softwareId").as("productInfoId")) .add(Projections.property("sw.pid").as("pid")) .add(Projections.property("mf.manufacturerName").as("manufacturerName")) .add(Projections.property("rt.name").as("reconcileTypeName")) .add(Projections.property("rt.id").as("reconcileTypeId")) .add(Projections.property("aus.remoteUser").as("assignee")) .add(Projections.property("h.processorCount").as("hardwareProcessorCount")) .add(Projections.property("hle.processorCount").as("hwLparEffProcessorCount")) .add(Projections.property("hl.osType").as("osType")) .add(Projections.property("hle.status").as("hwLparEffProcessorStatus")) .add(Projections.property("h.chips").as("chips"))); criteria.setResultTransformer(new AliasToBeanResultTransformer(ReconWorkspace.class)); criteria.addOrder(Order.desc("aus.open")); if (dir.equalsIgnoreCase("ASC")) { criteria.addOrder(Order.asc(sort)); } else { criteria.addOrder(Order.desc(sort)); } ArrayList<ReconWorkspace> list = new ArrayList<ReconWorkspace>(); ScrollableResults itemCursor = criteria.scroll(); itemCursor.beforeFirst(); if (itemCursor.next()) { itemCursor.scroll(startIndex); int i = 0; while (objectsPerPage > i++) { ReconWorkspace rw = (ReconWorkspace) itemCursor.get(0); if (null != rw.getHwLparEffProcessorStatus() && rw.getHwLparEffProcessorStatus().equalsIgnoreCase("INACTIVE")) { rw.setHwLparEffProcessorCount(0); } list.add(rw); if (!itemCursor.next()) break; } data.setList(list); itemCursor.last(); data.setFullListSize(itemCursor.getRowNumber() + 1); itemCursor.close(); addSchedulef2List(account, data.getList()); } else { data.setList(null); data.setFullListSize(0); itemCursor.close(); } }
From source file:com.orig.gls.group.dao.Group.java
public static void verifyGroup(int groupId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/* w w w . j a v a2 s. co m*/ try { tx = session.beginTransaction(); Criteria cr = session.createCriteria(GroupsTableMod.class); cr.add(Restrictions.eq("groupId", groupId)); int count = 0; ScrollableResults items = cr.scroll(); while (items.next()) { GroupsTableMod group = (GroupsTableMod) items.get(0); session.delete(group); if (++count % 100 == 0) { session.flush(); session.clear(); } } tx.commit(); } catch (Exception asd) { log.debug(asd.getMessage()); if (tx != null) { tx.rollback(); } } finally { session.close(); } }
From source file:com.orig.gls.subgroup.dao.SubGroup.java
public static void verifySubGroup(int groupId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;//from ww w . java 2 s . co m try { tx = session.beginTransaction(); Criteria cr = session.createCriteria(SubGrpTableMod.class); cr.add(Restrictions.eq("subGroupId", groupId)); int count = 0; ScrollableResults items = cr.scroll(); while (items.next()) { SubGrpTableMod group = (SubGrpTableMod) items.get(0); session.delete(group); if (++count % 100 == 0) { session.flush(); session.clear(); } } tx.commit(); } catch (Exception asd) { log.debug(asd.getMessage()); if (tx != null) { tx.rollback(); } } finally { session.close(); } }
From source file:com.sapienter.jbilling.server.process.db.BillingProcessDAS.java
License:Open Source License
public ScrollableResults findUsersToProcess(int entityId) { Criteria criteria = getSession().createCriteria(UserDTO.class).add(Restrictions.eq("deleted", 0)) .createAlias("company", "c").add(Restrictions.eq("c.id", entityId)).createAlias("userStatus", "us") .add(Restrictions.lt("us.id", UserDTOEx.STATUS_SUSPENDED)).setProjection(Projections.id()) .setComment("BillingProcessDAS.findUsersToProcess " + entityId); return criteria.scroll(); }
From source file:de.codesourcery.eve.skills.util.DBConverter.java
License:Apache License
protected void export(Class<?> entity) { System.out.println("\n============\nExporting " + entity.getName() + "\n============"); // load data/*from www.j ava 2s .co m*/ System.out.print("Opening MySQL session ..."); final Session mysqlSession = mysql.openSession(); System.out.print("created."); // mysqlSession.setFlushMode( FlushMode.MANUAL ); Transaction mysqlTransaction = mysqlSession.beginTransaction(); final Criteria criteria = mysqlSession.createCriteria(entity); // replicate data System.out.print("Opening HSQL session ..."); final Session hsqlSession = hsql.openSession(); System.out.println("created."); // mysqlSession.setFlushMode( FlushMode.MANUAL ); final Transaction hsqlTransaction = hsqlSession.beginTransaction(); final ScrollableResults data = criteria.scroll(); int count = 0; int dotCount = 0; try { while (data.next()) { Object loaded = data.get(0); // if ( entity == MarketGroup.class ) { // MarketGroup group = (MarketGroup) loaded; // System.out.println( group.getId() +" -> "+group.getParent() ); // } hsqlSession.replicate(loaded, ReplicationMode.IGNORE); if ((++count % 1000) == 0) { // make sure to adjust <prop key="hibernate.jdbc.batch_size">1000</prop> in config !! hsqlSession.flush(); hsqlSession.clear(); mysqlSession.flush(); mysqlSession.clear(); System.out.print("."); dotCount++; if (dotCount == 60) { System.out.println(); dotCount = 0; } } } } finally { data.close(); System.out.println("\nExported " + count + " entries"); } if (mysqlTransaction.isActive()) { mysqlTransaction.commit(); } if (hsqlTransaction.isActive()) { hsqlTransaction.commit(); } hsqlSession.flush(); mysqlSession.flush(); mysqlSession.close(); hsqlSession.close(); }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Return a {@link Set} of {@link String} instances consisting of <code>lemma+"_"+part-of-speech</code>, * filtered by given {@link Lexicon} name.<br> * The lemma is obtained from the written form of the first {@link FormRepresentation} of the {@link Lemma} * instance.//from w ww .j ava 2s . com * @param lexiconName * name of the lexicon which lemmas should be used * * @return a set of strings containing lemma and part-of-speech of the specified lexicon.<br> * This method returns an empty set if the lexicon with the specified name does no exist. * * @see Lemma#getFormRepresentations() * @see FormRepresentation#getWrittenForm() * @see EPartOfSpeech */ public Set<String> getLemmaPosPerLexicon(String lexiconName) { Criteria criteria = session.createCriteria(Lexicon.class, "l"); criteria = criteria.createCriteria("lexicalEntries", "e"); if (lexiconName != null) { criteria = criteria.add(Restrictions.eq("l.name", lexiconName)); } criteria = criteria.createCriteria("lemma").createCriteria("formRepresentations", "f") .setProjection(Projections.projectionList().add(Property.forName("f.writtenForm")) .add(Property.forName("e.partOfSpeech"))); ScrollableResults res = criteria.scroll(); ArrayList<String> out = new ArrayList<String>(); while (res.next()) { Object[] r = res.get(); if (r[1] != null) { // some resources do not have POS out.add((String) r[0] + "_" + ((EPartOfSpeech) r[1]).toString()); } else { out.add((String) r[0] + "_null"); } } HashSet<String> out2 = new HashSet<String>(out); return out2; }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Return a {@link Set} of {@link String} instances consisting of <code>lemma+"_"+part-of-speech</code>, * filtered by given {@link Lexicon} name, part-of-speech prefix and a language identifier.<br> * The lemma is obtained from the written form of the first {@link FormRepresentation} of the {@link Lemma} * instance.//from w ww . ja v a 2 s . c o m * * @param lexiconName * name of the lexicon which lemmas should be used * * @param prefix the part-of-speech prefix used when filtering {@link LexicalEntry} instances * * @param lang the language identifier used when filtering lexical entries * * @return a set of strings containing lemma and part-of-speech of the specified lexicon.<br> * * This method returns an empty set if the lexicon with the specified name does no exist or * the lexicon does not contain any lexical entries with specified part-of-speech prefix and language * identifier. * * @see Lemma#getFormRepresentations() * @see FormRepresentation#getWrittenForm() * @see EPartOfSpeech * @see ELanguageIdentifier */ public Set<String> getLemmaPosPerLexiconAndPosPrefixAndLanguage(String lexiconName, String prefix, String lang) { Criteria criteria = session.createCriteria(Lexicon.class, "l"); criteria = criteria.createCriteria("lexicalEntries", "e"); if (lexiconName != null) { criteria = criteria.add(Restrictions.eq("l.name", lexiconName)); } if (lang != null) { criteria = criteria.add(Restrictions.eq("l.languageIdentifier", lang)); } if (prefix != null) { criteria = criteria.add(Restrictions.sqlRestriction("partOfSpeech like '" + prefix + "'")); } criteria = criteria.createCriteria("lemma").createCriteria("formRepresentations", "f") .setProjection(Projections.projectionList().add(Property.forName("f.writtenForm")) .add(Property.forName("e.partOfSpeech"))); ScrollableResults res = criteria.scroll(); ArrayList<String> out = new ArrayList<String>(); while (res.next()) { Object[] r = res.get(); if (r[1] != null) { out.add((String) r[0] + "_" + ((EPartOfSpeech) r[1]).toString()); } else { out.add((String) r[0] + "_null"); } } HashSet<String> out2 = new HashSet<String>(out); return out2; }
From source file:debop4k.data.orm.hibernate.dao.HibernateDao.java
License:Apache License
public ScrollableResults scroll(@NonNull Criteria criteria) { return criteria.scroll(); }