Example usage for org.hibernate ScrollableResults getLong

List of usage examples for org.hibernate ScrollableResults getLong

Introduction

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

Prototype

Long getLong(int col);

Source Link

Document

Convenience method to read a long.

Usage

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

License:Apache License

@Override
public long renewResolution(StatusBean sb) {
    File f;//from   w  w w.  ja  va 2  s. co  m
    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:de.tudarmstadt.ukp.csniper.webapp.evaluation.EvaluationRepository.java

License:Apache License

@Transactional
public int[][] listCachedParsesPages(String aCollectionId, int aPageSize) {
    List<int[]> pages = new ArrayList<int[]>();
    ScrollableResults results = null;
    try {/*  w w w.j  av a  2s . co m*/
        String queryString = "SELECT id FROM CachedParse WHERE collectionId = :collectionId";
        org.hibernate.Query query = ((HibernateQuery) entityManager.createQuery(queryString))
                .getHibernateQuery();
        query.setParameter("collectionId", aCollectionId);
        results = query.scroll();
        results.beforeFirst();
        int row = 0;
        int[] curPage = new int[] { -1, -1 };
        boolean hasNext = results.next();
        while (hasNext) {
            int id = results.getLong(0).intValue();
            // Record start of page
            if ((row % aPageSize) == 0) {
                curPage[0] = id;
            }

            // Step ahead
            hasNext = results.next();
            row++;

            // Record end of page when end of page or end of results is reached
            if (((row % aPageSize) == (aPageSize - 1)) || !hasNext) {
                curPage[1] = id;
                pages.add(curPage);
                curPage = new int[] { -1, -1 };
            }
        }
    } finally {
        if (results != null) {
            results.close();
        }
    }
    return pages.toArray(new int[pages.size()][2]);
}

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

License:Apache License

@Override
@Transactional(readOnly = true)/*  w w  w  . ja  v a  2s  .  c  o  m*/
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

protected Long getLong(ScrollableResults rs, String[] returnAliases, ColumnMapping columnMapping) {
    int index = -1;
    if (columnMapping.isUsingColumnIndex()) {
        index = columnMapping.getColumnIndex();
    } else {/*from  w w  w  .  j a v  a2s .  c  om*/
        index = getIndex(returnAliases, columnMapping);
    }
    Type type = rs.getType(index);
    Long result;
    if (type instanceof IntegerType) {
        result = new Long(rs.getInteger(index).longValue());
    } else if (type instanceof DateType) {
        result = new Long(rs.getDate(index).getTime());
    } else {
        result = rs.getLong(index);
    }
    return result;
}

From source file:org.dcm4chee.archive.ejb.query.InstanceQueryImpl.java

License:LGPL

@Override
protected Attributes toAttributes(ScrollableResults results) {
    long seriesPk = results.getLong(0);
    String retrieveAETs = results.getString(1);
    String externalRetrieveAET = results.getString(2);
    Availability availability = (Availability) results.get(3);
    byte[] instAttributes = results.getBinary(4);
    if (this.seriesPk != seriesPk) {
        this.seriesAttrs = querySeriesAttrs(seriesPk);
        this.seriesPk = seriesPk;
    }//  w  w w.ja  v  a  2  s  .  c o m
    Attributes attrs = new Attributes(seriesAttrs);
    Utils.decodeAttributes(attrs, instAttributes);
    Utils.setRetrieveAET(attrs, retrieveAETs, externalRetrieveAET);
    Utils.setAvailability(attrs, availability);
    return attrs;
}

From source file:org.dcm4chee.archive.query.dao.InstanceQuery.java

License:LGPL

@Override
protected Attributes toAttributes(ScrollableResults results) {
    Long seriesPk = results.getLong(0);
    String retrieveAETs = results.getString(1);
    String externalRetrieveAET = results.getString(2);
    Availability availability = (Availability) results.get(3);
    byte[] instAttributes = results.getBinary(4);
    if (!seriesPk.equals(this.seriesPk)) {
        this.seriesAttrs = queryService.seriesService().getAttributes(seriesPk, queryParam);
        this.seriesPk = seriesPk;
    }/*from   w ww . jav a  2  s. c  om*/
    Attributes attrs = new Attributes(seriesAttrs);
    Utils.decodeAttributes(attrs, instAttributes);
    Utils.setRetrieveAET(attrs, retrieveAETs, externalRetrieveAET);
    Utils.setAvailability(attrs, availability);
    return attrs;
}

From source file:org.dcm4chee.archive.query.dao.SeriesQuery.java

License:LGPL

@Override
protected Attributes toAttributes(ScrollableResults results) {
    Long studyPk = results.getLong(0);
    Long seriesPk = results.getLong(1);
    int[] a = { results.getInteger(6), // series.numberOfInstances
            results.getInteger(7) }; // series.numberOfInstancesA
    String retrieveAETs = results.getString(10);
    String externalRetrieveAET = results.getString(11);
    Availability availability = (Availability) results.get(12);
    byte[] seriesAttributes = results.getBinary(13);
    if (!studyPk.equals(this.studyPk)) {
        this.studyAttrs = toStudyAttributes(studyPk, results);
        this.studyPk = studyPk;
    }//from   w w  w  .  j a  va 2 s .c o  m
    Attributes attrs = new Attributes(studyAttrs);
    Utils.decodeAttributes(attrs, seriesAttributes);
    if (a[0] == -1)
        a = queryService.seriesService().calculateNumberOfSeriesRelatedInstances(seriesPk);
    int numberOfSeriesRelatedInstances = queryParam.isShowRejectedInstances() ? a[1] : a[0];

    // skip match for empty Series
    if (numberOfSeriesRelatedInstances == 0)
        return null;

    Utils.setSeriesQueryAttributes(attrs, numberOfSeriesRelatedInstances);
    Utils.setRetrieveAET(attrs, retrieveAETs, externalRetrieveAET);
    Utils.setAvailability(attrs, availability);

    return attrs;
}

From source file:org.dcm4chee.archive.query.dao.StudyQuery.java

License:LGPL

@Override
protected Attributes toAttributes(ScrollableResults results) {
    Long studyPk = results.getLong(0);
    int[] a = { results.getInteger(1), // study.numberOfSeries
            results.getInteger(2), // study.numberOfSeriesA
            results.getInteger(3), // study.numberOfInstances
            results.getInteger(4) }; // study.numberOfInstancesA
    String modalitiesInStudy = results.getString(5);
    String sopClassesInStudy = results.getString(6);
    String retrieveAETs = results.getString(7);
    String externalRetrieveAET = results.getString(8);
    Availability availability = (Availability) results.get(9);
    byte[] studyAttributes = results.getBinary(10);
    byte[] patientAttributes = results.getBinary(11);
    Attributes attrs = new Attributes();
    Utils.decodeAttributes(attrs, patientAttributes);
    Utils.decodeAttributes(attrs, studyAttributes);
    if (a[2] == -1)
        a = queryService.seriesService().calculateNumberOfStudyRelatedInstances(studyPk);

    boolean showRejectedInstances = queryParam.isShowRejectedInstances();
    int numberOfStudyRelatedInstances = showRejectedInstances ? a[3] : a[2];

    // skip match for empty Study
    if (numberOfStudyRelatedInstances == 0)
        return null;

    Utils.setStudyQueryAttributes(attrs, showRejectedInstances ? a[1] : a[0], numberOfStudyRelatedInstances,
            modalitiesInStudy, sopClassesInStudy);
    Utils.setRetrieveAET(attrs, retrieveAETs, externalRetrieveAET);
    Utils.setAvailability(attrs, availability);

    return attrs;
}

From source file:org.dcm4chee.archive.query.impl.InstanceQuery.java

License:LGPL

@Override
public Attributes toAttributes(ScrollableResults results, QueryContext context) {
    Long seriesPk = results.getLong(0);
    String retrieveAETs = results.getString(1);
    Availability availability = (Availability) results.get(2);
    byte[] instByteAttributes = results.getBinary(3);
    if (!seriesPk.equals(this.seriesPk)) {
        this.seriesAttrs = context.getQueryService().getSeriesAttributes(seriesPk, context);
        this.seriesPk = seriesPk;
    }/* w  ww .j a v a 2 s  .c  o  m*/
    Attributes instanceAttrs = new Attributes();
    Utils.decodeAttributes(instanceAttrs, instByteAttributes);
    Attributes attrs = Utils.mergeAndNormalize(seriesAttrs, instanceAttrs);
    Utils.setRetrieveAET(attrs, retrieveAETs);
    Utils.setAvailability(attrs, availability);
    return attrs;
}

From source file:org.dcm4chee.archive.query.impl.SeriesQuery.java

License:LGPL

@Override
public Attributes toAttributes(ScrollableResults results, QueryContext context) {
    Long studyPk = results.getLong(0);
    Long seriesPk = results.getLong(1);
    Integer numberOfInstancesI = results.getInteger(2);
    int numberOfSeriesRelatedInstances;
    String retrieveAETs;/*  w w w.j a v  a  2 s .  com*/
    Availability availability;
    int numberOfSeriesVisibleInstances;
    Date seriesLastUpdateTime;
    if (numberOfInstancesI != null) {
        numberOfSeriesRelatedInstances = numberOfInstancesI;
        if (numberOfSeriesRelatedInstances == 0)
            return null;
        retrieveAETs = results.getString(9);
        availability = (Availability) results.get(10);
        numberOfSeriesVisibleInstances = results.getInteger(11);
        seriesLastUpdateTime = results.getDate(12);
    } else {
        SeriesQueryAttributes seriesView = context.getQueryService().createSeriesView(seriesPk,
                context.getQueryParam());
        numberOfSeriesRelatedInstances = seriesView.getNumberOfInstances();
        if (numberOfSeriesRelatedInstances == 0)
            return null;
        retrieveAETs = seriesView.getRawRetrieveAETs();
        availability = seriesView.getAvailability();
        numberOfSeriesVisibleInstances = seriesView.getNumberOfVisibleInstances();
        seriesLastUpdateTime = seriesView.getLastUpdateTime();
    }

    byte[] seriesAttributes = results.getBinary(13);
    if (!studyPk.equals(this.studyPk)) {
        this.studyAttrs = toStudyAttributes(studyPk, results, context);
        this.studyPk = studyPk;
    }
    Attributes seriesAttrs = new Attributes();
    Utils.decodeAttributes(seriesAttrs, seriesAttributes);
    Attributes attrs = Utils.mergeAndNormalize(studyAttrs, seriesAttrs);
    ArchiveDeviceExtension ade = context.getArchiveAEExtension().getApplicationEntity().getDevice()
            .getDeviceExtension(ArchiveDeviceExtension.class);
    Utils.setSeriesQueryAttributes(attrs, numberOfSeriesRelatedInstances, numberOfSeriesVisibleInstances,
            ade.getPrivateDerivedFields().findSeriesNumberOfVisibleInstancesTag(), seriesLastUpdateTime,
            ade.getPrivateDerivedFields().findSeriesUpdateTimeTag());
    Utils.setRetrieveAET(attrs, retrieveAETs);
    Utils.setAvailability(attrs, availability);

    return attrs;
}