Example usage for org.hibernate ScrollableResults getString

List of usage examples for org.hibernate ScrollableResults getString

Introduction

In this page you can find the example usage for org.hibernate ScrollableResults getString.

Prototype

String getString(int col);

Source Link

Document

Convenience method to read a string.

Usage

From source file:com.lp.server.system.fastlanereader.TheClientHandler.java

License:Open Source License

/**
 * sort//w ww  . ja  v  a  2 s . c o m
 * 
 * @param sortierKriterien
 *            SortierKriterium[]
 * @param selectedId
 *            Object
 * @return QueryResult
 */
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) {

    this.getQuery().setSortKrit(sortierKriterien);

    QueryResult result = null;
    int rowNumber = 0;

    if (selectedId != null /* && ( (Integer) selectedId).intValue() >= 0 */) {
        SessionFactory factory = FLRSessionFactory.getFactory();
        Session session = null;

        try {
            session = factory.openSession();
            // flr: 7
            String queryString = "select theclient.cnr from FLRTheClient theclient " + this.buildWhereClause()
                    + this.buildOrderByClause();
            Query query = session.createQuery(queryString);
            ScrollableResults scrollableResult = query.scroll();
            boolean idFound = false;
            if (scrollableResult != null) {
                scrollableResult.beforeFirst();
                while (scrollableResult.next()) {
                    // flr: 8
                    String id = (String) scrollableResult.getString(0);
                    if (selectedId.equals(id)) {
                        rowNumber = scrollableResult.getRowNumber();
                        break;
                    }
                }
            }
        } catch (Exception e) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
        } finally {
            try {
                session.close();
            } catch (HibernateException he) {
                throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
            }
        }
    }

    if (rowNumber < 0 || rowNumber >= this.getRowCount()) {
        rowNumber = 0;
    }

    result = this.getPageAt(new Integer(rowNumber));
    result.setIndexOfSelectedRow(rowNumber);

    return result;
}

From source file:com.lp.server.system.fastlanereader.TheJudgeHandler.java

License:Open Source License

/**
 * sort/*www.ja va2s. c om*/
 * 
 * @param sortierKriterien
 *            SortierKriterium[]
 * @param selectedId
 *            Object
 * @return QueryResult
 */
public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) {

    this.getQuery().setSortKrit(sortierKriterien);

    QueryResult result = null;
    int rowNumber = 0;

    // flrc: 5 weil selectedId ein zB. auch ein String sein kann
    if (selectedId != null /* && ( (Integer) selectedId).intValue() >= 0 */) {
        SessionFactory factory = FLRSessionFactory.getFactory();
        Session session = null;

        try {
            session = factory.openSession();
            // flrc: 6 hier das select formulieren
            String queryString = "select thejudge.id_comp.c_wer from FLRTheJudge thejudge "
                    + this.buildWhereClause() + this.buildOrderByClause();
            Query query = session.createQuery(queryString);
            ScrollableResults scrollableResult = query.scroll();
            boolean idFound = false;
            if (scrollableResult != null) {
                scrollableResult.beforeFirst();
                while (scrollableResult.next()) {
                    // flrc: 7 String, weil thejudge.id_comp.c_wer ein
                    // String ist.
                    String id = (String) scrollableResult.getString(0);
                    if (selectedId.equals(id)) {
                        rowNumber = scrollableResult.getRowNumber();
                        break;
                    }
                }
            }
        } catch (Exception e) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
        } finally {
            try {
                session.close();
            } catch (HibernateException he) {
                throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
            }
        }
    }

    if (rowNumber < 0 || rowNumber >= this.getRowCount()) {
        rowNumber = 0;
    }

    result = this.getPageAt(new Integer(rowNumber));
    result.setIndexOfSelectedRow(rowNumber);

    return result;
}

From source file:com.lp.server.system.fastlanereader.WaehrungHandler.java

License:Open Source License

public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP {
    this.getQuery().setSortKrit(sortierKriterien);

    QueryResult result = null;/*w w  w  .  j av  a  2 s.co  m*/
    int rowNumber = 0;

    if (selectedId != null /* && ( (Integer) selectedId).intValue() >= 0 */) {
        SessionFactory factory = FLRSessionFactory.getFactory();
        Session session = null;

        try {
            session = factory.openSession();
            String queryString = "select waehrung.c_nr from FLRWaehrung waehrung " + this.buildWhereClause()
                    + this.buildOrderByClause();
            Query query = session.createQuery(queryString);
            ScrollableResults scrollableResult = query.scroll();
            boolean idFound = false;
            if (scrollableResult != null) {
                scrollableResult.beforeFirst();
                while (scrollableResult.next()) {
                    String id = (String) scrollableResult.getString(0); // TYPE
                    // OF
                    // KEY
                    // ATTRIBUTE
                    // !
                    // !
                    // !
                    if (selectedId.equals(id)) {
                        rowNumber = scrollableResult.getRowNumber();
                        break;
                    }
                }
            }
        } catch (Exception e) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
        } finally {
            closeSession(session);
        }
    }

    if (rowNumber < 0 || rowNumber >= this.getRowCount()) {
        rowNumber = 0;
    }

    result = this.getPageAt(new Integer(rowNumber));
    result.setIndexOfSelectedRow(rowNumber);

    return result;
}

From source file:com.lp.server.system.fastlanereader.WechselkursHandler.java

License:Open Source License

public QueryResult sort(SortierKriterium[] sortierKriterien, Object selectedId) throws EJBExceptionLP {
    this.getQuery().setSortKrit(sortierKriterien);

    QueryResult result = null;/*  w  w w .java2 s . co m*/
    int rowNumber = 0;

    if (selectedId != null /* && ( (Integer) selectedId).intValue() >= 0 */) {
        SessionFactory factory = FLRSessionFactory.getFactory();
        Session session = null;

        try {
            session = factory.openSession();
            String queryString = "select kurs." + SystemFac.FLR_WECHSELKURS_WAEHRUNG_C_NR_ZU
                    + " from FLRWechselkurs kurs " + this.buildWhereClause() + this.buildOrderByClause();
            Query query = session.createQuery(queryString);
            ScrollableResults scrollableResult = query.scroll();
            boolean idFound = false;
            if (scrollableResult != null) {
                scrollableResult.beforeFirst();
                while (scrollableResult.next()) {
                    String id = (String) scrollableResult.getString(0); // TYPE
                    // OF
                    // KEY
                    // ATTRIBUTE
                    // !
                    // !
                    // !
                    if (selectedId.equals(id)) {
                        rowNumber = scrollableResult.getRowNumber();
                        break;
                    }
                }
            }
        } catch (Exception e) {
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e);
        } finally {
            try {
                session.close();
            } catch (HibernateException he) {
                throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, he);
            }
        }
    }

    if (rowNumber < 0 || rowNumber >= this.getRowCount()) {
        rowNumber = 0;
    }

    result = this.getPageAt(new Integer(rowNumber));
    result.setIndexOfSelectedRow(rowNumber);

    return result;
}

From source file:com.multimedia.service.wallpaper.CmsWallpaperService.java

License:Apache License

@Override
public long renewResolution(StatusBean sb) {
    File f;//from w  w w.jav a 2s.c om
    BufferedImage bi;
    sb.setTotal((Long) wallpaper_service.getSinglePropertyU("count(*)"));
    ScrollableResults sr = wallpaper_service.getScrollableResults("id, name", null, null, null, null);
    File img_dir = new File(wallpaper_service.getStorePath(), "full");

    sr.beforeFirst();
    while (sr.next()) {
        f = new File(img_dir, sr.getString(1));
        try {
            bi = ImageUtils.readImage(f).getImage();
            wallpaper_service.updateObjectArrayShortByProperty(WALLPAPER_RESOLUTION,
                    new Object[] { bi.getWidth(), bi.getHeight() }, "id", new Object[] { sr.getLong(0) });
            sb.increaseDone(1);
        } catch (Exception ex) {
            logger.error("while trying to read wallpaper's resolution id = " + sr.getLong(0), ex);
        }
    }
    return sb.getDone();
}

From source file:com.multimedia.service.wallpaper.WallpaperServiceImpl.java

License:Apache License

@Override
public Map<String, Double> getTags(int maxTags) {
    ScrollableResults wallpaper_tags = dao.getScrollableResults("tags", "active", Boolean.TRUE, null, null);
    Map<String, Double> tags = new HashMap<String, Double>();
    if (wallpaper_tags.first()) {
        String tag;/* www .ja  v  a2s  .  c o  m*/
        Double score;
        String[] tags_parsed;
        String tag_parsed;
        do {
            tag = wallpaper_tags.getString(0);
            if (tag != null) {
                tags_parsed = tag.split(",");
                for (int i = 1; i < tags_parsed.length; i++) {
                    tag_parsed = tags_parsed[i].trim();
                    if (!black_word_list.contains(tag_parsed)) {
                        score = tags.get(tag_parsed);
                        if (score == null) {
                            tags.put(tag_parsed, new Double(1.0));
                        } else {
                            tags.put(tag_parsed, (score + 1));
                        }
                    }
                }
            }
        } while (wallpaper_tags.next());
    }
    wallpaper_tags.close();
    //keeping only maxTags quantity
    Set<Entry<String, Double>> i = tags.entrySet();
    List<Entry<String, Double>> l = new LinkedList<Entry<String, Double>>(i);
    java.util.Collections.sort(l, new WallpaperServiceImpl.EntryComparatorDesc());

    if (maxTags > 0) {
        for (int j = maxTags; j < l.size(); j++) {
            tags.remove(l.get(j).getKey());
        }
    }
    return tags;
}

From source file:com.opensourcestrategies.financials.reports.FinancialReports.java

License:Open Source License

/**
 * <p>Look over invoice adjustments and transform  them into into sales and tax invoice item facts.
 * Thus an adjustment amount is added into discount column of the fact table and this is only
 * currency column affected.</p>/*  w w  w .  j  a va2 s .  co  m*/
 *
 * @param session Hibernate session
 * @throws GenericEntityException
 */
public static void loadInvoiceAdjustments(Session session, Delegator delegator) throws GenericEntityException {

    Transaction tx = session.beginTransaction();

    // retrieve data as scrollable result set.
    // this is join of InvoiceAdjustment and Invoice entities and each record has all required data
    // to create new fact row
    Query invAdjQry = session.createQuery(
            "select IA.invoiceAdjustmentId, IA.invoiceId, IA.amount, I.partyIdFrom, I.invoiceDate, I.currencyUomId from InvoiceAdjustment IA, Invoice I where IA.invoiceId = I.invoiceId and I.invoiceTypeId = 'SALES_INVOICE' and I.statusId not in ('INVOICE_IN_PROCESS', 'INVOICE_CANCELLED', 'INVOICE_VOIDED', 'INVOICE_WRITEOFF')");
    ScrollableResults adjustments = invAdjQry.scroll();

    // iterate over record set
    while (adjustments.next()) {

        // keep result fields in variables as a matter of convenience
        String invoiceId = adjustments.getString(1);
        String invoiceAdjustmentId = adjustments.getString(0);
        BigDecimal amount = adjustments.getBigDecimal(2);
        String organizationPartyId = adjustments.getString(3);
        Timestamp invoiceDate = (Timestamp) adjustments.get(4);
        String currencyUomId = adjustments.getString(5);

        // lookup date dimension
        DateFormat dayOfMonthFmt = new SimpleDateFormat("dd");
        DateFormat monthOfYearFmt = new SimpleDateFormat("MM");
        DateFormat yearNumberFmt = new SimpleDateFormat("yyyy");

        String dayOfMonth = dayOfMonthFmt.format(invoiceDate);
        String monthOfYear = monthOfYearFmt.format(invoiceDate);
        String yearNumber = yearNumberFmt.format(invoiceDate);

        EntityCondition dateDimConditions = EntityCondition.makeCondition(EntityOperator.AND,
                EntityCondition.makeCondition("dayOfMonth", dayOfMonth),
                EntityCondition.makeCondition("monthOfYear", monthOfYear),
                EntityCondition.makeCondition("yearNumber", yearNumber));
        Long dateDimId = UtilEtl.lookupDimension("DateDim", "dateDimId", dateDimConditions, delegator);

        // lookup currency dimension
        Long currencyDimId = UtilEtl.lookupDimension("CurrencyDim", "currencyDimId",
                EntityCondition.makeCondition("uomId", currencyUomId), delegator);

        // lookup organization dimension
        Long organizationDimId = UtilEtl.lookupDimension("OrganizationDim", "organizationDimId",
                EntityCondition.makeCondition("organizationPartyId", organizationPartyId), delegator);

        // creates rows for both fact tables
        TaxInvoiceItemFact taxFact = new TaxInvoiceItemFact();
        taxFact.setDateDimId(dateDimId);
        taxFact.setStoreDimId(0L);
        taxFact.setTaxAuthorityDimId(0L);
        taxFact.setCurrencyDimId(currencyDimId);
        taxFact.setOrganizationDimId(organizationDimId);
        taxFact.setInvoiceId(invoiceId);
        taxFact.setInvoiceAdjustmentId(invoiceAdjustmentId);
        taxFact.setGrossAmount(BigDecimal.ZERO);
        taxFact.setDiscounts(amount);
        taxFact.setRefunds(BigDecimal.ZERO);
        taxFact.setNetAmount(BigDecimal.ZERO);
        taxFact.setTaxable(BigDecimal.ZERO);
        taxFact.setTaxDue(BigDecimal.ZERO);
        session.save(taxFact);

        SalesInvoiceItemFact salesFact = new SalesInvoiceItemFact();
        salesFact.setDateDimId(dateDimId);
        salesFact.setStoreDimId(0L);
        salesFact.setCurrencyDimId(currencyDimId);
        salesFact.setOrganizationDimId(organizationDimId);
        salesFact.setInvoiceId(invoiceId);
        salesFact.setInvoiceAdjustmentId(invoiceAdjustmentId);
        salesFact.setGrossAmount(BigDecimal.ZERO);
        salesFact.setDiscounts(amount);
        salesFact.setRefunds(BigDecimal.ZERO);
        salesFact.setNetAmount(BigDecimal.ZERO);
        session.save(salesFact);

    }
    adjustments.close();
    tx.commit(); // persist result, don't move this statement upper
}

From source file:gallery.service.rss.RssServiceImpl.java

License:Apache License

@Override
@Transactional(readOnly = true)/*from   ww  w.java 2  s .  com*/
public void create() {
    if (generating) {
        logger.info("xml is allready generating ...");
        return;
    }
    try {
        generating = true;
        logger.info("start generate xml");
        long time = System.currentTimeMillis();

        File img_dir = new File(wallpaper_service.getStorePath(), Config.ENCLOSURE_IMG_SUBDIR);

        //get main wallpaper page
        Channel chan;
        List<Pages> temp = pages_service.getByPropertiesValueOrdered(null, MAIN_PSEUDONYMES, MAIN_VALUES, null,
                null);
        if (temp.isEmpty()) {
            chan = new Channel(gallery.web.Config.SITE_NAME, gallery.web.Config.SITE_NAME,
                    gallery.web.Config.SITE_NAME);
        } else {
            //TODO localize it !!!
            IAutoreplaceService.IReplacement repl = autoreplace_service.getAllReplacements("ru");
            String title = repl.replaceAll(temp.get(0).getTitle());
            String description = repl.replaceAll(temp.get(0).getDescription());
            chan = new Channel(title, gallery.web.Config.SITE_NAME, description);
        }

        RSS rss = new RSS();

        chan.setImage(new Channel.Image(gallery.web.Config.SITE_NAME + Config.LOGO_WEBDIR, chan.getTitle(),
                chan.getLink(), 0, 0, null));
        chan.setLastBuildDate(new java.util.Date());
        rss.addChannel(chan);

        ScrollableResults sr = wallpaper_service.getScrollableResults(
                "id, id_pages, description, title, date_upload, name", "active", Boolean.TRUE,
                new String[] { "date_upload" }, new String[] { "DESC" });
        int max_elements = 100;
        sr.beforeFirst();
        while (sr.next() && (max_elements-- > 0)) {
            try {
                Item item = new Item(sr.getString(2), gallery.web.Config.SITE_NAME + "index.htm?id_pages_nav="
                        + sr.getLong(1) + "&id_photo_nav=" + sr.getLong(0), sr.getString(3));
                item.setPubDate(sr.getDate(4));
                long fileLen = (new File(img_dir, sr.getString(5))).length();
                if (fileLen > 0) {
                    item.setEnclosure(new Item.Enclosure(
                            gallery.web.Config.SITE_NAME + Config.ENCLOSURE_IMG_WEBDIR + sr.getString(5),
                            fileLen, "image/jpeg"));
                }
                //item.addCategory(new Item.Category("test"));
                chan.addItem(item);
            } finally {
                //TODO: mb add some logging here
            }
        }
        sr.close();
        try {
            new RSSFeedGeneratorImpl().generateToFile(rss, new File(path, Config.RSS_FILE_NAME), "UTF-8");
        } catch (Exception e) {
            logger.error("error while saving rss to file", e);
        }
        time = System.currentTimeMillis() - time;
        logger.info("end generate xml. generated in: " + time);
    } finally {
        generating = false;
    }
}

From source file:org.compass.gps.device.hibernate.scrollable.Hibernate3Dialect.java

License:Apache License

public String getStringValue(ScrollableResults rs, String[] returnAliases, ColumnMapping mapping) {
    int index = -1;
    if (mapping.isUsingColumnIndex()) {
        index = mapping.getColumnIndex();
    } else {//from   ww  w.j a v  a 2s . c  om
        index = getIndex(returnAliases, mapping);
    }
    Type type = rs.getType(index);
    String result;
    if (type instanceof StringType) {
        result = rs.getString(index);
    } else {
        result = rs.get(index).toString();
    }
    return result;
}

From source file:org.compass.gps.device.hibernate.scrollable.Hibernate3Dialect.java

License:Apache License

public String getStringValue(ScrollableResults rs, int columnIndex) {
    Type type = rs.getType(columnIndex);
    String result;//w  w w .j a v  a  2s .c om
    if (type instanceof StringType) {
        result = rs.getString(columnIndex);
    } else {
        result = rs.get(columnIndex).toString();
    }
    return result;
}