Example usage for org.joda.time LocalDate LocalDate

List of usage examples for org.joda.time LocalDate LocalDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate LocalDate.

Prototype

public LocalDate(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:com.teamj.distribuidas.web.ExcursionUserBean.java

public String duracion(Date salida, Date retorno) {
    int days = Days.daysBetween(new LocalDate(salida), new LocalDate(retorno)).getDays();
    return String.valueOf(days);
}

From source file:com.tkmtwo.sarapi.convert.ValueToLocalDateConverter.java

License:Apache License

@Override
public LocalDate convert(Value v) {
    if (v == null || v.getValue() == null || v.getDataType() == DataType.NULL) {
        return null;
    }/* ww  w . ja  va2 s  .co  m*/

    if (!v.getDataType().equals(DataType.DATE)) {
        throw new InvalidValueAccessException("Value is not a DataType.DATE");
    }

    Object o = v.getValue();
    if (o instanceof DateInfo == false) {
        throw new InvalidValueAccessException("Value is not an DateInfo");
    }

    DateInfo di = (DateInfo) o;
    return new LocalDate(di.GetDate());
}

From source file:com.tourapp.tour.message.jibx._2012B.hotel.response.out.HotelRateResponseSOAPMsgReplyOut2012B.java

License:Open Source License

/**
 * Convert this source message to the ECXML format.
 * Typically you do not override this method, you override the getTransformer method
 * to supply a XSLT document to do the conversion.
 * @param recordOwner TODO//www  .  j  a v a 2  s.c o  m
 * @param source The source XML document.
 * @return The XML tree that conforms to the ECXML format.
 */
public Object convertInternalToMarshallableObject(RecordOwner recordOwner) {
    BaseMessage message = this.getMessage();
    HotelRateResponse hotelRateResponseOut = (HotelRateResponse) message.getMessageDataDesc(null);
    TrxMessageHeader messageHeader = (TrxMessageHeader) message.getMessageHeader();
    String strMessageType = (String) hotelRateResponseOut.get(TrxMessageHeader.MESSAGE_CODE);
    if (true)//GET_HOTEL_RATE.equalsIgnoreCase(strMessageType))
    {
        AvailRS root = new AvailRS();

        OTAPayloadStdAttributes payloadStdAttributes = new OTAPayloadStdAttributes();
        this.setPayloadProperties(message, payloadStdAttributes);
        root.setOTAPayloadStdAttributes(payloadStdAttributes);

        POS pos = new POS();
        root.setPOS(pos);
        Source source = new Source();
        pos.addSource(source);

        //+        SourceType.RequestorID uniqueId = null;
        //+        source.setRequestorID(uniqueId = factory.createSourceTypeRequestorID());
        //+        uniqueId.setID(messageHeader.get(TrxMessageHeader.LOG_TRX_ID).toString());
        //+        uniqueId.setType("12");
        //                source.setAgentSine("Test Agent");

        Success successType = new Success();
        root.setSuccess(successType);

        //                ErrorsTypeTypes errorsType = null;
        //                root.setErrors(errorsType = ObjectFactory.createErrorsTypeTypes());
        //            operation.setOperationName(AVAILABILITY_RESPONSE);    // Need a constant for this
        //            AvailabilityResponse availability = new AvailabilityResponse();
        //            operation.setAvailabilityResponse(availability);
        //            QuotedRateAmount rateAmount = new QuotedRateAmount();
        //            availability.setQuotedRateAmount(rateAmount);

        AvailRS.RoomStays roomStays = new AvailRS.RoomStays();
        root.setRoomStays(roomStays);

        roomStays.setMoreIndicator("No");
        AvailRS.RoomStays.RoomStay roomStay = new AvailRS.RoomStays.RoomStay();
        roomStays.addRoomStay(roomStay);

        roomStay.setIsAlternate(false);
        /*
        org.w3._2001.xmlschema.ObjectFactory w3Factory = new org.w3._2001.xmlschema.ObjectFactory();
        org.w3._2001.xmlschema.AnyType anyType = w3Factory.createAnyType();
        roomStay.setAlternateInfo(anyType);
        java.util.List listContent = anyType.getContent();
        BasicPropertyInfoTypez propInfo = factory.createBasicPropertyInfoTypez();
        roomStay.setBasicPropertyInfo(propInfo);
        propInfo.setHotelName("Test Hotel");
        //roomStay.setGuestCounts(value);
        */

        RoomStay.RatePlans ratePlans = new RoomStay.RatePlans();
        roomStay.setRatePlans(ratePlans);

        RatePlan ratePlan = new RatePlan();
        ratePlans.addRatePlan(ratePlan);

        ratePlan.setRatePlanCode("XYZ");
        ratePlan.setRateIndicator(RateIndicator.ON_REQUEST);

        RoomStay.RoomRates listRoomRate = new RoomStay.RoomRates();
        roomStay.setRoomRates(listRoomRate);

        RoomStay.RoomRates.RoomRate roomRate = new RoomStay.RoomRates.RoomRate();
        listRoomRate.addRoomRate(roomRate);

        Rate rates = new Rate();
        roomRate.setRates(rates);
        java.util.List<Rate.RateInner> listRates = rates.getRateList();
        Rate.RateInner rateType = new Rate.RateInner();
        listRates.add(rateType);

        String duration = "12345";
        rateType.setDuration(duration);
        AgeQualifyingGroup ageQualifyingGroup = new AgeQualifyingGroup();
        rateType.setAgeQualifyingGroup(ageQualifyingGroup);
        ageQualifyingGroup.setAgeQualifyingCode("AAA");
        ageQualifyingGroup.setAgeTimeUnit(TimeUnit.DAY);
        //rateType.setAmountAddlInfo(value);
        Total types = new Total();
        CurrencyCodeGroup currencyCodeGroup = new CurrencyCodeGroup();
        types.setCurrencyCodeGroup(currencyCodeGroup);
        currencyCodeGroup.setCurrencyCode("USD");
        Float bigAfter = new Float(20.00);
        types.setAmountAfterTax(bigAfter);
        rateType.setBase(types);
        String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
        SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
        GregorianCalendar calendar = new GregorianCalendar(pdt);
        calendar.setTime(new Date());
        int iDuration2 = 2;
        EffectiveExpireOptionalDateGroup effectiveExpireOptionalDateGroup = new EffectiveExpireOptionalDateGroup();
        rateType.setEffectiveExpireOptionalDateGroup(effectiveExpireOptionalDateGroup);
        LocalDate effectiveDate = new LocalDate(calendar);
        effectiveExpireOptionalDateGroup.setEffectiveDate(effectiveDate);
        calendar.add(Calendar.DATE, iDuration2);
        LocalDate expireDate = new LocalDate(calendar);
        effectiveExpireOptionalDateGroup.setExpireDate(expireDate);

        ageQualifyingGroup.setMaxAge(20);
        ageQualifyingGroup.setMinAge(1);
        //rateType.setTPAExtensions(value);
        listRates.add(rateType);
        roomRate.setRates(rates);

        listRoomRate.addRoomRate(roomRate);
        //HotelAvailRSType.RoomStaysTypez.RoomRatesType roomRates = factory.createRoomStayTypezRoomRatesType();
        //roomStay.setRoomRates(value);

        //roomStay.setRoomStayAddlInfo(value);
        //roomStay.setRoomTypes(value);        
        DateTimeSpan timeSpan = new DateTimeSpan();
        roomStay.setTimeSpan(timeSpan);

        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        DateTimeSpanGroup dateTimeSpanGroup = new DateTimeSpanGroup();
        timeSpan.setDateTimeSpanGroup(dateTimeSpanGroup);

        dateTimeSpanGroup.setStart(this.dateToStringDateFormat(cal.getTime()));
        int iDuration = 2;
        cal.add(Calendar.DATE, iDuration);
        dateTimeSpanGroup.setEnd(this.dateToStringDateFormat(cal.getTime()));

        ProductResponseMessageData messageData = (ProductResponseMessageData) hotelRateResponseOut
                .getMessageDataDesc(BaseProductResponse.PRODUCT_RESPONSE_MESSAGE);
        Double dblCurrency = (Double) messageData.get(BookingDetail.TOTAL_COST);

        root.getOTAPayloadStdAttributes().setEchoToken(dblCurrency.toString());
        //            double dCurrency = 0.00;
        //            if (dblCurrency != null)
        //                dCurrency = dblCurrency.doubleValue();
        //            rateAmount.setCurrency(dCurrency);        
        return root;
    }
    return null;
}

From source file:com.tysanclan.site.projectewok.beans.impl.DemocracyServiceImpl.java

License:Open Source License

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void resolveJoinApplication(JoinApplication _application) {
    JoinApplication application = joinApplicationDAO.load(_application.getId());
    if (application != null) {
        int inFavor = 0, total = 0;
        for (JoinVerdict verdict : application.getVerdicts()) {
            if (verdict.isInFavor()) {
                inFavor++;/* w  w  w. j  a v  a2 s. c  om*/
            }
            total++;
        }

        final User mentor = application.getMentor();
        final User applicant = application.getApplicant();
        Date startDate = application.getStartDate();
        LocalDate start = new LocalDate(startDate);
        LocalDate now = LocalDate.now();

        final boolean have3DaysPassed = start.plusDays(3).isBefore(now);

        boolean accepted = false;

        if (have3DaysPassed) {
            if (applicant.getActivations().isEmpty()) {
                // If we managed to let 3 days pass without the member
                // getting
                // accepted,
                // check for mentor is no longer relevant, all we need to
                // know
                // is if a Senator
                // voted against
                if (total == 0) {
                    accepted = true;
                } else {
                    if (inFavor == 0) {
                        accepted = false;
                    } else {
                        accepted = true;
                    }
                }
            } else {
                accepted = false;
            }
        } else {
            // This really shouldn't happen, but don't resolve unactivated
            // users prior to 3 days
            if (!applicant.getActivations().isEmpty()) {
                return;
            }

            // If this method gets invoked earlier, however, then member
            // needs a mentor and 1
            // vote in favor - otherwise do not resolve
            if (inFavor > 0 && mentor != null) {
                accepted = true;
            } else {
                return;
            }
        }

        if (accepted) {
            applicant.setMentor(application.getMentor());
            applicant.setRank(Rank.TRIAL);
            applicant.setJoinDate(new Date());
            applicant.setLoginCount(0);
            applicant.setLastAction(new Date());
            userDAO.update(applicant);

        }

        joinVerdictDAO.deleteForApplication(application);
        joinApplicationDAO.delete(application);

        mailService.sendHTMLMail(applicant.getEMail(), "Result of your Tysan Clan Application",
                mailService.getJoinApplicationMail(application, accepted, inFavor, total));

        logService.logUserAction(applicant, "Membership",
                "User has " + (accepted ? "been" : "not been") + " granted a trial membership");

        if (accepted) {
            notificationService.notifyUser(applicant, "You are now a Trial Member");

            dispatcher.dispatchEvent(new MemberStatusEvent(
                    com.tysanclan.site.projectewok.entities.MembershipStatusChange.ChangeType.TRIAL_GRANTED,
                    applicant));
        } else {
            dispatcher.dispatchEvent(new MemberStatusEvent(
                    com.tysanclan.site.projectewok.entities.MembershipStatusChange.ChangeType.TRIAL_DENIED,
                    applicant));
        }
    }

}

From source file:com.welflex.model.hibernate.LocalDateUserType.java

License:Apache License

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
    Date sqlDate = rs.getDate(names[0]);
    if (rs.wasNull()) {
        return null;
    }/*from   www .ja v a 2s. c  o m*/
    return new LocalDate(sqlDate.getTime());
}

From source file:cz.zcu.kiv.eegdatabase.webservices.rest.experiment.ExperimentServiceImpl.java

License:Apache License

/**
 * Fetches provided collection into ExperimentData data container.
 * @param exps collection of experiments
 * @return experiment collection wrapped in ExperimentData container
 *///  w w w. j a  va 2  s.c o  m
private List<ExperimentData> fillAndSortExperiments(Collection<Experiment> exps) {
    List<ExperimentData> experiments = new ArrayList<ExperimentData>(exps.size());

    for (Experiment exp : exps) {
        ExperimentData expData = new ExperimentData();
        expData.setExperimentId(exp.getExperimentId());
        expData.setStartTime(exp.getStartTime());
        expData.setEndTime(exp.getEndTime());

        ScenarioSimpleData scenarioData = new ScenarioSimpleData();
        scenarioData.setScenarioId(exp.getScenario().getScenarioId());
        scenarioData.setScenarioName(exp.getScenario().getTitle());

        Weather weather = exp.getWeather();
        if (weather != null) {
            WeatherData weatherData = new WeatherData();
            weatherData.setWeatherId(weather.getWeatherId());
            weatherData.setTitle(weather.getTitle());
            weatherData.setDescription(weather.getDescription());
            expData.setWeather(weatherData);
        }
        Person subject = exp.getPersonBySubjectPersonId();
        if (subject != null) {
            SubjectData subjectData = new SubjectData();
            subjectData.setPersonId(subject.getPersonId());
            subjectData.setName(subject.getGivenname());
            subjectData.setSurname(subject.getSurname());
            subjectData.setLeftHanded(subject.getLaterality() == 'L' || subject.getLaterality() == 'l');
            subjectData.setGender(subject.getGender());
            subjectData.setAge(
                    Years.yearsBetween(new LocalDate(subject.getDateOfBirth()), new LocalDate()).getYears());
            subjectData.setMail(subject.getUsername());
            expData.setSubject(subjectData);
        }

        Artifact artifact = exp.getArtifact();
        ArtifactData artifactData = new ArtifactData();
        artifactData.setArtifactId(artifact.getArtifactId());
        artifactData.setCompensation(artifact.getCompensation());
        artifactData.setRejectCondition(artifact.getRejectCondition());

        Set<Disease> diseases = exp.getDiseases();
        List<DiseaseData> diseaseDatas = new ArrayList<DiseaseData>();
        for (Disease dis : diseases) {
            DiseaseData diseaseData = new DiseaseData();
            diseaseData.setDiseaseId(dis.getDiseaseId());
            diseaseData.setName(dis.getTitle());
            diseaseData.setDescription(dis.getDescription());
            diseaseDatas.add(diseaseData);
        }

        Digitization digitization = exp.getDigitization();
        DigitizationData dgData = new DigitizationData();
        dgData.setDigitizationId(digitization.getDigitizationId());
        dgData.setGain(digitization.getGain());
        dgData.setFilter(digitization.getFilter());
        dgData.setSamplingRate(digitization.getSamplingRate());

        Set<Hardware> hardwares = exp.getHardwares();
        List<HardwareData> hardwareDatas = new ArrayList<HardwareData>();
        for (Hardware h : hardwares) {
            HardwareData hw = new HardwareData();
            hw.setHardwareId(h.getHardwareId());
            hw.setTitle(h.getTitle());
            hw.setType(h.getType());
            hw.setDefaultNumber(h.getDefaultNumber());
            hardwareDatas.add(hw);
        }

        ElectrodeConf elConf = exp.getElectrodeConf();
        ElectrodeConfData electrodeConfData = new ElectrodeConfData();
        //set primitive types
        electrodeConfData.setId(elConf.getElectrodeConfId());
        electrodeConfData.setImpedance(elConf.getImpedance());
        //set electrode system
        ElectrodeSystem elSystem = elConf.getElectrodeSystem();
        ElectrodeSystemData electrodeSystemData = new ElectrodeSystemData();
        electrodeSystemData.setId(elSystem.getElectrodeSystemId());
        electrodeSystemData.setDescription(elSystem.getDescription());
        electrodeSystemData.setTitle(elSystem.getTitle());
        electrodeSystemData.setDefaultNumber(elSystem.getDefaultNumber());
        electrodeConfData.setElectrodeSystem(electrodeSystemData);
        //set electrode locations
        Set<ElectrodeLocation> elLocations = elConf.getElectrodeLocations();

        if (elLocations != null && !elLocations.isEmpty()) {
            List<ElectrodeLocationData> electrodeLocations = new ArrayList<ElectrodeLocationData>(
                    elLocations.size());

            for (ElectrodeLocation el : elLocations) {
                ElectrodeLocationData electrodeLocation = new ElectrodeLocationData();
                //set primitives
                electrodeLocation.setId(el.getElectrodeLocationId());
                electrodeLocation.setTitle(el.getTitle());
                electrodeLocation.setDescription(el.getDescription());
                electrodeLocation.setAbbr(el.getShortcut());
                electrodeLocation.setDefaultNumber(el.getDefaultNumber());
                //set complex types
                ElectrodeFix elFix = el.getElectrodeFix();
                ElectrodeFixData electrodeFix = new ElectrodeFixData();
                electrodeFix.setId(elFix.getElectrodeFixId());
                electrodeFix.setTitle(elFix.getTitle());
                electrodeFix.setDescription(elFix.getDescription());
                electrodeFix.setDefaultNumber(elFix.getDefaultNumber());
                electrodeLocation.setElectrodeFix(electrodeFix);

                ElectrodeType elType = el.getElectrodeType();
                ElectrodeTypeData electrodeType = new ElectrodeTypeData();
                electrodeType.setId(elType.getElectrodeTypeId());
                electrodeType.setTitle(elType.getTitle());
                electrodeType.setDescription(elType.getDescription());
                electrodeType.setDefaultNumber(elType.getDefaultNumber());
                electrodeLocation.setElectrodeType(electrodeType);

                electrodeLocations.add(electrodeLocation);
            }
            electrodeConfData.setElectrodeLocations(new ElectrodeLocationDataList(electrodeLocations));
        }

        Set<Pharmaceutical> pharms = exp.getPharmaceuticals();
        List<PharmaceuticalData> pharmaceuticals = new ArrayList<PharmaceuticalData>();
        if (pharms != null && !pharms.isEmpty()) {
            for (Pharmaceutical p : pharms) {
                PharmaceuticalData pharmaceutical = new PharmaceuticalData();
                pharmaceutical.setId(p.getPharmaceuticalId());
                pharmaceutical.setTitle(p.getTitle());
                pharmaceutical.setDescription(p.getDescription());
                pharmaceuticals.add(pharmaceutical);
            }
        }

        Set<Software> softs = exp.getSoftwares();
        List<SoftwareData> softwareList = new ArrayList<SoftwareData>();
        if (softs != null && !softs.isEmpty()) {
            for (Software s : softs) {
                SoftwareData software = new SoftwareData();
                software.setId(s.getSoftwareId());
                software.setTitle(s.getTitle());
                software.setDescription(s.getDescription());
                software.setDefaultNumber(s.getDefaultNumber());
                softwareList.add(software);
            }
        }

        ResearchGroup rg = exp.getResearchGroup();
        ResearchGroupData researchGroup = new ResearchGroupData();

        researchGroup.setGroupId(rg.getResearchGroupId());
        researchGroup.setGroupName(rg.getTitle());

        Person ow = exp.getPersonByOwnerId();
        OwnerData owner = new OwnerData();
        String mail[] = ow.getUsername().split("@");
        owner.setId(ow.getPersonId());
        owner.setName(ow.getGivenname());
        owner.setSurname(ow.getSurname());
        if (mail.length == 2) {
            owner.setMailUsername(mail[0]);
            owner.setMailDomain(mail[1]);
        }

        expData.setTemperature(exp.getTemperature());

        expData.setOwner(owner);
        expData.setResearchGroup(researchGroup);
        expData.setPharmaceuticals(new PharmaceuticalDataList(pharmaceuticals));
        expData.setSoftwareList(new SoftwareDataList(softwareList));
        expData.setElectrodeConf(electrodeConfData);
        expData.setHardwareList(new HardwareDataList(hardwareDatas));
        expData.setScenario(scenarioData);
        expData.setArtifact(artifactData);
        expData.setDiseases(new DiseaseDataList(diseaseDatas));
        expData.setDigitization(dgData);

        experiments.add(expData);
    }
    Collections.sort(experiments, idComparator);
    return experiments;
}

From source file:cz.zcu.kiv.formgen.core.SimpleObjectBuilder.java

License:Apache License

protected Object toProperDateType(Object obj, Class<?> type) throws ObjectBuilderException {
    if (obj == null)
        return null;

    if (Date.class.equals(type)) {
        if (obj instanceof Date)
            return obj;
        else if (obj instanceof LocalDate)
            return ((LocalDate) obj).toDate();
    }//from w  w  w. j  a  va 2 s . com

    else if (java.sql.Date.class.equals(type)) {
        if (obj instanceof java.sql.Date)
            return obj;
        else if (obj instanceof Date)
            return new java.sql.Date(((Date) obj).getTime());
        else if (obj instanceof LocalDate)
            return new java.sql.Date(((LocalDate) obj).toDate().getTime());
    }

    else if (java.sql.Time.class.equals(type)) {
        if (obj instanceof java.sql.Time)
            return obj;
        else if (obj instanceof LocalTime)
            return java.sql.Time.valueOf(((LocalTime) obj).toString());
    }

    else if (java.sql.Timestamp.class.equals(type)) {
        if (obj instanceof java.sql.Timestamp)
            return obj;
        else if (obj instanceof Date)
            return new java.sql.Timestamp(((Date) obj).getTime());
        else if (obj instanceof LocalDate)
            return new java.sql.Timestamp(((LocalDate) obj).toDate().getTime());
    }

    else if (LocalDate.class.equals(type)) {
        if (obj instanceof LocalDate)
            return obj;
        else if (obj instanceof Date)
            return new LocalDate(obj);
    }

    else if (LocalTime.class.equals(type)) {
        if (obj instanceof LocalTime)
            return obj;
    }

    else if (LocalDateTime.class.equals(type)) {
        if (obj instanceof LocalDateTime)
            return obj;
        else if (obj instanceof Date)
            return new LocalDateTime(obj);
    }

    throw new ObjectBuilderException(
            "Unsupported date/time conversion from " + obj.getClass().getName() + " to " + type.getName());
}

From source file:dao.ClienteDAOBD.java

public List<Emprestimo> getEmprestimosAtivos(Cliente cliente) {
    List<Emprestimo> lista = new ArrayList<Emprestimo>();
    try {//from   w w  w.  java  2s  . co  m
        String sql = "SELECT * FROM emprestimo WHERE codCliente=? AND ativo=true";
        conectar(sql);
        comando.setInt(1, cliente.getId());
        ResultSet r = comando.executeQuery();
        while (r.next()) {
            Cliente c = new servico.ServicoCliente().pesquisaClienteID(r.getInt("codCliente"));
            ItemLivro itemLivro = new servico.ServicoItemLivro().pesquisaItemLivroID(r.getInt("codItemLivro"));
            Emprestimo e = new Emprestimo(r.getInt("id"), c, itemLivro,
                    new LocalDate(r.getDate("dataEmprestimo")), new LocalDate(r.getDate("dataDevolucao")),
                    new LocalDate(r.getDate("devolucaoEfetiva")), r.getInt("diasAtraso"), true);
            lista.add(e);
        }
    } catch (SQLException ex) {
        Logger.getLogger(ClienteDAOBD.class.getName()).log(Level.SEVERE, null, ex);
    }
    return lista;
}

From source file:dao.EmprestimoDAOBD.java

@Override
public List<Emprestimo> listar() {
    ArrayList<Emprestimo> array = new ArrayList<>();
    try {//from www . j  a  v  a  2 s  . co m
        ClienteDAOBD cliente = new ClienteDAOBD();
        ItemLivroDAOBD itemLivro = new ItemLivroDAOBD();
        String sql = "SELECT * FROM emprestimo ORDER BY id";
        conectar(sql);
        ResultSet r = comando.executeQuery();
        while (r.next()) {
            int id = r.getInt("id");
            Cliente c = cliente.procurarPorId(r.getInt("codCliente"));
            ItemLivro livro = itemLivro.procurarPorId(r.getInt("codItemLivro"));
            LocalDate dataEmprestimo = new LocalDate(r.getDate("dataEmprestimo"));
            LocalDate dataDevolucao = new LocalDate(r.getDate("dataDevolucao"));
            LocalDate devolucaoEfetiva = new LocalDate(r.getDate("devolucaoEfetiva"));
            int diasAtraso = r.getInt("diasAtraso");
            boolean ativo = r.getBoolean("ativo");
            array.add(new Emprestimo(id, c, livro, dataEmprestimo, dataDevolucao, devolucaoEfetiva, diasAtraso,
                    ativo));
        }
    } catch (SQLException ex) {
        Logger.getLogger(LivroDAOBD.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        fecharConexao();
    }
    return array;
}

From source file:dao.EmprestimoDAOBD.java

@Override
public Emprestimo procurarPorId(int id) {
    try {/*  w w  w  .j  a  v a  2 s. co  m*/
        String sql = "SELECT * FROM emprestimo WHERE id=?";
        conectar(sql);
        comando.setInt(1, id);
        ResultSet r = comando.executeQuery();
        if (r.next()) {
            ClienteDAOBD cliente = new ClienteDAOBD();
            ItemLivroDAOBD itemLivro = new ItemLivroDAOBD();
            Cliente c = cliente.procurarPorId(r.getInt("codCliente"));
            ItemLivro livro = itemLivro.procurarPorId(r.getInt("codItemLivro"));
            LocalDate dataEmprestimo = new LocalDate(r.getDate("dataEmprestimo"));
            LocalDate dataDevolucao = new LocalDate(r.getDate("dataDevolucao"));
            LocalDate devolucaoEfetiva = new LocalDate(r.getDate("devolucaoEfetiva"));
            int diasAtraso = r.getInt("diasAtraso");
            boolean ativo = r.getBoolean("ativo");
            return new Emprestimo(id, c, livro, dataEmprestimo, dataDevolucao, devolucaoEfetiva, diasAtraso,
                    ativo);
        }
    } catch (SQLException ex) {
        Logger.getLogger(LivroDAOBD.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        fecharConexao();
    }
    return null;
}