Example usage for org.hibernate ScrollableResults getDate

List of usage examples for org.hibernate ScrollableResults getDate

Introduction

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

Prototype

Date getDate(int col);

Source Link

Document

Convenience method to read a Date.

Usage

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

License:Apache License

@Override
@Transactional(readOnly = true)//from   w ww .j a  va2s  . 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

protected Long getLong(ScrollableResults rs, String[] returnAliases, ColumnMapping columnMapping) {
    int index = -1;
    if (columnMapping.isUsingColumnIndex()) {
        index = columnMapping.getColumnIndex();
    } else {/* ww  w  .  ja  v a  2  s .co  m*/
        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.compass.gps.device.hibernate.scrollable.Hibernate3Dialect.java

License:Apache License

protected Long getDateAsLong(ScrollableResults rs, String[] returnAliases, ColumnMapping columnMapping) {
    Date date = null;/*from w  w  w .  ja va 2  s  .c om*/
    if (columnMapping.isUsingColumnIndex()) {
        date = rs.getDate(columnMapping.getColumnIndex());
    } else {
        date = rs.getDate(getIndex(returnAliases, columnMapping));
    }
    return new Long(date.getTime());
}

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

License:Apache License

protected Long getTimeAsLong(ScrollableResults rs, String[] returnAliases, ColumnMapping columnMapping) {
    Date date = null;/*from ww  w.java 2s.c  om*/
    if (columnMapping.isUsingColumnIndex()) {
        date = rs.getDate(columnMapping.getColumnIndex());
    } else {
        date = rs.getDate(getIndex(returnAliases, columnMapping));
    }
    return new Long(date.getTime());
}

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

License:Apache License

protected Long getTimestampAsLong(ScrollableResults rs, String[] returnAliases, ColumnMapping columnMapping) {
    Date timestamp = null;/*  ww  w . ja  v a2 s. c  o  m*/
    if (columnMapping.isUsingColumnIndex()) {
        timestamp = rs.getDate(columnMapping.getColumnIndex());
    } else {
        timestamp = rs.getDate(getIndex(returnAliases, columnMapping));
    }
    return new Long(timestamp.getTime());
}

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;//from w  ww. jav  a  2s.c o m
    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;
}

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

License:LGPL

private Attributes toStudyAttributes(Long studyPk, ScrollableResults results, QueryContext context) {
    Integer numberOfInstancesI = results.getInteger(3);
    int numberOfStudyRelatedInstances;
    int numberOfStudyRelatedSeries;
    String modalitiesInStudy;//from  w ww .ja  v a2s . c o m
    String sopClassesInStudy;
    int numberOfStudyVisibleInstances;
    Date studyLastUpdateTime;
    if (numberOfInstancesI != null) {
        numberOfStudyRelatedInstances = numberOfInstancesI;
        numberOfStudyRelatedSeries = results.getInteger(4);
        modalitiesInStudy = results.getString(5);
        sopClassesInStudy = results.getString(6);
        numberOfStudyVisibleInstances = results.getInteger(7);
        studyLastUpdateTime = results.getDate(8);
    } else {
        StudyQueryAttributes studyView = context.getQueryService().createStudyView(studyPk,
                context.getQueryParam());
        numberOfStudyRelatedInstances = studyView.getNumberOfInstances();
        numberOfStudyRelatedSeries = studyView.getNumberOfSeries();
        modalitiesInStudy = studyView.getRawModalitiesInStudy();
        sopClassesInStudy = studyView.getRawSOPClassesInStudy();
        numberOfStudyVisibleInstances = studyView.getNumberOfVisibleInstances();
        studyLastUpdateTime = studyView.getLastUpdateTime();
    }

    byte[] studyByteAttributes = results.getBinary(14);
    byte[] patientByteAttributes = results.getBinary(15);
    Attributes patientAttrs = new Attributes();
    Attributes studyAttrs = new Attributes();
    Utils.decodeAttributes(patientAttrs, patientByteAttributes);
    Utils.decodeAttributes(studyAttrs, studyByteAttributes);
    Attributes attrs = Utils.mergeAndNormalize(patientAttrs, studyAttrs);
    ArchiveDeviceExtension ade = context.getArchiveAEExtension().getApplicationEntity().getDevice()
            .getDeviceExtension(ArchiveDeviceExtension.class);
    Utils.setStudyQueryAttributes(attrs, numberOfStudyRelatedSeries, numberOfStudyRelatedInstances,
            modalitiesInStudy, sopClassesInStudy, numberOfStudyVisibleInstances,
            ade.getPrivateDerivedFields().findStudyNumberOfVisibleInstancesTag(), studyLastUpdateTime,
            ade.getPrivateDerivedFields().findStudyUpdateTimeTag());

    return attrs;
}

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

License:LGPL

@Override
public Attributes toAttributes(ScrollableResults results, QueryContext context) {
    Long studyPk = results.getLong(0);
    Integer numberOfInstancesI = results.getInteger(1);
    int numberOfStudyRelatedInstances;
    int numberOfStudyRelatedSeries;
    String modalitiesInStudy;/*from   w w w . j av a 2  s . co m*/
    String sopClassesInStudy;
    String retrieveAETs;
    Availability availability;
    int numberOfStudyVisibleInstances;
    Date studyLastUpdateTime;
    if (numberOfInstancesI != null) {
        numberOfStudyRelatedInstances = numberOfInstancesI;
        if (numberOfStudyRelatedInstances == 0)
            return null;

        numberOfStudyRelatedSeries = results.getInteger(2);
        modalitiesInStudy = results.getString(3);
        sopClassesInStudy = results.getString(4);
        retrieveAETs = results.getString(5);
        availability = (Availability) results.get(6);
        numberOfStudyVisibleInstances = results.getInteger(7);
        studyLastUpdateTime = results.getDate(8);
    } else {
        StudyQueryAttributes studyView = context.getQueryService().createStudyView(studyPk,
                context.getQueryParam());
        numberOfStudyRelatedInstances = studyView.getNumberOfInstances();
        if (numberOfStudyRelatedInstances == 0)
            return null;

        numberOfStudyRelatedSeries = studyView.getNumberOfSeries();
        modalitiesInStudy = studyView.getRawModalitiesInStudy();
        sopClassesInStudy = studyView.getRawSOPClassesInStudy();
        retrieveAETs = studyView.getRawRetrieveAETs();
        availability = studyView.getAvailability();
        numberOfStudyVisibleInstances = studyView.getNumberOfVisibleInstances();
        studyLastUpdateTime = studyView.getLastUpdateTime();
    }

    byte[] studyByteAttributes = results.getBinary(9);
    byte[] patientByteAttributes = results.getBinary(10);
    Attributes patientAttrs = new Attributes();
    Attributes studyAttrs = new Attributes();
    Utils.decodeAttributes(patientAttrs, patientByteAttributes);
    Utils.decodeAttributes(studyAttrs, studyByteAttributes);
    Attributes attrs = Utils.mergeAndNormalize(patientAttrs, studyAttrs);
    ArchiveDeviceExtension ade = context.getArchiveAEExtension().getApplicationEntity().getDevice()
            .getDeviceExtension(ArchiveDeviceExtension.class);
    Utils.setStudyQueryAttributes(attrs, numberOfStudyRelatedSeries, numberOfStudyRelatedInstances,
            modalitiesInStudy, sopClassesInStudy, numberOfStudyVisibleInstances,
            ade.getPrivateDerivedFields().findStudyNumberOfVisibleInstancesTag(), studyLastUpdateTime,
            ade.getPrivateDerivedFields().findStudyUpdateTimeTag());
    Utils.setRetrieveAET(attrs, retrieveAETs);
    Utils.setAvailability(attrs, availability);
    return attrs;
}