Example usage for java.sql Timestamp getTime

List of usage examples for java.sql Timestamp getTime

Introduction

In this page you can find the example usage for java.sql Timestamp getTime.

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Timestamp object.

Usage

From source file:com.collabnet.ccf.core.EntityService.java

/**
 * For a given source artifact id, source repository and the target
 * repository details, this method finds out the target artifact id mapped
 * to the source artifact id by looking up the identity mapping table.
 * //from   ww  w .ja v  a 2  s .c  o m
 * If the source artifact id had ever passed through the wiring the identity
 * mapping will contain the corresponding target artifact id. This method
 * fetches the target artifact id and returns. If there is no target
 * artifact id mapped to this source artifact id this method return a null.
 * 
 * @param sourceArtifactId
 *            - The source artifact id that should be looked up for a target
 *            artifact id
 * @param sourceSystemId
 *            - The system id of the source repository
 * @param sourceRepositoryId
 *            - The repository id of the source artifact
 * @param targetSystemId
 *            - The system id of the target repository
 * @param targetRepositoryId
 *            - The repository id of the target artifact
 * @param artifactType
 *            - The artifact type
 * 
 * @return array with target artifactId, sourceArtifactLastModifiedDate,
 *         sourceArtifactVersion, targetArtifactVersion (in this order)
 */
private Object[] lookupTargetArtifact(Element element, String sourceArtifactId, String sourceSystemId,
        String sourceRepositoryId, String targetSystemId, String targetRepositoryId, String artifactType) {
    IOrderedMap inputParameters = new OrderedHashMap();

    inputParameters.add(sourceSystemId);
    inputParameters.add(sourceRepositoryId);
    inputParameters.add(targetSystemId);
    inputParameters.add(targetRepositoryId);
    inputParameters.add(sourceArtifactId);
    inputParameters.add(artifactType);
    String artifactAction = null;
    try {
        artifactAction = XPathUtils.getAttributeValue(element, GenericArtifactHelper.ARTIFACT_ACTION);
    } catch (GenericArtifactParsingException e) {
        String cause = "Problem occured while parsing the Document to extract specific attributes";
        log.error(cause, e);
        XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                GenericArtifact.ERROR_GENERIC_ARTIFACT_PARSING);
        throw new CCFRuntimeException(cause, e);
    }
    boolean waitForIdentityMappedEvent = false;
    int waitCount = 0;
    // identityMappingDatabaseReader.disconnect();
    Object[] resultSet = null;
    do {
        identityMappingDatabaseReader.connect();
        resultSet = identityMappingDatabaseReader.next(inputParameters, 1000);
        // identityMappingDatabaseReader.disconnect();
        if (artifactAction.equals(GenericArtifactHelper.ARTIFACT_ACTION_RESYNC)) {
            if (resultSet == null || resultSet.length == 0) {
                if (++waitCount < this.getIdentityMapEventWaitCount()) {
                    waitForIdentityMappedEvent = true;
                    try {
                        log.debug("No identity mapping found for resync request of " + sourceArtifactId + "-"
                                + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId + "-"
                                + targetSystemId + ". Sleeping for " + this.getIdentityMapEventWaitTime()
                                + " milliseconds...");
                        Thread.sleep(this.getIdentityMapEventWaitTime());
                    } catch (InterruptedException e) {
                        // INFO Digesting the interrupt
                    }
                } else {
                    log.warn("There was no prior identity mapping for the resync request " + sourceArtifactId
                            + "-" + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId + "-"
                            + targetSystemId
                            + " in the identity mapping table even after the entity service waited for "
                            + (waitCount * this.getIdentityMapEventWaitTime())
                            + " milliseconds. Discarding the artifact.");
                    waitForIdentityMappedEvent = false;
                }
            } else {
                waitForIdentityMappedEvent = false;
            }
        }
    } while (waitForIdentityMappedEvent);
    Object[] results = null;
    if (resultSet == null || resultSet.length == 0) {
        log.debug(sourceArtifactId + "-" + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId
                + "-" + targetSystemId + " are not mapped.");
    } else if (resultSet.length == 1) {
        if (resultSet[0] instanceof OrderedHashMap) {
            OrderedHashMap result = (OrderedHashMap) resultSet[0];
            if (result.size() == 4) {
                results = new Object[4];
                results[0] = result.get(0);
                Timestamp timeStamp = (Timestamp) result.get(1);
                Date date;
                if (timeStamp == null) {
                    // use earliest date possible
                    date = new Date(0);
                } else {
                    date = new Date(timeStamp.getTime());
                }

                results[1] = date;
                results[2] = result.get(2);
                results[3] = result.get(3);
            } else {
                String cause = "Seems as if the SQL statement for identityMappingDatabase reader does not return 4 values.";
                XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                        GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
                log.error(cause);
                throw new CCFRuntimeException(cause);
            }
        } else {
            String cause = "SQL query on identity mapping table did not return data in correct format!";
            XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                    GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
            log.error(cause);
            throw new CCFRuntimeException(cause);
        }
    } else {
        String cause = "There is more than one mapping for the combination " + sourceArtifactId + "-"
                + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId + "-" + targetSystemId
                + " in the identity mapping table.";
        XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
        log.error(cause);
        throw new CCFRuntimeException(cause);
    }
    return results;
}

From source file:org.eevolution.form.VSCRP.java

public CategoryDataset createDataset(Timestamp start, MResource r) {
    //System.out.println("Create new data set");
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);/*from  w  w  w .  ja  v  a  2s  . co m*/
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    Timestamp date = start;
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    System.out.println("\n Namecapacity :" + namecapacity);
    String nameload = Msg.translate(Env.getCtx(), "Load");
    System.out.println("\n Nameload :" + nameload);
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    System.out.println("\n Namesummary :" + namesummary);
    MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
    System.out.println("\n Resourcetype " + t);
    int days = 1;
    long hours = 0;

    if (t.isTimeSlot()) {

        hours = MMPCMRP.getHoursAvailable(t.getTimeSlotStart(), t.getTimeSlotEnd());

    } else {
        //fjviejo e-evolution MachineQty
        if (r.getDailyCapacity().multiply(r.getMachineQty()).compareTo(Env.ZERO) != 0)
            hours = r.getDailyCapacity().multiply(r.getMachineQty()).longValue();
        else
            //fjviejo e-evolution end
            hours = 24;
    }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //      Long Hours = new Long(hours);                            
    int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ",
            r.getS_Resource_ID());
    MUOM uom = new MUOM(Env.getCtx(), C_UOM_ID, null);
    System.out.println("\n uom1 " + uom + "\n");
    //System.out.println("um.isHour()"+ uom.isHour() );
    if (!uom.isHour()) {
        System.out.println("\n uom2 " + uom + "\n");
        return dataset;
    }
    System.out.println("\n Dataset " + dataset + "\n");
    int summary = 0;
    int secondsAcum = 0;
    long hoursAcum = 0;

    while (days < 29) {
        //System.out.println("Day Number" + days);
        String day = new String(new Integer(date.getDate()).toString());
        System.out.println("r.getS_Resource_ID()" + r.getS_Resource_ID());
        System.out.println("Date:" + date);
        int seconds = getLoad(r.getS_Resource_ID(), date, date);
        Long Hours = new Long(hours);
        System.out.println("Summary " + summary);
        System.out.println("Capacity " + hours);
        System.out.println("Load " + seconds);

        /*
        **  Realizo la verificacin sobre que da me encuentro
        **  para graficar cada 7 dias el estado de la semana.
        **
        **  secondsAcum y hoursAcum llevan los acumulados para la semana
        **  los reinicio en cada nueva semana.
        **
        **  VIT4B - 07/12/2006
        */

        if (days == 1 || days == 8 || days == 15 || days == 22) {
            secondsAcum = 0;
            hoursAcum = 0;
        }

        secondsAcum += seconds;
        hoursAcum += hours;

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SUNDAY:
            if (t.isOnSunday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600); //+ (Hours.intValue() - ((seconds / 3600)));
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.MONDAY:
            if (t.isOnMonday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.TUESDAY:
            if (t.isOnTuesday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.WEDNESDAY:
            if (t.isOnWednesday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.THURSDAY:
            if (t.isOnThursday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.FRIDAY:
            if (t.isOnFriday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.SATURDAY:
            if (t.isOnSaturday()) {
                /*
                                                **  Realizo la verificacin sobre que da me encuentro
                                                **  para graficar cada 7 dias el estado de la semana.
                                                **
                                                **  VIT4B - 07/12/2006
                                                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        }

        days++;

    }
    return dataset;
}

From source file:org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue.java

private Timestamp copyTimestamp(Timestamp timestamp) {
    if (timestamp == null) {
        return null;
    }//from ww w  .ja  v  a2  s.  co m
    return new Timestamp(timestamp.getTime());
}

From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchGeneratorImpl.java

/**
 * Processes the search result row, returning a DocumentSearchResult
 * @param criteria the original search criteria
 * @param searchAttributeStatement statement being used to call the database for queries
 * @param rs the search result set/*  w w w .j  a  v  a2 s .  c  om*/
 * @return a DocumentSearchResult representing the current ResultSet row
 * @throws SQLException
 */
protected DocumentSearchResult.Builder processRow(DocumentSearchCriteria criteria,
        Statement searchAttributeStatement, ResultSet rs) throws SQLException {

    String documentId = rs.getString("DOC_HDR_ID");
    String initiatorPrincipalId = rs.getString("INITR_PRNCPL_ID");
    String documentTypeName = rs.getString("DOC_TYP_NM");
    org.kuali.rice.kew.api.doctype.DocumentType documentType = getApiDocumentTypeService()
            .getDocumentTypeByName(documentTypeName);
    if (documentType == null) {
        throw new IllegalStateException(
                "Failed to locate a document type with the given name: " + documentTypeName);
    }
    String documentTypeId = documentType.getId();

    Document.Builder documentBuilder = Document.Builder.create(documentId, initiatorPrincipalId,
            documentTypeName, documentTypeId);
    DocumentSearchResult.Builder resultBuilder = DocumentSearchResult.Builder.create(documentBuilder);

    String statusCode = rs.getString("DOC_HDR_STAT_CD");
    Timestamp createTimestamp = rs.getTimestamp("CRTE_DT");
    String title = rs.getString("TTL");
    String applicationDocumentStatus = rs.getString("APP_DOC_STAT");

    documentBuilder.setStatus(DocumentStatus.fromCode(statusCode));
    documentBuilder.setDateCreated(new DateTime(createTimestamp.getTime()));
    documentBuilder.setTitle(title);
    documentBuilder.setApplicationDocumentStatus(applicationDocumentStatus);
    documentBuilder.setApplicationDocumentStatusDate(new DateTime(rs.getTimestamp("APP_DOC_STAT_MDFN_DT")));
    documentBuilder.setDateApproved(new DateTime(rs.getTimestamp("APRV_DT")));
    documentBuilder.setDateFinalized(new DateTime(rs.getTimestamp("FNL_DT")));
    documentBuilder.setApplicationDocumentId(rs.getString("APP_DOC_ID"));
    documentBuilder.setDateLastModified(new DateTime(rs.getTimestamp("STAT_MDFN_DT")));
    documentBuilder.setRoutedByPrincipalId(rs.getString("RTE_PRNCPL_ID"));

    // TODO - KULRICE-5755 - should probably set as many properties on the document as we can
    documentBuilder.setDocumentHandlerUrl(rs.getString("DOC_HDLR_URL"));

    if (isUsingAtLeastOneSearchAttribute(criteria)) {
        populateDocumentAttributesValues(resultBuilder, searchAttributeStatement);
    }

    return resultBuilder;
}

From source file:org.kuali.kfs.sys.service.impl.GeneralLedgerPendingEntryServiceImpl.java

/**
 * This populates an empty GeneralLedgerPendingEntry instance with default values for a bank offset. A global error will be
 * posted as a side-effect if the given bank has not defined the necessary bank offset relations.
 *
 * @param bank//from  w w w. j a  va  2 s .c  om
 * @param depositAmount
 * @param financialDocument
 * @param universityFiscalYear
 * @param sequenceHelper
 * @param bankOffsetEntry
 * @param errorPropertyName
 * @return whether the entry was populated successfully
 */
@Override
public boolean populateBankOffsetGeneralLedgerPendingEntry(Bank bank, KualiDecimal depositAmount,
        GeneralLedgerPostingDocument financialDocument, Integer universityFiscalYear,
        GeneralLedgerPendingEntrySequenceHelper sequenceHelper, GeneralLedgerPendingEntry bankOffsetEntry,
        String errorPropertyName) {
    bankOffsetEntry.setFinancialDocumentTypeCode(
            dataDictionaryService.getDocumentTypeNameByClass(financialDocument.getClass()));
    bankOffsetEntry.setVersionNumber(1L);
    bankOffsetEntry.setTransactionLedgerEntrySequenceNumber(sequenceHelper.getSequenceCounter());
    Timestamp transactionTimestamp = new Timestamp(dateTimeService.getCurrentDate().getTime());
    bankOffsetEntry.setTransactionDate(new java.sql.Date(transactionTimestamp.getTime()));
    bankOffsetEntry.setTransactionEntryProcessedTs(transactionTimestamp);
    Account cashOffsetAccount = bank.getCashOffsetAccount();

    if (ObjectUtils.isNull(cashOffsetAccount)) {
        GlobalVariables.getMessageMap().putError(errorPropertyName,
                KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_NO_ACCOUNT, new String[] { bank.getBankCode() });
        return false;
    }

    if (!cashOffsetAccount.isActive()) {
        GlobalVariables.getMessageMap().putError(errorPropertyName,
                KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_ACCOUNT_CLOSED, new String[] { bank.getBankCode(),
                        cashOffsetAccount.getChartOfAccountsCode(), cashOffsetAccount.getAccountNumber() });
        return false;
    }

    if (cashOffsetAccount.isExpired()) {
        GlobalVariables.getMessageMap().putError(errorPropertyName,
                KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_ACCOUNT_EXPIRED, new String[] { bank.getBankCode(),
                        cashOffsetAccount.getChartOfAccountsCode(), cashOffsetAccount.getAccountNumber() });
        return false;
    }

    bankOffsetEntry.setChartOfAccountsCode(bank.getCashOffsetFinancialChartOfAccountCode());
    bankOffsetEntry.setAccountNumber(bank.getCashOffsetAccountNumber());
    bankOffsetEntry.setFinancialDocumentApprovedCode(
            AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE.NO);
    bankOffsetEntry.setTransactionEncumbranceUpdateCode(BLANK_SPACE);
    bankOffsetEntry.setFinancialBalanceTypeCode(BALANCE_TYPE_ACTUAL);
    bankOffsetEntry.setTransactionDebitCreditCode(depositAmount.isPositive() ? GL_DEBIT_CODE : GL_CREDIT_CODE);
    bankOffsetEntry.setFinancialSystemOriginationCode(SpringContext.getBean(HomeOriginationService.class)
            .getHomeOrigination().getFinSystemHomeOriginationCode());
    bankOffsetEntry.setDocumentNumber(financialDocument.getDocumentNumber());

    ObjectCode cashOffsetObject = bank.getCashOffsetObject();
    if (ObjectUtils.isNull(cashOffsetObject)) {
        GlobalVariables.getMessageMap().putError(errorPropertyName,
                KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_NO_OBJECT_CODE, new String[] { bank.getBankCode() });
        return false;
    }

    if (!cashOffsetObject.isFinancialObjectActiveCode()) {
        GlobalVariables.getMessageMap().putError(errorPropertyName,
                KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_INACTIVE_OBJECT_CODE,
                new String[] { bank.getBankCode(), cashOffsetObject.getFinancialObjectCode() });
        return false;
    }

    bankOffsetEntry.setFinancialObjectCode(bank.getCashOffsetObjectCode());
    bankOffsetEntry.setFinancialObjectTypeCode(bank.getCashOffsetObject().getFinancialObjectTypeCode());
    bankOffsetEntry.setOrganizationDocumentNumber(
            financialDocument.getDocumentHeader().getOrganizationDocumentNumber());
    bankOffsetEntry.setOrganizationReferenceId(null);
    bankOffsetEntry.setProjectCode(KFSConstants.getDashProjectCode());
    bankOffsetEntry.setReferenceFinancialDocumentNumber(null);
    bankOffsetEntry.setReferenceFinancialDocumentTypeCode(null);
    bankOffsetEntry.setReferenceFinancialSystemOriginationCode(null);

    if (StringUtils.isBlank(bank.getCashOffsetSubAccountNumber())) {
        bankOffsetEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
    } else {
        SubAccount cashOffsetSubAccount = bank.getCashOffsetSubAccount();
        if (ObjectUtils.isNull(cashOffsetSubAccount)) {
            GlobalVariables.getMessageMap().putError(errorPropertyName,
                    KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_NONEXISTENT_SUB_ACCOUNT,
                    new String[] { bank.getBankCode(), cashOffsetAccount.getChartOfAccountsCode(),
                            cashOffsetAccount.getAccountNumber(), bank.getCashOffsetSubAccountNumber() });
            return false;
        }

        if (!cashOffsetSubAccount.isActive()) {
            GlobalVariables.getMessageMap().putError(errorPropertyName,
                    KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_INACTIVE_SUB_ACCOUNT,
                    new String[] { bank.getBankCode(), cashOffsetAccount.getChartOfAccountsCode(),
                            cashOffsetAccount.getAccountNumber(), bank.getCashOffsetSubAccountNumber() });
            return false;
        }

        bankOffsetEntry.setSubAccountNumber(bank.getCashOffsetSubAccountNumber());
    }

    if (StringUtils.isBlank(bank.getCashOffsetSubObjectCode())) {
        bankOffsetEntry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
    } else {
        SubObjectCode cashOffsetSubObject = bank.getCashOffsetSubObject();
        if (ObjectUtils.isNull(cashOffsetSubObject)) {
            GlobalVariables.getMessageMap().putError(errorPropertyName,
                    KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_NONEXISTENT_SUB_OBJ,
                    new String[] { bank.getBankCode(), cashOffsetAccount.getChartOfAccountsCode(),
                            cashOffsetAccount.getAccountNumber(), cashOffsetObject.getFinancialObjectCode(),
                            bank.getCashOffsetSubObjectCode() });
            return false;
        }

        if (!cashOffsetSubObject.isActive()) {
            GlobalVariables.getMessageMap().putError(errorPropertyName,
                    KFSKeyConstants.ERROR_DOCUMENT_BANK_OFFSET_INACTIVE_SUB_OBJ,
                    new String[] { bank.getBankCode(), cashOffsetAccount.getChartOfAccountsCode(),
                            cashOffsetAccount.getAccountNumber(), cashOffsetObject.getFinancialObjectCode(),
                            bank.getCashOffsetSubObjectCode() });
            return false;
        }

        bankOffsetEntry.setFinancialSubObjectCode(bank.getCashOffsetSubObjectCode());
    }

    bankOffsetEntry.setTransactionEntryOffsetIndicator(true);
    bankOffsetEntry.setTransactionLedgerEntryAmount(depositAmount.abs());
    bankOffsetEntry.setUniversityFiscalPeriodCode(null); // null here, is assigned during batch or in specific document rule
    bankOffsetEntry.setUniversityFiscalYear(universityFiscalYear);
    bankOffsetEntry.setAcctSufficientFundsFinObjCd(getSufficientFundsService()
            .getSufficientFundsObjectCode(cashOffsetObject, cashOffsetAccount.getAccountSufficientFundsCode()));

    return true;
}

From source file:com.collabnet.ccf.core.EntityService.java

/**
 * This method looks up whether the artifact has been quarantined in the
 * hospital and has not been reprocessed yet. If so, it will find out
 * whether to skip the artifact or not./*from  w  w w  . j  a va  2  s .co  m*/
 * 
 * @param sourceArtifactId
 *            - The source artifact id that should be looked up for a target
 *            artifact id
 * @param sourceSystemId
 *            - The system id of the source repository
 * @param sourceRepositoryId
 *            - The repository id of the source artifact
 * @param targetSystemId
 *            - The system id of the target repository
 * @param targetRepositoryId
 *            - The repository id of the target artifact
 * @param artifactType
 *            - The artifact type
 * @param sourceArtifactVersionInt
 *            version of the current artifact
 * @param sourceArtifactLastModifiedDate
 *            last modified date of the current artifact
 * 
 * @return true if artifact should be skipped, false if not
 */
private boolean skipQuarantinedArtifact(Element element, String sourceArtifactId, String sourceSystemId,
        String sourceRepositoryId, String targetSystemId, String targetRepositoryId, String artifactType,
        Date sourceArtifactLastModifiedDate, long sourceArtifactVersionLong,
        boolean onlyCheckIfQuarantinedArtifactExists) {

    // only if a connection to the hospital table is possible we can skip
    // artifacts
    if (getHospitalDatabaseReader() == null) {
        return false;
    }

    IOrderedMap inputParameters = new OrderedHashMap();

    inputParameters.add(sourceSystemId);
    inputParameters.add(sourceRepositoryId);
    inputParameters.add(targetSystemId);
    inputParameters.add(targetRepositoryId);
    inputParameters.add(sourceArtifactId);
    inputParameters.add(artifactType);
    // hospitalDatabaseReader.disconnect();
    hospitalDatabaseReader.connect();
    // TODO Find out whether 10000 is enough in hard cases
    Object[] resultSet = hospitalDatabaseReader.next(inputParameters, 10000);
    // hospitalDatabaseReader.disconnect();
    if (resultSet == null || resultSet.length == 0) {
        // artifact is not in the hospital
        return false;
    } else if (onlyCheckIfQuarantinedArtifactExists) {
        return true;
    } else if (isSkipNewerVersionsOfQuarantinedArtifacts()) {
        // we do not have to compare version numbers since we skip every
        // version of the artifact
        log.warn("At least one entry for combination " + sourceArtifactId + "-" + sourceRepositoryId + "-"
                + sourceSystemId + targetRepositoryId + "-" + targetSystemId
                + " is still in the hospital and not yet reprocessed, skipping it ...");
        return true;
    }

    for (Object resultObject : resultSet) {
        if (resultObject instanceof OrderedHashMap) {
            OrderedHashMap result = (OrderedHashMap) resultObject;
            if (result.size() == 3) {
                Date sourceArtifactLastModifiedDateFromTable;
                String hospitalId = result.get(0).toString();
                Timestamp timeStamp = (Timestamp) result.get(1);
                if (timeStamp == null) {
                    // use earliest date possible
                    sourceArtifactLastModifiedDateFromTable = new Date(0);
                } else {
                    sourceArtifactLastModifiedDateFromTable = new Date(timeStamp.getTime());
                }
                String sourceArtifactVersionFromTable = result.get(2).toString();
                if (sourceArtifactVersionFromTable.equalsIgnoreCase(GenericArtifact.VALUE_UNKNOWN)) {
                    sourceArtifactVersionFromTable = GenericArtifactHelper.ARTIFACT_VERSION_FORCE_RESYNC;
                }
                long sourceArtifactVersionLongFromTable = Long.parseLong(sourceArtifactVersionFromTable);
                if (sourceArtifactLastModifiedDateFromTable.after(sourceArtifactLastModifiedDate)
                        || sourceArtifactVersionLongFromTable >= sourceArtifactVersionLong) {
                    if (sourceArtifactVersionLong == -1 && sourceArtifactVersionLongFromTable == -1) {
                        log.warn(
                                "It seems as if artifact synchronization is done exclusively with a system that does not support version control, so artifact from combination "
                                        + sourceArtifactId + "-" + sourceRepositoryId + "-" + sourceSystemId
                                        + targetRepositoryId + "-" + targetSystemId
                                        + " will not be skipped despite it is in the hospital. Hospital ID: "
                                        + hospitalId);
                    } else {
                        log.warn("Non re-processed artifact from combination " + sourceArtifactId + "-"
                                + sourceRepositoryId + "-" + sourceSystemId + targetRepositoryId + "-"
                                + targetSystemId
                                + " is still in the hospital in a newer or equal version, so skipping it. Hospital ID: "
                                + hospitalId);
                        return true;
                    }
                }
            } else {
                String cause = "Seems as if the SQL statement for hospitalDatabase reader does not return 3 values.";
                XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                        GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
                log.error(cause);
                throw new CCFRuntimeException(cause);
            }
        } else {
            String cause = "SQL query on hospital table did not return data in correct format!";
            XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                    GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
            log.error(cause);
            throw new CCFRuntimeException(cause);
        }
    }
    log.info("Only older non-reprocessed versions of artifact combination " + sourceArtifactId + "-"
            + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId + "-" + targetSystemId
            + " are in the hospital, so pass artifact ...");
    return false;
}

From source file:com.collabnet.ccf.core.EntityService2.java

/**
 * For a given source artifact id, source repository and the target
 * repository details, this method finds out the target artifact id mapped
 * to the source artifact id by looking up the identity mapping table.
 * //  w  ww.j  av  a 2s.  c  om
 * If the source artifact id had ever passed through the wiring the identity
 * mapping will contain the corresponding target artifact id. This method
 * fetches the target artifact id and returns. If there is no target
 * artifact id mapped to this source artifact id this method return a null.
 * 
 * @param sourceArtifactId
 *            - The source artifact id that should be looked up for a target
 *            artifact id
 * @param sourceSystemId
 *            - The system id of the source repository
 * @param sourceRepositoryId
 *            - The repository id of the source artifact
 * @param targetSystemId
 *            - The system id of the target repository
 * @param targetRepositoryId
 *            - The repository id of the target artifact
 * @param artifactType
 *            - The artifact type
 * 
 * @return array with target artifactId, sourceArtifactLastModifiedDate,
 *         sourceArtifactVersion, targetArtifactVersion (in this order)
 */
private Object[] lookupTargetArtifact(Element element, String sourceArtifactId, String sourceSystemId,
        String sourceRepositoryId, String targetSystemId, String targetRepositoryId, String artifactType,
        String repositoryMappingId) {
    IOrderedMap inputParameters = new OrderedHashMap();

    inputParameters.add(repositoryMappingId);
    inputParameters.add(sourceArtifactId);
    inputParameters.add(artifactType);
    String artifactAction = null;
    try {
        artifactAction = XPathUtils.getAttributeValue(element, GenericArtifactHelper.ARTIFACT_ACTION);
    } catch (GenericArtifactParsingException e) {
        String cause = "Problem occured while parsing the Document to extract specific attributes";
        log.error(cause, e);
        XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                GenericArtifact.ERROR_GENERIC_ARTIFACT_PARSING);
        throw new CCFRuntimeException(cause, e);
    }
    boolean waitForIdentityMappedEvent = false;
    int waitCount = 0;
    // identityMappingDatabaseReader.disconnect();
    Object[] resultSet = null;
    do {
        identityMappingDatabaseReader.connect();
        resultSet = identityMappingDatabaseReader.next(inputParameters, 1000);
        // identityMappingDatabaseReader.disconnect();
        if (artifactAction.equals(GenericArtifactHelper.ARTIFACT_ACTION_RESYNC)) {
            if (resultSet == null || resultSet.length == 0) {
                if (++waitCount < this.getIdentityMapEventWaitCount()) {
                    waitForIdentityMappedEvent = true;
                    try {
                        log.debug("No identity mapping found for resync request of " + sourceArtifactId + "-"
                                + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId + "-"
                                + targetSystemId + ". Sleeping for " + this.getIdentityMapEventWaitTime()
                                + " milliseconds...");
                        Thread.sleep(this.getIdentityMapEventWaitTime());
                    } catch (InterruptedException e) {
                        // INFO Digesting the interrupt
                    }
                } else {
                    log.warn("There was no prior identity mapping for the resync request " + sourceArtifactId
                            + "-" + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId + "-"
                            + targetSystemId
                            + " in the identity mapping table even after the entity service waited for "
                            + (waitCount * this.getIdentityMapEventWaitTime())
                            + " milliseconds. Discarding the artifact.");
                    waitForIdentityMappedEvent = false;
                }
            } else {
                waitForIdentityMappedEvent = false;
            }
        }
    } while (waitForIdentityMappedEvent);
    Object[] results = null;
    if (resultSet == null || resultSet.length == 0) {
        log.debug(sourceArtifactId + "-" + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId
                + "-" + targetSystemId + " are not mapped.");
    } else if (resultSet.length == 1) {
        if (resultSet[0] instanceof OrderedHashMap) {
            OrderedHashMap result = (OrderedHashMap) resultSet[0];
            if (result.size() == 4) {
                results = new Object[4];
                results[0] = result.get(0);
                Timestamp timeStamp = (Timestamp) result.get(1);
                Date date;
                if (timeStamp == null) {
                    // use earliest date possible
                    date = new Date(0);
                } else {
                    date = new Date(timeStamp.getTime());
                }

                results[1] = date;
                results[2] = result.get(2);
                results[3] = result.get(3);
            } else {
                String cause = "Seems as if the SQL statement for identityMappingDatabase reader does not return 4 values.";
                XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                        GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
                log.error(cause);
                throw new CCFRuntimeException(cause);
            }
        } else {
            String cause = "SQL query on identity mapping table did not return data in correct format!";
            XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                    GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
            log.error(cause);
            throw new CCFRuntimeException(cause);
        }
    } else {
        String cause = "There is more than one mapping for the combination " + sourceArtifactId + "-"
                + sourceRepositoryId + "-" + sourceSystemId + "-" + targetRepositoryId + "-" + targetSystemId
                + " in the identity mapping table.";
        XPathUtils.addAttribute(element, GenericArtifactHelper.ERROR_CODE,
                GenericArtifact.ERROR_INTERNAL_DATABASE_TABLE_CORRUPT);
        log.error(cause);
        throw new CCFRuntimeException(cause);
    }
    return results;
}

From source file:com.flexive.core.search.PropertyEntry.java

/**
 * Decodes a daterange result value consisting of two date columns.
 * @param rs    the result set//from www.  j a  va2 s.  c  o m
 * @param pos   the position of the first date column
 * @param secondDateOffset  the offset for the second date column
 * @return      the decoded dates. If a column is null, the corresponding entry is also null.
 * @throws SQLException if the column datatypes don't match
 */
private Pair<Date, Date> decodeDateRange(ResultSet rs, int pos, int secondDateOffset) throws SQLException {
    final Timestamp fromTimestamp = rs.getTimestamp(pos); // FDATE1
    final Timestamp toTimestamp = rs.getTimestamp(pos + secondDateOffset); // FDATE2
    final Date from = fromTimestamp != null ? new Date(fromTimestamp.getTime()) : null;
    final Date to = toTimestamp != null ? new Date(toTimestamp.getTime()) : null;
    return new Pair<Date, Date>(from, to);
}

From source file:nl.sidn.pcap.parquet.ICMPParquetPacketWriter.java

@Override
public void write(PacketCombination packetCombo) {

    GenericRecordBuilder builder = newBuilder();

    ICMPPacket icmpPacket = (ICMPPacket) packetCombo.getRequest();

    Packet originalPacket = null;//from www  .  j av a  2  s.c o  m
    Message dnsResponseMessage = null;
    ICMPPacket originalICMPPacket = null;

    packetCounter++;
    if (packetCounter % STATUS_COUNT == 0) {
        showStatus();
    }

    //get message .nl auth send to client and which is returned in the icmp payload
    if (icmpPacket.getOriginalIPPacket() != null && icmpPacket.getOriginalIPPacket() != Packet.NULL) {
        originalPacket = icmpPacket.getOriginalIPPacket();
    }

    if (originalPacket instanceof DNSPacket) {
        dnsResponseMessage = ((DNSPacket) originalPacket).getMessage();
    } else if (originalPacket instanceof ICMPPacket) {
        originalICMPPacket = (ICMPPacket) originalPacket;
    }

    //icmp packet ip+headers
    Timestamp packetTime = new Timestamp((icmpPacket.getTs() * 1000));
    String country = getCountry(icmpPacket.getSrc());
    String asn = getAsn(icmpPacket.getSrc(), icmpPacket.getIpVersion() == 4);

    //icmp payload   
    Question q = null;
    Header dnsResponseHdr = null;
    Domaininfo domaininfo = null;
    String normalizedQname = null;

    if (dnsResponseMessage != null) {
        //malformed (bad_format) message can have missing question
        if (dnsResponseMessage.getQuestions().size() > 0) {
            q = dnsResponseMessage.getQuestions().get(0);
        }
        dnsResponseHdr = dnsResponseMessage.getHeader();
        normalizedQname = q == null ? "" : filter(q.getqName());
        normalizedQname = StringUtils.lowerCase(normalizedQname);
        domaininfo = NameUtil.getDomain(normalizedQname, Settings.getTldSuffixes());
    }

    //values from query now.
    builder.set("svr", packetCombo.getServer().getName()).set("unixtime", icmpPacket.getTs())
            .set("time_micro", icmpPacket.getTsmicros()).set("time", packetTime.getTime())
            .set("icmp_type", icmpPacket.getType()).set("icmp_code", icmpPacket.getCode())
            .set("icmp_echo_client_type", icmpPacket.getClientType()).set("ip_ttl", icmpPacket.getTtl())
            .set("ip_v", (int) icmpPacket.getIpVersion()).set("ip_src", icmpPacket.getSrc())
            .set("ip_dst", icmpPacket.getDst()).set("ip_country", country).set("ip_asn", asn)
            .set("l4_prot", (int) icmpPacket.getProtocol()).set("l4_srcp", icmpPacket.getSrcPort())
            .set("l4_dstp", icmpPacket.getDstPort()).set("ip_len", icmpPacket.getTotalLength()); //size of ip packet incl headers

    //add file name
    builder.set("pcap_file", packetCombo.getPcapFilename());

    //if no anycast location is encoded in the name then the anycast server name and location will be null
    //only store this column in case of anycast, to save storage space.
    //the server name can be determined with the "svr" column
    builder.set("server_location", packetCombo.getServer().getLocation());

    //orig packet from payload

    if (originalPacket != null && originalPacket != Packet.NULL) {

        builder.set("orig_ip_ttl", originalPacket.getTtl())
                .set("orig_ip_v", (int) originalPacket.getIpVersion())
                .set("orig_ip_src", originalPacket.getSrc()).set("orig_ip_dst", originalPacket.getDst())
                .set("orig_l4_prot", (int) originalPacket.getProtocol())
                .set("orig_l4_srcp", originalPacket.getSrcPort())
                .set("orig_l4_dstp", originalPacket.getDstPort())
                .set("orig_udp_sum", originalPacket.getUdpsum())
                .set("orig_ip_len", originalPacket.getTotalLength()); //size of ip packet incl headers

        if (originalICMPPacket != null) {
            builder.set("orig_icmp_type", originalICMPPacket.getType())
                    .set("orig_icmp_code", originalICMPPacket.getCode())
                    .set("orig_icmp_echo_client_type", originalICMPPacket.getClientType());
        }

        if (dnsResponseMessage != null) {
            //orig dns response from icmp packet
            builder.set("orig_dns_len", originalPacket.getPayloadLength()) //get the size from the reassembled udp header of the original udp response
                    .set("orig_dns_id", dnsResponseHdr.getId()).set("orig_dns_qname", normalizedQname)
                    .set("orig_dns_domainname", domaininfo.name).set("orig_dns_aa", dnsResponseHdr.isAa())
                    .set("orig_dns_tc", dnsResponseHdr.isTc()).set("orig_dns_rd", dnsResponseHdr.isRd())
                    .set("orig_dns_ra", dnsResponseHdr.isRa()).set("orig_dns_z", dnsResponseHdr.isZ())
                    .set("orig_dns_ad", dnsResponseHdr.isAd()).set("orig_dns_cd", dnsResponseHdr.isCd())
                    .set("orig_dns_ancount", (int) dnsResponseHdr.getAnCount())
                    .set("orig_dns_arcount", (int) dnsResponseHdr.getArCount())
                    .set("orig_dns_nscount", (int) dnsResponseHdr.getNsCount())
                    .set("orig_dns_qdcount", (int) dnsResponseHdr.getQdCount())
                    .set("orig_dns_rcode", dnsResponseHdr.getRawRcode())
                    .set("orig_dns_opcode", dnsResponseHdr.getRawOpcode())
                    //set edns0 defaults
                    .set("orig_dns_edns_udp", null).set("orig_dns_edns_version", null)
                    .set("orig_dns_edns_do", null).set("orig_dns_labels", domaininfo.labels);

            if (q != null) {
                //unassinged, private or unknown, get raw value
                builder.set("orig_dns_qtype", q.getqTypeValue());
                //unassinged, private or unknown, get raw value
                builder.set("orig_dns_qclass", q.getqClassValue());
            }

            OPTResourceRecord opt = dnsResponseMessage.getPseudo();
            if (opt != null) {
                builder.set("orig_dns_edns_udp", (int) opt.getUdpPlayloadSize())
                        .set("orig_dns_edns_version", (int) opt.getVersion())
                        .set("orig_dns_edns_do", opt.getDnssecDo());
            }
        }
    }

    GenericRecord record = builder.build();
    writer.write(record);

    //write stats
    if (icmpPacket.isIPv4()) {
        v4++;
        updateMetricMap(types_v4, new Integer(icmpPacket.getType()));
    } else {
        v6++;
        updateMetricMap(types_v6, new Integer(icmpPacket.getType()));
    }

    if (icmpPacket.isError()) {
        typeError++;
    } else {
        typeInfo++;
    }
}

From source file:com.alfaariss.oa.engine.requestor.jdbc.JDBCFactory.java

/**
 * Establish the most recent timestamp from the two Timestamps; returns -1 when 
 * @param ts1 Value for date 1; may be null
 * @param ts2 Value for date 2; may be null
 * @return Most recent date in ms since 1970, or -1 when it could not be established
 *///from  w w  w . j a  va 2 s  .c o  m
private long getMostRecentDate(Timestamp ts1, Timestamp ts2) {
    // Both null? Then we don't know
    if (ts1 == null && ts2 == null)
        return -1;

    // Not both null, but tsPool is null? Then tsRequestors contains the time we want
    if (ts1 == null)
        return ts2.getTime();
    // Or tsPool is it when tsRequestors is null...
    if (ts2 == null)
        return ts1.getTime();

    // So, both are non-null; which one is most recent:
    if (ts1.before(ts2))
        return ts2.getTime();
    return ts1.getTime();
}