List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java
/** * Consume an XML message and update the specified Long instance. * <br>/* w w w .ja v a 2 s . c om*/ * @param object the instance that is to be updated with the XML message data. * @param cellElement the XML element that contains the data * @return the updated instance. * @exception JDOMException if there is an error consuming the message. */ private Object consumeMsg(Short object, Element cellElement) throws JDOMException { // ----------------------- // Process the element ... // ----------------------- Short result; try { result = Short.valueOf(cellElement.getTextTrim()); } catch (NumberFormatException e) { throw new JDOMException("Unable to parse the value for " + cellElement.getName() + //$NON-NLS-1$ " element: " + cellElement.getTextTrim(), e); //$NON-NLS-2$ //$NON-NLS-1$ } return result; }
From source file:de.minigameslib.mclib.api.config.ConfigurationValueInterface.java
/** * Sets the value to this configuration variable. * /*from w w w.ja v a 2 s . c o m*/ * @param value * value to set. * @param subpath * the sub path */ default void setShortList(short[] value, String subpath) { final List<Short> list = new ArrayList<>(); for (int i = 0; i < value.length; i++) { list.add(Short.valueOf(value[i])); } ConfigurationTool.consume(this, subpath, (val, configs, config, lib, minigame, path) -> { minigame.getConfig(configs.file()).setPrimitiveList(path, list); }); }
From source file:org.mifos.application.servicefacade.AdminServiceFacadeWebTier.java
@Override public void createOrUpdateProductMix(Integer productId, List<Integer> notAllowedProductIds) { try {//w ww. j a v a 2s . com PrdOfferingBO product = new PrdOfferingPersistence().getPrdOfferingByID(productId.shortValue()); StaticHibernateUtil.startTransaction(); product.setPrdMixFlag(YesNoFlag.YES.getValue()); applicationConfigurationDao.save(product); StaticHibernateUtil.flushSession(); List<PrdOfferingBO> newNotAllowedProducts = new ArrayList<PrdOfferingBO>(); for (Integer notAllowedProductId : notAllowedProductIds) { PrdOfferingBO notAllowedProduct = new PrdOfferingPersistence() .getPrdOfferingByID(notAllowedProductId.shortValue()); newNotAllowedProducts.add(notAllowedProduct); } for (ProductMixBO oldNotAllowedProduct : product.getCollectionProductMix()) { ProductMixBO productMix = legacyProductMixDao.getPrdOfferingMixByPrdOfferingID( productId.shortValue(), oldNotAllowedProduct.getPrdOfferingNotAllowedId().getPrdOfferingId()); if (null != productMix) { applicationConfigurationDao.delete(productMix); StaticHibernateUtil.flushSession(); } ProductMixBO alternateproductmix = legacyProductMixDao.getPrdOfferingMixByPrdOfferingID( oldNotAllowedProduct.getPrdOfferingNotAllowedId().getPrdOfferingId(), productId.shortValue()); if (null != alternateproductmix) { applicationConfigurationDao.delete(alternateproductmix); StaticHibernateUtil.flushSession(); } } for (PrdOfferingBO notAllowedProduct : newNotAllowedProducts) { ProductMixBO productMix = new ProductMixBO(product, notAllowedProduct); productMix.setUpdatedDate(new DateTime().toDate()); productMix.setUpdatedBy(Short.valueOf("1")); applicationConfigurationDao.save(productMix); StaticHibernateUtil.flushSession(); } StaticHibernateUtil.commitTransaction(); } catch (Exception e) { StaticHibernateUtil.rollbackTransaction(); throw new MifosRuntimeException(e); } finally { StaticHibernateUtil.closeSession(); } }
From source file:com.mimp.controllers.familia.java
@RequestMapping("/FfichaGuardar/opc1") public ModelAndView FfichaGuardarElla(ModelMap map, @RequestParam("nombre_ella") String nombre, @RequestParam("apellido_p_ella") String apellido_p, @RequestParam("apellido_m_ella") String apellido_m, @RequestParam("edad_ella") String edad, @RequestParam("lugar_nac_ella") String lugar_nac, @RequestParam("depa_nac_ella") String depa_nac, @RequestParam("pais_nac_ella") String pais_nac, @RequestParam("TipoDoc") String tipo_doc, @RequestParam("n_doc_ella") String n_doc, @RequestParam("domicilio") String domicilio, @RequestParam("telefono") String telefono, @RequestParam("celular_ella") String celular, @RequestParam("correo_ella") String correo, @RequestParam("estCivil") String est_civil, @RequestParam("fechaMatri") String fecha_matri, @RequestParam("nivel_inst_ella") String nivel_inst, @RequestParam("culm_nivel_ella") String culm_nivel, @RequestParam("prof_ella") String prof, @RequestParam("Trabajador_Depend_ella") String trab_depend, @RequestParam(value = "ocup_act_dep_ella", required = false) String ocup_actual, @RequestParam(value = "centro_trabajo_ella", required = false) String centro_trabajo, @RequestParam(value = "dir_centro_ella", required = false) String dir_centro, @RequestParam(value = "tel_centro_ella", required = false) String tel_centro, @RequestParam(value = "ingreso_dep_ella", required = false) String ingreso_dep, @RequestParam("Trabajador_Indep_ella") String trab_indep, @RequestParam(value = "ocup_act_indep_ella", required = false) String ocup_act_indep, @RequestParam(value = "ingreso_ind_ella", required = false) String ingreso_ind, @RequestParam("seguro_salud_ella") String seguro_salud, @RequestParam("tipo_seguro") String tipo_seguro, @RequestParam("seguro_vida_ella") String seguro_vida, @RequestParam("sist_pen_ella") String sist_pen, @RequestParam("est_salud_ella") String est_salud, HttpSession session) { Familia usuario = (Familia) session.getAttribute("usuario"); if (usuario == null) { String mensaje = "La sesin ha finalizado. Favor identificarse nuevamente"; map.addAttribute("mensaje", mensaje); return new ModelAndView("login", map); }/*from www . ja v a2 s . c o m*/ dateFormat format = new dateFormat(); Date factual = new Date(); String fechaactual = format.dateToString(factual); map.addAttribute("factual", fechaactual); FichaSolicitudAdopcion ficha = (FichaSolicitudAdopcion) session.getAttribute("ficha"); Solicitante sol = new Solicitante(); for (Iterator iter2 = ficha.getSolicitantes().iterator(); iter2.hasNext();) { sol = (Solicitante) iter2.next(); if (sol.getSexo() == 'F') { ficha.getSolicitantes().remove(sol); break; } } sol.setNombre(nombre); sol.setApellidoP(apellido_p); sol.setApellidoM(apellido_m); try { sol.setEdad(Short.parseShort(edad)); } catch (Exception ex) { String mensaje_edad = "ERROR: El campo Edad contiene parmetros invlidos"; map.addAttribute("mensaje_edad", mensaje_edad); } sol.setLugarNac(lugar_nac); sol.setDepaNac(depa_nac); sol.setPaisNac(pais_nac); try { sol.setTipoDoc(tipo_doc.charAt(0)); } catch (Exception ex) { } sol.setNDoc(n_doc); ficha.setDomicilio(domicilio); ficha.setFijo(telefono); sol.setCelular(celular); sol.setCorreo(correo); try { ficha.setEstadoCivil(est_civil); } catch (Exception ex) { } Date tempfecha = ficha.getFechaMatrimonio(); if (fecha_matri.contains("ene") || fecha_matri.contains("feb") || fecha_matri.contains("mar") || fecha_matri.contains("abr") || fecha_matri.contains("may") || fecha_matri.contains("jun") || fecha_matri.contains("jul") || fecha_matri.contains("ago") || fecha_matri.contains("set") || fecha_matri.contains("oct") || fecha_matri.contains("nov") || fecha_matri.contains("dic")) { ficha.setFechaMatrimonio(tempfecha); } else { ficha.setFechaMatrimonio(format.stringToDate(fecha_matri)); } sol.setNivelInstruccion(nivel_inst); sol.setCulminoNivel(Short.valueOf(culm_nivel)); sol.setProfesion(prof); sol.setTrabajadorDepend(Short.valueOf(trab_depend)); sol.setOcupActualDep(ocup_actual); sol.setCentroTrabajo(centro_trabajo); sol.setDireccionCentro(dir_centro); sol.setTelefonoCentro(tel_centro); try { sol.setIngresoDep(Long.valueOf(ingreso_dep)); } catch (Exception ex) { if (ingreso_dep != null) { String mensaje_ingreso_dep = "ERROR: La informacin contenida en este campo contiene parmetros invlidos"; map.addAttribute("mensaje_ing_dep", mensaje_ingreso_dep); } } sol.setTrabajadorIndepend(Short.valueOf(trab_indep)); sol.setOcupActualInd(ocup_act_indep); try { sol.setIngresoIndep(Long.valueOf(ingreso_ind)); } catch (Exception ex) { if (ingreso_ind != null) { String mensaje_ingreso_indep = "ERROR: La informacin contenida en este campo contiene parmetros invlidos"; map.addAttribute("mensaje_ing_indep", mensaje_ingreso_indep); } } sol.setSeguroSalud(Short.valueOf(seguro_salud)); sol.setTipoSeguro(tipo_seguro); sol.setSeguroVida(Short.valueOf(seguro_vida)); sol.setSistPensiones(Short.valueOf(sist_pen)); sol.setSaludActual(est_salud); ficha.getSolicitantes().add(sol); session.removeAttribute("ficha"); session.setAttribute("ficha", ficha); map.put("sol", sol); String fechanac = format.dateToString(sol.getFechaNac()); map.addAttribute("fechanac", fechanac); map.addAttribute("estCivil", est_civil.charAt(0)); map.addAttribute("fechaMatri", format.dateToString(ficha.getFechaMatrimonio())); map.addAttribute("estCivil", ficha.getEstadoCivil().charAt(0)); map.addAttribute("domicilio", ficha.getDomicilio()); map.addAttribute("fijo", ficha.getFijo()); String pagina = "/Familia/Ficha/ficha_inscripcion_ella"; return new ModelAndView(pagina, map); }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testCreateIndividualLoan() throws Exception { createInitialCustomers();//from w w w. ja v a 2s . c o m MeetingBO meeting = TestObjectFactory.createLoanMeeting(group.getCustomerMeeting().getMeeting()); Date startDate = new Date(System.currentTimeMillis()); loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.GROUPS, startDate, PrdStatus.LOAN_ACTIVE, 300.0, 1.2, 1, InterestType.FLAT, meeting); List<Date> meetingDates = TestObjectFactory.getMeetingDates(meeting, 1); try { LoanBO.createIndividualLoan(userContext, loanOffering, group, AccountState.LOAN_PARTIAL_APPLICATION, TestUtils.createMoney("300.0"), Short.valueOf("1"), meetingDates.get(0), true, false, 10.0, (short) 0, null, new ArrayList<FeeView>(), null, false); Assert.fail(); } catch (AccountException e) { Assert.assertTrue(true); } }
From source file:org.mifos.application.servicefacade.AdminServiceFacadeWebTier.java
@Override public SavingsProductFormDto retrieveSavingsProductFormReferenceData() { try {//from ww w . j a va 2s.c om SavingsPrdBusinessService service = new SavingsPrdBusinessService(); List<ListElement> statusOptions = new ArrayList<ListElement>(); List<PrdStatusEntity> applicableStatuses = service.getApplicablePrdStatus(Short.valueOf("1")); for (PrdStatusEntity entity : applicableStatuses) { statusOptions.add( new ListElement(entity.getOfferingStatusId().intValue(), entity.getPrdState().getName())); } List<ListElement> penaltiesOptions = new ArrayList<ListElement>(); List<PenaltyBO> applicablePenalties = this.penaltyDao.findAllSavingPenalties(); for (PenaltyBO entity : applicablePenalties) { penaltiesOptions.add(new ListElement(entity.getPenaltyId().intValue(), entity.getPenaltyName())); } List<ListElement> productCategoryOptions = new ArrayList<ListElement>(); List<ProductCategoryBO> productCategories = service.getActiveSavingsProductCategories(); for (ProductCategoryBO category : productCategories) { productCategoryOptions.add(new ListElement(category.getProductCategoryID().intValue(), category.getProductCategoryName())); } List<ListElement> applicableForOptions = new ArrayList<ListElement>(); List<PrdApplicableMasterEntity> applicableCustomerTypes = this.loanProductDao .retrieveSavingsApplicableProductCategories(); for (PrdApplicableMasterEntity entity : applicableCustomerTypes) { applicableForOptions.add(new ListElement(entity.getId().intValue(), entity.getName())); } List<ListElement> savingsTypeOptions = new ArrayList<ListElement>(); List<SavingsTypeEntity> savingsTypes = this.loanProductDao.retrieveSavingsTypes(); for (SavingsTypeEntity entity : savingsTypes) { savingsTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName())); } List<ListElement> recommendedAmountTypeOptions = new ArrayList<ListElement>(); List<RecommendedAmntUnitEntity> recommendedAmountTypes = this.loanProductDao .retrieveRecommendedAmountTypes(); for (RecommendedAmntUnitEntity entity : recommendedAmountTypes) { recommendedAmountTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName())); } List<ListElement> interestCalcTypeOptions = new ArrayList<ListElement>(); List<InterestCalcTypeEntity> interestCalcTypes = this.savingsProductDao .retrieveInterestCalculationTypes(); for (InterestCalcTypeEntity entity : interestCalcTypes) { interestCalcTypeOptions.add(new ListElement(entity.getId().intValue(), entity.getName())); } List<ListElement> timePeriodOptions = new ArrayList<ListElement>(); List<RecurrenceTypeEntity> applicableRecurrences = savingsProductDao .getSavingsApplicableRecurrenceTypes(); for (RecurrenceTypeEntity entity : applicableRecurrences) { timePeriodOptions .add(new ListElement(entity.getRecurrenceId().intValue(), entity.getRecurrenceName())); } List<GLCodeEntity> depositGlCodeList = new ArrayList<GLCodeEntity>(); depositGlCodeList.addAll(new FinancialBusinessService() .getGLCodes(FinancialActionConstants.MANDATORYDEPOSIT, FinancialConstants.CREDIT)); depositGlCodeList.addAll(new FinancialBusinessService() .getGLCodes(FinancialActionConstants.VOLUNTARYDEPOSIT, FinancialConstants.CREDIT)); List<ListElement> depositGlCodeOptions = new ArrayList<ListElement>(); for (GLCodeEntity glCode : depositGlCodeList) { depositGlCodeOptions.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode())); } List<GLCodeEntity> interestGlCodeList = new FinancialBusinessService() .getGLCodes(FinancialActionConstants.SAVINGS_INTERESTPOSTING, FinancialConstants.DEBIT); List<ListElement> interestGlCodes = new ArrayList<ListElement>(); for (GLCodeEntity glCode : interestGlCodeList) { interestGlCodes.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode())); } return new SavingsProductFormDto(productCategoryOptions, applicableForOptions, savingsTypeOptions, recommendedAmountTypeOptions, interestCalcTypeOptions, timePeriodOptions, depositGlCodeOptions, interestGlCodes, statusOptions); } catch (PersistenceException e) { throw new MifosRuntimeException(e); } catch (SystemException e) { throw new MifosRuntimeException(e); } catch (ApplicationException e) { throw new BusinessRuleException(e.getKey(), e); } }
From source file:org.ednovo.gooru.domain.service.resource.ResourceServiceImpl.java
@Override public Resource updateResourceByGooruContentId(final String gooruContentId, final String resourceTitle, final String distinguish, final Integer isFeatured, final String description, final Boolean hasFrameBreaker, final String tags, final String sharing, final Integer resourceSourceId, final User user, final String mediaType, final String attribution, final String category, final String mediaFileName, final Boolean isBlacklisted, final String grade, final String resourceFormat, final String licenseName, final String url) { final Resource existingResource = resourceRepository.findResourceByContentGooruId(gooruContentId); if (resourceTitle != null) { existingResource.setTitle(resourceTitle); }// w w w .j a va 2 s . c o m if (description != null) { existingResource.setDescription(description); } if (hasFrameBreaker != null) { existingResource.setHasFrameBreaker(hasFrameBreaker); } if (isFeatured != null) { existingResource.setIsFeatured(isFeatured); } if (getUserService().isContentAdmin(user)) { ResourceSource resourceSource = null; String domainName = null; if (url != null) { existingResource.setUrl(url); domainName = BaseUtil.getDomainName(url); if (domainName != null) { resourceSource = this.getResourceRepository().findResourceSource(domainName); } if (resourceSource != null && resourceSource.getFrameBreaker() != null && resourceSource.getFrameBreaker() == 1) { existingResource.setHasFrameBreaker(true); } else { existingResource.setHasFrameBreaker(false); } this.mapSourceToResource(existingResource); } } if (category != null) { existingResource.setCategory(category); } if (resourceFormat != null) { final CustomTableValue customTableValue = this.getCustomTableRepository() .getCustomTableValue(RESOURCE_CATEGORY_FORMAT, resourceFormat); existingResource.setResourceFormat(customTableValue); } if (!StringUtils.isEmpty(mediaType)) { existingResource.setMediaType(mediaType); } if (resourceSourceId != null && resourceSourceId != 0) { if (existingResource.getResourceSource() == null) { ResourceSource resourceSource = new ResourceSource(); resourceSource.setResourceSourceId(resourceSourceId); if (attribution != null) { resourceSource.setAttribution(attribution); } existingResource.setResourceSource(resourceSource); existingResource.setDistinguish(Short.valueOf(distinguish)); } else { existingResource.getResourceSource().setResourceSourceId(resourceSourceId); } } else if (attribution != null) { ResourceSource resourceSource = new ResourceSource(); resourceSource = createResourcesourceAttribution(null, attribution); existingResource.setResourceSource(resourceSource); } if (sharing != null && !sharing.isEmpty()) { SessionContextSupport.putLogParameter("sharing-" + existingResource.getGooruOid(), existingResource.getSharing() + " to " + sharing); existingResource.setSharing(sharing); } if (tags != null && !tags.isEmpty()) { existingResource.setTags(tags); } if (mediaFileName != null) { this.getResourceImageUtil().downloadAndSendMsgToGenerateThumbnails(existingResource, mediaFileName); } if (getUserService().isContentAdmin(user)) { if (isBlacklisted != null && isBlacklisted == true) { existingResource.setSharing(PRIVATE); existingResource.setBatchId(DEL_FROM_SEARCH_INDEX); } } if (getUserService().isContentAdmin(user) && grade != null) { existingResource.setGrade(grade); } if (licenseName != null) { final License licenseData = this.getResourceRepository().getLicenseByLicenseName(licenseName); if (licenseData != null) { existingResource.setLicense(licenseData); } } resourceRepository.save(existingResource); if (tags != null && !tags.isEmpty()) { ResourceInfo resourceInfo = resourceRepository.findResourceInfo(gooruContentId); if (resourceInfo == null) { resourceInfo = new ResourceInfo(); } resourceInfo.setTags(tags); resourceInfo.setResource(existingResource); resourceInfo.setLastUpdated(new Date()); resourceRepository.save(resourceInfo); } if (isBlacklisted != null && isBlacklisted == true) { if (getUserService().isContentAdmin(user)) { indexHandler.setReIndexRequest(existingResource.getGooruOid(), IndexProcessor.DELETE, RESOURCE, null, false, false); } } else { indexHandler.setReIndexRequest(existingResource.getGooruOid(), IndexProcessor.INDEX, RESOURCE, null, false, false); } return existingResource; }
From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java
public void testWaiveMiscFeeAfterPayment() throws Exception { createInitialCustomers();//from w w w. j a va2 s . com LoanOfferingBO loanOffering = createLoanOffering(false); List<FeeView> feeViews = new ArrayList<FeeView>(); boolean isInterestDedAtDisb = false; Short noOfinstallments = (short) 6; LoanBO loan = createAndRetrieveLoanAccount(loanOffering, isInterestDedAtDisb, feeViews, noOfinstallments); loan.setUserContext(TestUtils.makeUser()); loan.applyCharge(Short.valueOf("-1"), Double.valueOf("200")); for (AccountActionDateEntity accountActionDateEntity : loan.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) { Assert.assertEquals(loanScheduleEntity.getMiscFee(), new Money(getCurrency(), "200")); Assert.assertEquals(loanScheduleEntity.getMiscFeePaid(), new Money(getCurrency())); } } Assert.assertEquals(loan.getLoanSummary().getOriginalFees(), new Money(getCurrency(), "200")); Assert.assertEquals(loan.getLoanSummary().getFeesPaid(), new Money(getCurrency())); List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>(); accntActionDates.addAll(loan.getAccountActionDates()); Date currentDate = new Date(System.currentTimeMillis()); PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney(200), null, accountBO.getPersonnel(), "receiptNum", Short.valueOf("1"), currentDate, currentDate); loan.applyPaymentWithPersist(paymentData); TestObjectFactory.updateObject(loan); for (AccountActionDateEntity accountActionDateEntity : loan.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) { Assert.assertEquals(loanScheduleEntity.getMiscFee(), new Money(getCurrency(), "200")); Assert.assertEquals(loanScheduleEntity.getMiscFeePaid(), new Money(getCurrency(), "200")); } } Assert.assertEquals(loan.getLoanSummary().getOriginalFees(), new Money(getCurrency(), "200")); Assert.assertEquals(loan.getLoanSummary().getFeesPaid(), new Money(getCurrency(), "200")); loan.applyCharge(Short.valueOf("-1"), Double.valueOf("300")); TestObjectFactory.updateObject(loan); for (AccountActionDateEntity accountActionDateEntity : loan.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) { Assert.assertEquals(loanScheduleEntity.getMiscFee(), new Money(getCurrency(), "500")); Assert.assertEquals(loanScheduleEntity.getMiscFeePaid(), new Money(getCurrency(), "200")); } } Assert.assertEquals(loan.getLoanSummary().getOriginalFees(), new Money(getCurrency(), "500")); Assert.assertEquals(loan.getLoanSummary().getFeesPaid(), new Money(getCurrency(), "200")); loan.waiveAmountDue(WaiveEnum.FEES); for (AccountActionDateEntity accountActionDateEntity : loan.getAccountActionDates()) { LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity; if (loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) { Assert.assertEquals(loanScheduleEntity.getMiscFee(), new Money(getCurrency(), "200")); Assert.assertEquals(loanScheduleEntity.getMiscFeePaid(), new Money(getCurrency(), "200")); } } Assert.assertEquals(loan.getLoanSummary().getOriginalFees(), new Money(getCurrency(), "200")); Assert.assertEquals(loan.getLoanSummary().getFeesPaid(), new Money(getCurrency(), "200")); }
From source file:org.apache.openjpa.meta.FieldMetaData.java
/** * Return the string value converted to the given type code. The string * must be non-null and trimmed./*www . j a v a 2s . c om*/ */ private Object transform(String val, int typeCode) { if ("null".equals(val)) return null; switch (typeCode) { case JavaTypes.BOOLEAN: case JavaTypes.BOOLEAN_OBJ: return Boolean.valueOf(val); case JavaTypes.BYTE: case JavaTypes.BYTE_OBJ: return Byte.valueOf(val); case JavaTypes.INT: case JavaTypes.INT_OBJ: return Integer.valueOf(val); case JavaTypes.LONG: case JavaTypes.LONG_OBJ: return Long.valueOf(val); case JavaTypes.SHORT: case JavaTypes.SHORT_OBJ: return Short.valueOf(val); case JavaTypes.DOUBLE: case JavaTypes.DOUBLE_OBJ: return Double.valueOf(val); case JavaTypes.FLOAT: case JavaTypes.FLOAT_OBJ: return Float.valueOf(val); case JavaTypes.CHAR: case JavaTypes.CHAR_OBJ: return Character.valueOf(val.charAt(0)); case JavaTypes.STRING: return val; case JavaTypes.ENUM: return Enum.valueOf((Class<? extends Enum>) getDeclaredType(), val); } throw new MetaDataException(_loc.get("bad-external-type", this)); }
From source file:com.draagon.meta.manager.db.driver.GenericSQLDriver.java
/** * Sets a specific value on a prepared statement *//* w w w .j a va 2s .c om*/ protected void setStatementValue(PreparedStatement s, MetaField f, int index, Object value) throws SQLException { int j = index; switch (f.getType()) { case MetaField.BOOLEAN: { if (value == null) { s.setNull(j, Types.BIT); } else if (value instanceof Boolean) { s.setBoolean(j, ((Boolean) value).booleanValue()); } else { s.setBoolean(j, Boolean.valueOf(value.toString()).booleanValue()); } } break; case MetaField.BYTE: { if (value == null) { s.setNull(j, Types.TINYINT); } else if (value instanceof Byte) { s.setByte(j, ((Byte) value).byteValue()); } else { s.setByte(j, Byte.valueOf(value.toString()).byteValue()); } } break; case MetaField.SHORT: { if (value == null) { s.setNull(j, Types.SMALLINT); } else if (value instanceof Short) { s.setShort(j, ((Short) value).shortValue()); } else { s.setShort(j, Short.valueOf(value.toString()).shortValue()); } } break; case MetaField.INT: { if (value == null) { s.setNull(j, Types.INTEGER); } else if (value instanceof Integer) { s.setInt(j, ((Integer) value).intValue()); } else { s.setInt(j, Integer.valueOf(value.toString()).intValue()); } } break; case MetaField.DATE: // NOTE DATE IS TREATED AS LONG! { if (value == null) { s.setNull(j, Types.TIMESTAMP); } else if (value instanceof java.util.Date) { s.setTimestamp(j, new Timestamp(((java.util.Date) value).getTime())); } else { s.setTimestamp(j, new Timestamp(Long.valueOf(value.toString()).longValue())); } } break; case MetaField.LONG: { if (value == null) { s.setNull(j, Types.BIGINT); } else if (value instanceof Long) { s.setLong(j, ((Long) value).longValue()); } else { s.setLong(j, Long.valueOf(value.toString()).longValue()); } } break; // WARNING: This should not be a valid key case MetaField.FLOAT: { if (value == null) { s.setNull(j, Types.FLOAT); } else if (value instanceof Float) { s.setFloat(j, ((Float) value).floatValue()); } else { s.setFloat(j, Float.valueOf(value.toString()).floatValue()); } } break; // WARNING: This should not be a valid key case MetaField.DOUBLE: { if (value == null) { s.setNull(j, Types.DOUBLE); } else if (value instanceof Double) { s.setDouble(j, ((Double) value).doubleValue()); } else { s.setDouble(j, Double.valueOf(value.toString()).doubleValue()); } } break; case MetaField.STRING: if (value == null) { s.setNull(j, Types.VARCHAR); } else { s.setString(j, value.toString()); } break; case MetaField.OBJECT: //if ( value == null ) // s.setNull( j, Types.BLOB ); //else s.setObject(j, value); break; } }