Example usage for java.sql Time toString

List of usage examples for java.sql Time toString

Introduction

In this page you can find the example usage for java.sql Time toString.

Prototype

@SuppressWarnings("deprecation")
public String toString() 

Source Link

Document

Formats a time in JDBC time escape format.

Usage

From source file:org.gdms.driver.csv.CSVDriver.java

@Override
public String getStatementString(Time t) {
    return t.toString();
}

From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java

/**
 * Produce an XML message for an instance of the Time.
 * <br>//  ww  w .  j ava 2 s.c o m
 * @param object the instance for which the message is to be produced.
 * @param parent the XML element that is to be the parent of the produced XML message.
 * @return the root element of the XML segment that was produced.
 * @exception JDOMException if there is an error producing the message.
 */
private Element produceMsg(Time object, Element parent) throws JDOMException {

    // ----------------------
    // Create the Time element ...
    // ----------------------
    Element timeElement = new Element(TagNames.Elements.TIME);
    timeElement.setText(object.toString());
    if (parent != null) {
        timeElement = parent.addContent(timeElement);
    }

    return timeElement;
}

From source file:org.ojbc.adapters.analyticaldatastore.processor.IncidentReportProcessor.java

@Transactional
public void processReport(Document incidentReport) throws Exception {
    Incident incident = new Incident();

    String rootElemntName = incidentReport.getDocumentElement().getLocalName();
    if (INCIDENT_REPORT_ROOT_ELEMENT_NAME.equals(rootElemntName)) {
        incident.setRecordType('N');
    } else if (INCIDENT_REPORT_UPDATE_ROOT_ELEMENT_NAME.equals(rootElemntName)) {
        incident.setRecordType('U');
    }//from w w  w.  j  a v  a2 s.c  o  m

    String reportingAgencyName = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DIGEST
            + "/lexsdigest:EntityOrganization/nc:Organization[@s:id= " + PATH_TO_LEXS_DIGEST
            + " /lexsdigest:Associations/nc:ActivityReportingOrganizationAssociation[nc:ActivityReference/@s:ref="
            + PATH_TO_LEXS_DIGEST
            + "/lexsdigest:EntityActivity/nc:Activity[nc:ActivityCategoryText='Incident']/@s:id]/nc:OrganizationReference/@s:ref]/nc:OrganizationName");
    log.debug("Agency Name: " + reportingAgencyName);

    String reportingAgencyORI = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE
            + "/lexs:PackageMetadata/lexs:DataOwnerMetadata/lexs:DataOwnerIdentifier/lexs:ORI");
    log.debug("Agency ORI: " + reportingAgencyORI);

    Integer reportingAgencyId = null;

    if (StringUtils.isNotBlank(reportingAgencyORI)) {
        reportingAgencyId = analyticalDatastoreDAO.searchForAgenyIDbyAgencyORI(reportingAgencyORI);

        if (reportingAgencyId == null) {
            throw new Exception("Valid Agency ORI required for incident.  Agency Name is: "
                    + reportingAgencyName + ", Agency ORI is: " + reportingAgencyORI);
        }

        incident.setReportingAgencyID(reportingAgencyId);
    } else {
        throw new Exception("Valid Agency ORI required for incident.  Agency Name is: "
                + StringUtils.trimToEmpty(reportingAgencyName) + ", Agency ORI is: "
                + StringUtils.trimToEmpty(reportingAgencyORI));
    }

    String incidentCaseNumber = XmlUtils.xPathStringSearch(incidentReport,
            PATH_TO_LEXS_DATA_ITEM_PACKAGE + "/lexs:PackageMetadata/lexs:DataItemID");
    log.debug("Incident Case Number: " + incidentCaseNumber);

    if (StringUtils.isNotBlank(incidentCaseNumber)) {
        incident.setIncidentCaseNumber(incidentCaseNumber);
    }

    //Check to see if incident(s) already exists
    List<Incident> incidents = analyticalDatastoreDAO
            .searchForIncidentsByIncidentNumberAndReportingAgencyID(incidentCaseNumber, reportingAgencyId);

    //if incidents exist, delete them prior to inserting a new one
    if (incidents.size() > 1) {
        throw new IllegalStateException(
                "Error condition. Duplicate records with same incident number and agency ID exists in database");
    }

    Integer incidentIDToReplace = null;

    if (incidents.size() == 1) {
        incidentIDToReplace = incidents.get(0).getIncidentID();
        incident.setIncidentID(incidentIDToReplace);
        log.debug("Incident ID to replace: " + incidentIDToReplace);

        analyticalDatastoreDAO.deleteIncident(incidents.get(0).getIncidentID());
    }

    String reportingSystem = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE
            + "/lexs:PackageMetadata/lexs:DataOwnerMetadata/lexs:DataOwnerIdentifier/lexs:SystemID");
    incident.setReportingSystem(reportingSystem);

    //Look for either incident date/time or incident date field
    String incidentDateTimeAsString = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DIGEST
            + "/lexsdigest:EntityActivity/nc:Activity/nc:ActivityDateRange/nc:StartDate/nc:DateTime");
    log.debug("Incident Date/Time: " + incidentDateTimeAsString);

    if (StringUtils.isNotEmpty(incidentDateTimeAsString)) {
        Calendar incidentDateTimeCal = DatatypeConverter.parseDateTime(incidentDateTimeAsString);
        Date incidentDateTime = incidentDateTimeCal.getTime();

        if (incidentDateTime != null) {
            incident.setIncidentDate(incidentDateTime);
        }

        Time incidentTime = new Time(incidentDateTime.getTime());
        log.debug("Incident Time: " + incidentTime.toString());

        if (incidentTime != null) {
            incident.setIncidentTime(incidentTime);
        }
    } else {
        String incidentDateAsString = XmlUtils.xPathStringSearch(incidentReport,
                PATH_TO_LEXS_DIGEST + "/lexsdigest:EntityActivity/nc:Activity/nc:ActivityDate/nc:Date");
        log.debug("Incident Date: " + incidentDateAsString);

        Calendar incidentDateCal = DatatypeConverter.parseDate(incidentDateAsString);
        Date incidentDate = incidentDateCal.getTime();

        if (incidentDate != null) {
            incident.setIncidentDate(incidentDate);
        }

    }

    String mapHorizontalCoordinateText = XmlUtils.xPathStringSearch(incidentReport,
            PATH_TO_LEXS_DATA_ITEM_PACKAGE
                    + "/lexs:StructuredPayload/inc-ext:IncidentReport/inc-ext:Location/nc:LocationMapLocation/nc:MapHorizontalCoordinateText");

    if (StringUtils.isNotBlank(mapHorizontalCoordinateText)) {
        //TODO: put this into a strategy
        try {
            mapHorizontalCoordinateText = updatedCoordinate(mapHorizontalCoordinateText);
            log.debug("Map horizontal coordinate text: " + mapHorizontalCoordinateText);

            BigDecimal longitude = new BigDecimal(mapHorizontalCoordinateText);
            incident.setIncidentLocationLongitude(longitude);
        } catch (Exception ex) {
            log.warn("Unable to set map horizontal text coordinate");
        }
    }

    String mapVerticalCoordinateText = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE
            + "/lexs:StructuredPayload/inc-ext:IncidentReport/inc-ext:Location/nc:LocationMapLocation/nc:MapVerticalCoordinateText");

    if (StringUtils.isNotBlank(mapVerticalCoordinateText)) {
        //TODO: put this into a strategy
        try {
            mapVerticalCoordinateText = updatedCoordinate(mapVerticalCoordinateText);
            log.debug("Map vertical coordinate text: " + mapVerticalCoordinateText);

            BigDecimal latitude = new BigDecimal(mapVerticalCoordinateText);
            incident.setIncidentLocationLatitude(latitude);
        } catch (Exception ex) {
            log.warn("Unable to set map vertical text coordinate");
        }
    }

    String incidentLocationReference = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DIGEST
            + "/lexsdigest:Associations/lexsdigest:IncidentLocationAssociation/nc:LocationReference/@s:ref");

    if (StringUtils.isNotEmpty(incidentLocationReference)) {
        Node locationNode = XmlUtils.xPathNodeSearch(incidentReport, PATH_TO_LEXS_DIGEST
                + "/lexsdigest:EntityLocation/nc:Location[@s:id='" + incidentLocationReference + "']");

        String streetFullText = XmlUtils.xPathStringSearch(locationNode,
                "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetFullText");
        log.debug("Street Full Text: " + streetFullText);

        if (StringUtils.isNotBlank(streetFullText)) {
            incident.setIncidentLocationStreetAddress(streetFullText);
        } else {
            String streetNumberText = XmlUtils.xPathStringSearch(locationNode,
                    "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetNumberText");
            log.debug("Street Number Text: " + streetNumberText);

            String streetName = XmlUtils.xPathStringSearch(locationNode,
                    "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetName");
            log.debug("Street Name Text: " + streetName);

            String streetCategoryText = XmlUtils.xPathStringSearch(locationNode,
                    "nc:LocationAddress/nc:StructuredAddress/nc:LocationStreet/nc:StreetCategoryText");
            log.debug("Street Category Text: " + streetCategoryText);

            streetFullText = streetNumberText + streetName + streetFullText;
            log.debug("Street Full Text built from number, name and category: " + streetFullText);

            if (StringUtils.isNotBlank(streetFullText)) {
                incident.setIncidentLocationStreetAddress(streetFullText);
            }

        }

        String cityTown = XmlUtils.xPathStringSearch(locationNode,
                "nc:LocationAddress/nc:StructuredAddress/nc:LocationCityName");
        log.debug("City/Town: " + cityTown);

        if (StringUtils.isNotBlank(cityTown)) {
            incident.setIncidentLocationTown(cityTown);
        }

    }

    Integer incidentPk = analyticalDatastoreDAO.saveIncident(incident);

    //Add Incident Description Text
    processIncidentType(incidentReport, incidentPk);

    //Save circumstance codes
    processCircumstanceCodes(incidentReport, incidentPk);

    processArrests(incidentReport, incidentPk, reportingSystem);

}

From source file:org.ojbc.adapters.analyticaldatastore.processor.IncidentReportProcessor.java

protected void processArrests(Document incidentReport, Integer incidentPk, String reportingSystem)
        throws Exception {
    NodeList arrestSubjectAssocationNodes = XmlUtils.xPathNodeListSearch(incidentReport,
            PATH_TO_LEXS_DIGEST + "/lexsdigest:Associations/lexsdigest:ArrestSubjectAssociation");

    if (arrestSubjectAssocationNodes == null || arrestSubjectAssocationNodes.getLength() == 0) {
        log.debug("No Arrest nodes in document");
        return;// ww w.java 2  s  . co m
    }

    for (int i = 0; i < arrestSubjectAssocationNodes.getLength(); i++) {
        Arrest arrest = new Arrest();

        arrest.setIncidentID(incidentPk);
        arrest.setReportingSystem(reportingSystem);

        if (arrestSubjectAssocationNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
            String personId = XmlUtils.xPathStringSearch(arrestSubjectAssocationNodes.item(i),
                    "nc:PersonReference/@s:ref");
            log.debug("Arrestee Person ID: " + personId);

            String arrestId = XmlUtils.xPathStringSearch(arrestSubjectAssocationNodes.item(i),
                    "nc:ActivityReference/@s:ref");
            log.debug("Arrest ID: " + arrestId);

            Node personNode = XmlUtils.xPathNodeSearch(incidentReport, PATH_TO_LEXS_DIGEST
                    + "/lexsdigest:EntityPerson/lexsdigest:Person[@s:id='" + personId + "']");

            Map<String, Object> arrestee = AnalyticalDataStoreUtils.retrieveMapOfPersonAttributes(personNode);
            String personIdentifierKey = identifierGenerationStrategy.generateIdentifier(arrestee);
            log.debug("Arrestee person identifier keys: " + personIdentifierKey);

            String personBirthDateAsString = (String) arrestee
                    .get(IdentifierGenerationStrategy.BIRTHDATE_FIELD);
            String personRace = (String) arrestee.get("personRace");

            if (StringUtils.isBlank(personRace)) {
                personRace = XmlUtils.xPathStringSearch(incidentReport, PATH_TO_LEXS_DATA_ITEM_PACKAGE
                        + "/lexs:StructuredPayload/ndexia:IncidentReport/ndexia:Person/ndexia:PersonAugmentation[lexslib:SameAsDigestReference/@lexslib:ref='"
                        + personId + "']/ndexia:PersonRaceCode");
                log.debug("Person race retrieved from ndex payload: " + personRace);
            }

            String personSex = (String) arrestee.get(IdentifierGenerationStrategy.SEX_FIELD);

            int personPk = savePerson(personBirthDateAsString, personSex, personRace, personIdentifierKey);
            arrest.setPersonID(personPk);

            Date arrestDateTime = returnArrestDate(incidentReport, arrestSubjectAssocationNodes.item(i));

            arrest.setArrestDate(arrestDateTime);

            Time arrestTime = new Time(arrestDateTime.getTime());
            log.debug("Arrest Time: " + arrestTime.toString());

            arrest.setArrestTime(arrestTime);

            String arrestingAgency = returnArrestingAgency(incidentReport);
            log.debug("Arresting Agency: " + arrestingAgency);

            if (StringUtils.isNotBlank(arrestingAgency)) {
                arrest.setArrestingAgencyName(arrestingAgency);
            }

            //Save arrest
            int arrestPk = analyticalDatastoreDAO.saveArrest(arrest);

            //Save Charges
            processArrestCharge(incidentReport, arrestPk, arrestId);
        }
    }
}

From source file:org.openmrs.module.sync.serialization.TimestampNormalizer.java

public String toString(Object o) {

    java.sql.Date d;/*from w w  w . j a  v a  2 s  .co m*/
    java.sql.Time t;
    long time;
    String result = null;

    if (o instanceof java.sql.Timestamp) { //this is how hibernate recreates Date objects
        SimpleDateFormat dfm = new SimpleDateFormat(TimestampNormalizer.DATETIME_MASK);
        result = dfm.format((Date) o);
    } else if (o instanceof java.sql.Date) {
        d = (java.sql.Date) o;
        t = new java.sql.Time(d.getTime());
        result = d.toString() + ' ' + t.toString();
    } else if (o instanceof java.util.Date) {
        SimpleDateFormat dfm = new SimpleDateFormat(TimestampNormalizer.DATETIME_MASK);
        result = dfm.format((Date) o);
        ;
    } else if (o instanceof java.util.Calendar) {
        time = ((java.util.Calendar) o).getTime().getTime();
        d = new java.sql.Date(time);
        t = new java.sql.Time(time);
        result = d.toString() + ' ' + t.toString();
    } else {
        log.warn("Unknown class in timestamp " + o.getClass().getName());
        result = o.toString();//ugh
    }

    return result;
}