Example usage for java.math BigDecimal toString

List of usage examples for java.math BigDecimal toString

Introduction

In this page you can find the example usage for java.math BigDecimal toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns the string representation of this BigDecimal , using scientific notation if an exponent is needed.

Usage

From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.ExtendedRowSetBuilder.java

public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField,
        Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter)
        throws Exception {
    if (rs == null) {
        return 0;
    }/*from  w  ww. j  ava2s .c  o m*/
    int rowCounter = 0;
    Element docRoot = doc.getDocumentElement();
    ResultSetMetaData metadata = rs.getMetaData();
    buildFormatterAndNamesArray(metadata, fieldNameToFormatter, fieldIdToFormatter);

    boolean noKey = ((keyField == null) || keyField.isEmpty());
    boolean isKeyCol = false;

    boolean isNull = false;
    Element data = null;
    Element row = null;
    Element col = null;
    Text text = null;
    String textVal = null;
    String precKey = null;
    String colKey = null;
    Map<String, Element> keyCols = new TreeMap<String, Element>();
    while (rs.next()) {
        if (rowCounter % 10 == 0) {
            ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger);
        }
        row = parser.createElementNS(doc, AbstractDBO.ROW_NAME, NS);

        parser.setAttribute(row, AbstractDBO.ID_NAME, id);
        for (int j = 1; j <= metadata.getColumnCount(); j++) {
            FieldFormatter fF = fFormatters[j];
            String colName = colNames[j];

            isKeyCol = (!noKey && keyField.contains(new Integer(j)));
            isNull = false;
            col = parser.createElementNS(doc, colName, NS);
            if (isKeyCol) {
                parser.setAttribute(col, AbstractDBO.ID_NAME, String.valueOf(j));
            }
            switch (metadata.getColumnType(j)) {
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE);
                Timestamp dateVal = rs.getTimestamp(j);
                isNull = dateVal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT);
                    textVal = "";
                } else {
                    if (fF != null) {
                        parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getDateFormat());
                        textVal = fF.formatDate(dateVal);
                    } else {
                        parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT);
                        textVal = dateFormatter.format(dateVal);
                    }
                }
            }
                break;
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.REAL: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE);
                float numVal = rs.getFloat(j);
                parser.setAttribute(col, AbstractDBO.NULL_NAME, "false");
                if (fF != null) {
                    parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat());
                    parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator());
                    parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator());
                    textVal = fF.formatNumber(numVal);
                } else {
                    parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat);
                    parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator);
                    parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator);
                    textVal = numberFormatter.format(numVal);
                }
            }
                break;
            case Types.BIGINT:
            case Types.INTEGER:
            case Types.NUMERIC:
            case Types.SMALLINT:
            case Types.TINYINT: {
                BigDecimal bigdecimal = rs.getBigDecimal(j);
                isNull = bigdecimal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    if (metadata.getScale(j) > 0) {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE);
                    } else {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE);
                    }
                    textVal = "";
                } else {
                    if (fF != null) {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE);
                        parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat());
                        parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator());
                        parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator());
                        textVal = fF.formatNumber(bigdecimal);
                    } else if (metadata.getScale(j) > 0) {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE);
                        parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat);
                        parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator);
                        parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator);
                        textVal = numberFormatter.format(bigdecimal);
                    } else {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE);
                        textVal = bigdecimal.toString();
                    }
                }
            }
                break;
            case Types.NCHAR:
            case Types.NVARCHAR: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE);
                textVal = rs.getNString(j);
                isNull = textVal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                }
            }
                break;
            case Types.CHAR:
            case Types.VARCHAR: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE);
                textVal = rs.getString(j);
                isNull = textVal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                }
            }
                break;
            case Types.NCLOB: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE);
                NClob clob = rs.getNClob(j);
                isNull = clob == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                } else {
                    Reader is = clob.getCharacterStream();
                    StringWriter str = new StringWriter();

                    IOUtils.copy(is, str);
                    is.close();
                    textVal = str.toString();
                }
            }
                break;
            case Types.CLOB: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE);
                Clob clob = rs.getClob(j);
                isNull = clob == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                } else {
                    Reader is = clob.getCharacterStream();
                    StringWriter str = new StringWriter();

                    IOUtils.copy(is, str);
                    is.close();
                    textVal = str.toString();
                }
            }
                break;
            case Types.BLOB: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE);
                Blob blob = rs.getBlob(j);
                isNull = blob == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                } else {
                    InputStream is = blob.getBinaryStream();
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    IOUtils.copy(is, baos);
                    is.close();
                    try {
                        byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length());
                        textVal = Base64.getEncoder().encodeToString(buffer);
                    } catch (SQLFeatureNotSupportedException exc) {
                        textVal = Base64.getEncoder().encodeToString(baos.toByteArray());
                    }
                }
            }
                break;
            default: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE);
                textVal = rs.getString(j);
                isNull = textVal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                }
            }
            }
            if (textVal != null) {
                text = doc.createTextNode(textVal);
                col.appendChild(text);
            }
            if (isKeyCol) {
                if (textVal != null) {
                    if (colKey == null) {
                        colKey = textVal;
                    } else {
                        colKey += "##" + textVal;
                    }
                    keyCols.put(String.valueOf(j), col);
                }
            } else {
                row.appendChild(col);
            }
        }
        if (noKey) {
            if (data == null) {
                data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS);
                parser.setAttribute(data, AbstractDBO.ID_NAME, id);
            }
        } else if ((colKey != null) && !colKey.equals(precKey)) {
            if (data != null) {
                docRoot.appendChild(data);
            }
            data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS);
            parser.setAttribute(data, AbstractDBO.ID_NAME, id);
            Element key = parser.createElementNS(doc, AbstractDBO.KEY_NAME, NS);
            data.appendChild(key);
            for (Entry<String, Element> keyColsEntry : keyCols.entrySet()) {
                key.appendChild(keyColsEntry.getValue());
            }
            keyCols.clear();
            precKey = colKey;
        }
        colKey = null;
        data.appendChild(row);
        rowCounter++;
    }
    if (data != null) {
        docRoot.appendChild(data);
    }

    return rowCounter;
}

From source file:Logica.Usuario.java

/**
 *
 * @param numorden/*from w  ww  . j av a2s  .  c  o  m*/
 * @param id
 * @return
 * @throws RemoteException
 *
 * Retorna los datos completos de una orden de compra.
 */
@Override
public recepcionProd getDatosPedidoRecibido(BigDecimal numorden, String id) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden");
    q.setParameter("numorden", new Double(numorden.toString()));
    q.setParameter("recibido", "SI");
    ArrayList<itemRecep> items = new ArrayList<>();
    List<Itmxorden> resultList = q.getResultList();
    if (!resultList.isEmpty() || resultList != null) {
        Itmxorden get = resultList.get(0);
        proveedor p = new proveedor(get.getProveedorNit().getNit(), get.getProveedorNit().getNombre(),
                get.getProveedorNit().getDir(), get.getProveedorNit().getTel(), get.getProveedorNit().getFax(),
                get.getProveedorNit().getCiudad(), get.getProveedorNit().getCelular(),
                get.getProveedorNit().getCorreo(), get.getProveedorNit().getContacto());
        for (Itmxorden itmxorden : resultList) {
            Item itemCinterno = itmxorden.getItemCinterno();
            Query qq = em.createNamedQuery("Recepcion.findByNumorden");
            qq.setParameter("numorden", new Ordencompra(new Double(numorden.toString())));
            List<Recepcion> recepcion = qq.getResultList();
            for (Recepcion r : recepcion) {
                if (r.getCinterno().getCinterno().equalsIgnoreCase(itemCinterno.getCinterno())) {
                    itemRecep itmRecibido = new itemRecep(itemCinterno.getCinterno(), r.getFechallegada(),
                            r.getFechavencimiento(), r.getCcalidad(), r.getCesp(), r.getMverificacion(),
                            r.getObservaciones(), new Float(itmxorden.getCaprobada()),
                            new Float(r.getPrecioanterior()));
                    items.add(itmRecibido);
                }
            }
        }
        recepcionProd recepcionProd = new recepcionProd(numorden, p, "", items, id);
        return recepcionProd;
    } else {
        return null;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param numSol/*from   w w  w .  jav  a  2s .c  o m*/
 * @return ArrayList
 * @throws RemoteException
 *
 * Genera el listado de tems solicitados asociados a un numero de
 * solicitud.
 */
@Override
public ArrayList<ItemInventario> getItems_numSol(BigDecimal numSol) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    ItemJpaController control = new ItemJpaController(emf);
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itxsol.findByNumSol");
    q.setParameter("numSol", new Double(numSol.toString()));
    List<Itxsol> resultList = q.getResultList();
    ArrayList<ItemInventario> retorno = new ArrayList<>();
    for (Itxsol i : resultList) {
        Item findItem = control.findItem(i.getCinterno().getCinterno());
        ItemInventario itm = findItem.EntityToItem(findItem);
        itm.setCantidadSolicitada(new Float(i.getCantidadsol()));
        retorno.add(itm);
    }
    emf.close();
    return retorno;
}

From source file:Logica.Usuario.java

@Override
public recepcionProd getDatosRec2(BigDecimal numorden, String id) throws RemoteException {
    recepcionProd rec = null;//from ww w .ja v a2s.  c  o  m
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden2");
    q.setParameter("numorden", new Double(numorden.toString()));
    List<Itmxorden> resultList = q.getResultList();
    ArrayList<itemRecep> items = new ArrayList<>();
    proveedor p = new proveedor();
    for (Itmxorden i : resultList) {
        Proveedor prov = i.getProveedorNit();
        p = new proveedor(prov.getNit(), prov.getNombre(), prov.getDir(), prov.getTel(), prov.getFax(),
                prov.getCiudad(), prov.getCelular(), prov.getCorreo(), p.getContacto());
        Item itm = i.getItemCinterno();
        items.add(new itemRecep(itm.getCinterno(), "", new Float(i.getCaprobada()), new Float(i.getPrecioU())));
    }
    Query qq = em.createNamedQuery("Ordencompra.findByNumOrden");
    qq.setParameter("numOrden", new Double(numorden.toString()));
    if (qq.getResultList().isEmpty()) {
        return null;
    } else {
        Ordencompra o = (Ordencompra) qq.getResultList().get(0);
        emf.close();
        rec = new recepcionProd(numorden, p, id, items, o.getObservaciones());
        return rec;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param numorden//  ww w.j a  va  2 s. com
 * @param id
 * @return
 * @throws RemoteException
 *
 * Retorna los datos completos de una orden de compra.
 */
@Override
public recepcionProd getDatosRec(BigDecimal numorden, String id) throws RemoteException {
    recepcionProd rec = null;
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden");
    q.setParameter("numorden", new Double(numorden.toString()));
    q.setParameter("recibido", "NO");
    List<Itmxorden> resultList = q.getResultList();
    ArrayList<itemRecep> items = new ArrayList<>();
    proveedor p = new proveedor();
    for (Itmxorden i : resultList) {
        Proveedor prov = i.getProveedorNit();
        p = new proveedor(prov.getNit(), prov.getNombre(), prov.getDir(), prov.getTel(), prov.getFax(),
                prov.getCiudad(), prov.getCelular(), prov.getCorreo(), p.getContacto());
        Item itm = i.getItemCinterno();
        items.add(new itemRecep(itm.getCinterno(), "", new Float(i.getCaprobada()), new Float(i.getPrecioU())));
    }
    Query qq = em.createNamedQuery("Ordencompra.findByNumOrden");
    qq.setParameter("numOrden", new Double(numorden.toString()));
    if (qq.getResultList().isEmpty()) {
        return null;
    } else {
        Ordencompra o = (Ordencompra) qq.getResultList().get(0);
        emf.close();
        rec = new recepcionProd(numorden, p, id, items, o.getObservaciones());
        return rec;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param numSol//w w w. j  av a2  s.co  m
 * @param Aprobado
 * @return
 * @throws RemoteException
 */
@Override
public ArrayList<ItemInventario> getItemsAprobado(BigDecimal numSol, String Aprobado) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    ItemJpaController control = new ItemJpaController(emf);
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itxsol.findByAprobado");
    q.setParameter("numSol", new Double(numSol.toString()));
    q.setParameter("aprobado", "%" + Aprobado + "%");
    List<Itxsol> resultList = q.getResultList();
    ArrayList<ItemInventario> retorno = new ArrayList<>();
    for (Itxsol i : resultList) {
        Item findItem = control.findItem(i.getCinterno().getCinterno());
        ItemInventario itm = findItem.EntityToItem(findItem);
        itm.setCantidadSolicitada(new Float(i.getCantidadsol()));
        retorno.add(itm);
    }
    emf.close();
    return retorno;
}

From source file:Logica.Usuario.java

/**
 *
 * @param numOrden//from   w  w w  . ja  v  a 2 s. c  om
 * @param idRec
 * @param articulos
 * @return
 * @throws RemoteException
 */
@Override
public boolean devolverPedido(BigDecimal numOrden, String idRec, ArrayList<itemRecep> articulos)
        throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createNamedQuery("Itmxorden.findByNumorden");
    q.setParameter("numorden", new Double(numOrden.toString()));
    q.setParameter("recibido", "SI");
    List<Itmxorden> resultList = q.getResultList();
    ItmxordenJpaController itm = new ItmxordenJpaController(emf);
    for (Itmxorden i : resultList) {
        for (itemRecep rec : articulos) {
            if (i.getItemCinterno().getCinterno().equalsIgnoreCase(rec.getCinterno())) {
                try {
                    this.updateCantidad(rec.getCinterno(), -rec.getcAprobada());
                    i.setRecibido("NO");
                    itm.edit(i);
                } catch (Exception ex) {
                    Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    q = em.createNamedQuery("Recepcion.findByNumorden");
    q.setParameter("numorden", new Ordencompra(new Double(numOrden.toString())));
    List<Recepcion> recepcion = q.getResultList();
    RecepcionJpaController contrRec = new RecepcionJpaController(emf);
    for (Recepcion r : recepcion) {
        for (itemRecep rec : articulos) {
            if (rec.getCinterno().equalsIgnoreCase(rec.getCinterno())) {
                try {
                    contrRec.destroy(r.getFechallegada());
                } catch (NonexistentEntityException ex) {
                    Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    return true;

}

From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.StandardRowSetBuilder.java

public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField,
        Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter)
        throws Exception {
    if (rs == null) {
        return 0;
    }//  ww  w. j a v  a  2 s  .c om
    int rowCounter = 0;
    Element docRoot = doc.getDocumentElement();
    ResultSetMetaData metadata = rs.getMetaData();
    FieldFormatter[] fFormatters = buildFormatterArray(metadata, fieldNameToFormatter, fieldIdToFormatter);

    boolean noKey = ((keyField == null) || keyField.isEmpty());

    //boolean isNull = false;
    Element data = null;
    Element row = null;
    Element col = null;
    Text text = null;
    String textVal = null;
    String precKey = null;
    String colKey = null;
    Map<String, String> keyAttr = new HashMap<String, String>();
    while (rs.next()) {
        if (rowCounter % 10 == 0) {
            ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger);
        }
        row = parser.createElement(doc, AbstractDBO.ROW_NAME);

        parser.setAttribute(row, AbstractDBO.ID_NAME, id);
        for (int j = 1; j <= metadata.getColumnCount(); j++) {
            FieldFormatter fF = fFormatters[j];

            //isNull = false;
            col = parser.createElement(doc, AbstractDBO.COL_NAME);
            switch (metadata.getColumnType(j)) {
            case Types.DATE: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DATE_TYPE);
                java.sql.Date dateVal = rs.getDate(j);
                textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT);
            }
                break;
            case Types.TIME: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIME_TYPE);
                java.sql.Time dateVal = rs.getTime(j);
                textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_TIME_FORMAT);
            }
                break;
            case Types.TIMESTAMP: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE);
                Timestamp dateVal = rs.getTimestamp(j);
                textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT);
            }
                break;
            case Types.DOUBLE: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE);
                double numVal = rs.getDouble(j);
                textVal = processDouble(col, fF, numVal);
            }
                break;
            case Types.FLOAT:
            case Types.REAL: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE);
                float numVal = rs.getFloat(j);
                textVal = processDouble(col, fF, numVal);
            }
                break;
            case Types.BIGINT: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BIGINT_TYPE);
                long numVal = rs.getLong(j);
                parser.setAttribute(col, AbstractDBO.NULL_NAME, "false");
                textVal = String.valueOf(numVal);
            }
                break;
            case Types.INTEGER: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.INTEGER_TYPE);
                int numVal = rs.getInt(j);
                parser.setAttribute(col, AbstractDBO.NULL_NAME, "false");
                textVal = String.valueOf(numVal);
            }
                break;
            case Types.SMALLINT:
            case Types.TINYINT: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.SMALLINT_TYPE);
                short numVal = rs.getShort(j);
                parser.setAttribute(col, AbstractDBO.NULL_NAME, "false");
                textVal = String.valueOf(numVal);
            }
                break;
            case Types.NUMERIC:
            case Types.DECIMAL: {
                BigDecimal bigdecimal = rs.getBigDecimal(j);
                boolean isNull = bigdecimal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    if (metadata.getScale(j) > 0) {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE);
                    } else {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE);
                    }
                    textVal = "";
                } else {
                    if (fF != null) {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE);
                        parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat());
                        parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator());
                        parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator());
                        textVal = fF.formatNumber(bigdecimal);
                    } else if (metadata.getScale(j) > 0) {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE);
                        parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat);
                        parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator);
                        parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator);
                        textVal = numberFormatter.format(bigdecimal);
                    } else {
                        parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE);
                        textVal = bigdecimal.toString();
                    }
                }
            }
                break;
            case Types.BOOLEAN: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BOOLEAN_TYPE);
                boolean bVal = rs.getBoolean(j);
                parser.setAttribute(col, AbstractDBO.NULL_NAME, "false");
                textVal = String.valueOf(bVal);
            }
                break;
            case Types.SQLXML: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.XML_TYPE);
                SQLXML xml = rs.getSQLXML(j);
                boolean isNull = xml == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                } else {
                    textVal = xml.getString();
                }
            }
                break;
            case Types.NCHAR:
            case Types.NVARCHAR: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE);
                textVal = rs.getNString(j);
                if (textVal == null) {
                    textVal = "";
                }
            }
                break;
            case Types.CHAR:
            case Types.VARCHAR: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE);
                textVal = rs.getString(j);
                boolean isNull = textVal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                }
            }
                break;
            case Types.NCLOB: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE);
                NClob clob = rs.getNClob(j);
                if (clob != null) {
                    Reader is = clob.getCharacterStream();
                    StringWriter str = new StringWriter();

                    IOUtils.copy(is, str);
                    is.close();
                    textVal = str.toString();
                } else {
                    textVal = "";
                }
            }
                break;
            case Types.CLOB: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE);
                Clob clob = rs.getClob(j);
                if (clob != null) {
                    Reader is = clob.getCharacterStream();
                    StringWriter str = new StringWriter();

                    IOUtils.copy(is, str);
                    is.close();
                    textVal = str.toString();
                } else {
                    textVal = "";
                }
            }
                break;
            case Types.BLOB: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE);
                Blob blob = rs.getBlob(j);
                boolean isNull = blob == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                } else {
                    InputStream is = blob.getBinaryStream();
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    IOUtils.copy(is, baos);
                    is.close();
                    try {
                        byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length());
                        textVal = Base64.getEncoder().encodeToString(buffer);
                    } catch (SQLFeatureNotSupportedException exc) {
                        textVal = Base64.getEncoder().encodeToString(baos.toByteArray());
                    }
                }
            }
                break;
            default: {
                parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE);
                textVal = rs.getString(j);
                boolean isNull = textVal == null;
                parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull));
                if (isNull) {
                    textVal = "";
                }
            }
            }
            if (textVal != null) {
                text = doc.createTextNode(textVal);
                col.appendChild(text);
            }
            if (!noKey && keyField.contains(new Integer(j))) {
                if (textVal != null) {
                    if (colKey == null) {
                        colKey = textVal;
                    } else {
                        colKey += "##" + textVal;
                    }
                    keyAttr.put("key_" + j, textVal);
                }
            } else {
                row.appendChild(col);
            }
        }
        if (noKey) {
            if (data == null) {
                data = parser.createElement(doc, AbstractDBO.DATA_NAME);
                parser.setAttribute(data, AbstractDBO.ID_NAME, id);
            }
        } else if ((colKey != null) && !colKey.equals(precKey)) {
            if (data != null) {
                docRoot.appendChild(data);
            }
            data = parser.createElement(doc, AbstractDBO.DATA_NAME);
            parser.setAttribute(data, AbstractDBO.ID_NAME, id);
            for (Entry<String, String> keyAttrEntry : keyAttr.entrySet()) {
                parser.setAttribute(data, keyAttrEntry.getKey(), keyAttrEntry.getValue());
            }
            keyAttr.clear();
            precKey = colKey;
        }
        colKey = null;
        data.appendChild(row);
        rowCounter++;
    }
    if (data != null) {
        docRoot.appendChild(data);
    }

    return rowCounter;
}

From source file:it.govpay.web.rs.dars.monitoraggio.pagamenti.PagamentiHandler.java

@Override
public Map<String, Voce<String>> getVoci(Pagamento entry, BasicBD bd) throws ConsoleException {
    Map<String, Voce<String>> valori = new HashMap<String, Voce<String>>();
    Date dataPagamento = entry.getDataPagamento();

    String statoPagamento = Stato.INCASSATO.name();
    String statoPagamentoLabel = Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle(
            this.nomeServizio + ".label.sottotitolo." + Stato.INCASSATO.name(), this.sdf.format(dataPagamento));

    Stato stato = entry.getStato();/*from w  w w  .  j  a  v a2s  .  c  o  m*/

    if (!stato.equals(Stato.INCASSATO)) {
        boolean inRitardo = false;
        Integer sogliaGiorniRitardoPagamenti = ConsoleProperties.getInstance()
                .getSogliaGiorniRitardoPagamenti();
        if (sogliaGiorniRitardoPagamenti != null && sogliaGiorniRitardoPagamenti.intValue() > 0) {
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            c.add(Calendar.DAY_OF_YEAR, -sogliaGiorniRitardoPagamenti.intValue());
            inRitardo = dataPagamento.getTime() < c.getTime().getTime();
        }

        if (inRitardo) {
            statoPagamento = PagamentoFilter.STATO_RITARDO_INCASSO;
            if (sogliaGiorniRitardoPagamenti.intValue() > 1)
                statoPagamentoLabel = Utils.getInstance(this.getLanguage())
                        .getMessageWithParamsFromResourceBundle(
                                this.nomeServizio + ".label.sottotitolo."
                                        + PagamentoFilter.STATO_RITARDO_INCASSO + ".sogliaGiorni",
                                sogliaGiorniRitardoPagamenti);
            else
                statoPagamentoLabel = Utils.getInstance(this.getLanguage())
                        .getMessageWithParamsFromResourceBundle(this.nomeServizio + ".label.sottotitolo."
                                + PagamentoFilter.STATO_RITARDO_INCASSO + ".sogliaGiorno");
        } else {
            statoPagamento = Stato.PAGATO.name();
            statoPagamentoLabel = Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle(
                    this.nomeServizio + ".label.sottotitolo." + Stato.PAGATO.name(),
                    this.sdf.format(dataPagamento));
        }
    }

    BigDecimal importo = entry.getImportoPagato() != null ? entry.getImportoPagato() : BigDecimal.ZERO;

    valori.put(
            Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(this.nomeServizio + ".stato.id"),
            new Voce<String>(statoPagamentoLabel, statoPagamento));

    valori.put(
            Utils.getInstance(this.getLanguage())
                    .getMessageFromResourceBundle(this.nomeServizio + ".importoPagato.id"),
            new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                    this.nomeServizio + ".importoPagato.label"), importo.toString() + ""));

    if (dataPagamento != null) {
        valori.put(
                Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".dataPagamento.id"),
                new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                        this.nomeServizio + ".dataPagamento.label"), this.sdf.format(dataPagamento)));
    }

    if (entry.getIur() != null) {
        valori.put(
                Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iur.id"),
                new Voce<String>(Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iur.label"), entry.getIur()));
    }

    if (entry.getIuv() != null) {
        valori.put(
                Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iuv.id"),
                new Voce<String>(Utils.getInstance(this.getLanguage())
                        .getMessageFromResourceBundle(this.nomeServizio + ".iuv.label"), entry.getIuv()));
    }

    if (StringUtils.isNotEmpty(entry.getCodDominio())) {
        try {
            Dominio dominio = entry.getDominio(bd);
            Domini dominiDars = new Domini();
            Elemento elemento = ((DominiHandler) dominiDars.getDarsHandler()).getElemento(dominio,
                    dominio.getId(), dominiDars.getPathServizio(), bd);
            valori.put(
                    Utils.getInstance(this.getLanguage())
                            .getMessageFromResourceBundle(this.nomeServizio + ".idDominio.id"),
                    new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                            this.nomeServizio + ".idDominio.label"), elemento.getTitolo()));

        } catch (Exception e) {
            valori.put(
                    Utils.getInstance(this.getLanguage())
                            .getMessageFromResourceBundle(this.nomeServizio + ".idDominio.id"),
                    new Voce<String>(Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                            this.nomeServizio + ".idDominio.label"), entry.getCodDominio()));
        }
    }

    try {
        SingoloVersamento singoloVersamento = entry.getSingoloVersamento(bd);
        if (singoloVersamento != null) {
            valori.put(
                    Utils.getInstance(this.getLanguage())
                            .getMessageFromResourceBundle(this.nomeServizio + ".codSingoloVersamentoEnte.id"),
                    new Voce<String>(
                            Utils.getInstance(this.getLanguage()).getMessageFromResourceBundle(
                                    this.nomeServizio + ".codSingoloVersamentoEnte.label"),
                            singoloVersamento.getCodSingoloVersamentoEnte()));
        }
    } catch (ServiceException e) {
        throw new ConsoleException(e);
    }
    return valori;
}

From source file:Logica.Usuario.java

/**
 *
 * @param numOrden/* ww  w. j a  v  a  2  s  . c  om*/
 * @param idRec
 * @param articulos
 * @return
 * @throws RemoteException
 *
 * Funcin para recibir el pedido y registrarlo en la base de datos.
 */
@Override
public boolean recibirPedido(BigDecimal numOrden, String idRec, ArrayList<itemRecep> articulos)
        throws RemoteException {
    boolean valido = false;
    try {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
        Recepcion r = new Recepcion();
        RecepcionJpaController contr = new RecepcionJpaController(emf);
        Ordencompra orden = new Ordencompra();
        for (itemRecep a : articulos) {

            orden = new OrdencompraJpaController(emf).findOrdencompra(new Double(numOrden.toString()));
            ItemJpaController itemJpaController = new ItemJpaController(emf);
            Item findItem = itemJpaController.findItem(a.getCinterno());
            findItem.setCantidad(findItem.getCantidad() + a.getcAprobada());
            findItem.setCcalidad(a.getcCalidad());
            findItem.setCesp(a.getcEsp());
            itemJpaController.edit(findItem);
            this.updateCantidad(findItem.getCinterno(), a.getcAprobada());
            r = new Recepcion(a.getfLlegada());
            r.setFechavencimiento(a.getfVencimiento());
            r.setCcalidad(a.getcCalidad());
            r.setCesp(a.getcEsp());
            r.setMverificacion(a.getmVerificacion().toString());
            r.setCinterno(findItem);
            r.setIdUsuario(new UsuarioJpaController(emf).findUsuario(idRec));
            r.setNumOrden(orden);
            r.setPrecioanterior(new Double(a.getPrecio()));
            r.setObservaciones(a.getObs());
            contr.create(r);
            EntityManager em = emf.createEntityManager();
            Query q = em.createNamedQuery("Itmxorden.findByNumorden_item");
            q.setParameter("numorden", orden.getNumOrden());
            ItmxordenJpaController itmcontrol = new ItmxordenJpaController(emf);
            q.setParameter("cinterno", findItem);
            List<Itmxorden> resultList = q.getResultList();
            Itmxorden findItmxorden = itmcontrol.findItmxorden(resultList.get(0).getIdOCompra());
            findItmxorden.setRecibido("SI");
            itmcontrol.edit(findItmxorden);
            valido = true;
        }
        emf.close();
    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    return valido;
}