Example usage for java.sql Date valueOf

List of usage examples for java.sql Date valueOf

Introduction

In this page you can find the example usage for java.sql Date valueOf.

Prototype

@SuppressWarnings("deprecation")
public static Date valueOf(LocalDate date) 

Source Link

Document

Obtains an instance of Date from a LocalDate object with the same year, month and day of month value as the given LocalDate .

Usage

From source file:org.apache.ddlutils.model.Column.java

/**
 * Tries to parse the default value of the column and returns it as an object of the
 * corresponding java type. If the value could not be parsed, then the original
 * definition is returned.//from  www.j av a  2  s.  co  m
 * 
 * @return The parsed default value
 */
public Object getParsedDefaultValue() {
    if ((_defaultValue != null) && (_defaultValue.length() > 0)) {
        try {
            switch (_typeCode) {
            case Types.TINYINT:
            case Types.SMALLINT:
                return new Short(_defaultValue);
            case Types.INTEGER:
                return new Integer(_defaultValue);
            case Types.BIGINT:
                return new Long(_defaultValue);
            case Types.DECIMAL:
            case Types.NUMERIC:
                return new BigDecimal(_defaultValue);
            case Types.REAL:
                return new Float(_defaultValue);
            case Types.DOUBLE:
            case Types.FLOAT:
                return new Double(_defaultValue);
            case Types.DATE:
                return Date.valueOf(_defaultValue);
            case Types.TIME:
                return Time.valueOf(_defaultValue);
            case Types.TIMESTAMP:
                return Timestamp.valueOf(_defaultValue);
            case Types.BIT:
            case Types.BOOLEAN:
                return ConvertUtils.convert(_defaultValue, Boolean.class);
            }
        } catch (NumberFormatException ex) {
            return null;
        } catch (IllegalArgumentException ex) {
            return null;
        }
    }
    return _defaultValue;
}

From source file:com.ar.hotwiredautorepairshop.beans.MainBean.java

@PostConstruct
public void init() {

    Customer customer1 = new Customer();
    String socialSecurityNumber1 = "197607261992";
    customer1.setSocialSecurityNumber(socialSecurityNumber1);
    customer1.setFirstName("Anders");
    customer1.setLastName("Rapp");
    customer1.setStreetAddress("Waernsgatan 3C");
    customer1.setZipCode("41670");
    customer1.setCity("Gteborg");
    customer1.setEmail("anders.rapp@gmail.com");
    customer1.setPhoneNumber("+46703305805");
    customer1.setGender("male");
    customer1.setAge(calculateAge(socialSecurityNumber1));

    Customer customer2 = new Customer();
    String socialSecurityNumber2 = "195912017894";
    customer2.setSocialSecurityNumber(socialSecurityNumber2);
    customer2.setFirstName("Johan");
    customer2.setLastName("Rapp");
    customer2.setStreetAddress("Vrbackegatan 31");
    customer2.setZipCode("76584");
    customer2.setCity("Vsters");
    customer2.setEmail("johan.rapp@gmail.com");
    customer2.setPhoneNumber("+46707895623");
    customer2.setGender("male");
    customer2.setAge(calculateAge(socialSecurityNumber2));

    Customer customer3 = new Customer();
    String socialSecurityNumber3 = "197606132905";
    customer3.setSocialSecurityNumber(socialSecurityNumber3);
    customer3.setFirstName("Kristina");
    customer3.setLastName("Nilsson");
    customer3.setStreetAddress("Waernsgatan 3C");
    customer3.setZipCode("41670");
    customer3.setCity("Gteborg");
    customer3.setEmail("kristina.nilsson76@gmail.com");
    customer3.setPhoneNumber("+46706893068");
    customer3.setGender("female");
    customer3.setAge(calculateAge(socialSecurityNumber3));

    Customer customer4 = new Customer();
    String socialSecurityNumber4 = "194711203102";
    customer4.setSocialSecurityNumber(socialSecurityNumber4);
    customer4.setFirstName("Gunborg");
    customer4.setLastName("Rapp");
    customer4.setStreetAddress("Sjhagavgen 11");
    customer4.setZipCode("51234");
    customer4.setCity("Borghamn");
    customer4.setEmail("gunborg.rapp@gmail.com");
    customer4.setPhoneNumber("+46707252525");
    customer4.setGender("female");
    customer4.setAge(calculateAge(socialSecurityNumber4));

    Customer customer5 = new Customer();
    String socialSecurityNumber5 = "199005114237";
    customer5.setSocialSecurityNumber(socialSecurityNumber5);
    customer5.setFirstName("Benjamin");
    customer5.setLastName("Bengtsson");
    customer5.setStreetAddress("Furuvgen 43");
    customer5.setZipCode("12345");
    customer5.setCity("Vnersborg");
    customer5.setEmail("benjamin.bengtsson@gmail.com");
    customer5.setPhoneNumber("+46707898989");
    customer5.setGender("male");
    customer5.setAge(calculateAge(socialSecurityNumber5));

    Customer customer6 = new Customer();
    String socialSecurityNumber6 = "196206211345";
    customer6.setSocialSecurityNumber(socialSecurityNumber6);
    customer6.setFirstName("Arnold");
    customer6.setLastName("Schwarzenegger");
    customer6.setStreetAddress("GetOutOfTheWay 321");
    customer6.setZipCode("12345");
    customer6.setCity("Lund");
    customer6.setEmail("arnold.schwarzenegger@gmail.com");
    customer6.setPhoneNumber("+465559989");
    customer6.setGender("male");
    customer6.setAge(calculateAge(socialSecurityNumber6));

    Mechanic mechanic1 = new Mechanic();
    mechanic1.setSocialSecurityNumber("197409231998");
    mechanic1.setFirstName("Eric");
    mechanic1.setLastName("Rapp");
    mechanic1.setStreetAddress("Majsgatan 27");
    mechanic1.setZipCode("32165");
    mechanic1.setCity("ngelholm");
    mechanic1.setEmail("eric.rapp@gmail.com");
    mechanic1.setPhoneNumber("+46702555666");
    mechanic1.setGender("male");

    Mechanic mechanic2 = new Mechanic();
    mechanic2.setSocialSecurityNumber("198707074563");
    mechanic2.setFirstName("Kalle");
    mechanic2.setLastName("Svensson");
    mechanic2.setStreetAddress("Trskvgen 21");
    mechanic2.setZipCode("98765");
    mechanic2.setCity("Uddevalla");
    mechanic2.setEmail("kalle.svensson@gmail.com");
    mechanic2.setPhoneNumber("+46707444555");
    mechanic2.setGender("male");

    Mechanic mechanic3 = new Mechanic();
    mechanic3.setSocialSecurityNumber("198002151111");
    mechanic3.setFirstName("Nina");
    mechanic3.setLastName("Haugen");
    mechanic3.setStreetAddress("Godisvgen 101");
    mechanic3.setZipCode("41625");
    mechanic3.setCity("Gteborg");
    mechanic3.setEmail("nina.haugen@gmail.com");
    mechanic3.setPhoneNumber("+4670799988");
    mechanic3.setGender("female");

    Car car1 = new Car();
    car1.setLicensePlate("AAA111");
    car1.setBrand("Volvo");
    car1.setModel("X90");
    car1.setProductionYear("2008");
    car1.setFuelType("gasoline");
    car1.setMileage(20000);//www .j  a  va 2  s.  c om

    Car car2 = new Car();
    car2.setLicensePlate("BBB111");
    car2.setBrand("Ford");
    car2.setModel("Escort");
    car2.setProductionYear("1989");
    car2.setFuelType("gasoline");
    car2.setMileage(500000);

    Car car3 = new Car();
    car3.setLicensePlate("CCC111");
    car3.setBrand("Ford");
    car3.setModel("Ka");
    car3.setProductionYear("2005");
    car3.setFuelType("gasoline");
    car3.setMileage(2000);

    Car car4 = new Car();
    car4.setLicensePlate("DDD111");
    car4.setBrand("SAAB");
    car4.setModel("9-5");
    car4.setProductionYear("1997");
    car4.setFuelType("diesel");
    car4.setMileage(50000);

    Car car5 = new Car();
    car5.setLicensePlate("EEE111");
    car5.setBrand("Rolls Royce");
    car5.setModel("Bentley");
    car5.setProductionYear("2015");
    car5.setFuelType("gasoline");
    car5.setMileage(1500);

    Car car6 = new Car();
    car6.setLicensePlate("FFF111");
    car6.setBrand("Volvo");
    car6.setModel("340");
    car6.setProductionYear("1981");
    car6.setFuelType("gasoline");
    car6.setMileage(700000);

    Car car7 = new Car();
    car7.setLicensePlate("GGG111");
    car7.setBrand("SAAB");
    car7.setModel("9000");
    car7.setProductionYear("1990");
    car7.setFuelType("diesel");
    car7.setMileage(345700);

    Car car8 = new Car();
    car8.setLicensePlate("HHH111");
    car8.setBrand("Volvo");
    car8.setModel("S70");
    car8.setProductionYear("2001");
    car8.setFuelType("gasoline");
    car8.setMileage(150000);

    Car car9 = new Car();
    car9.setLicensePlate("III111");
    car9.setBrand("Lada");
    car9.setModel("russia");
    car9.setProductionYear("1957");
    car9.setFuelType("diesel");
    car9.setMileage(2250000);

    WorkType workType1 = new WorkType();
    workType1.setDescription("change oil");
    workType1.setPrice(150);

    WorkType workType2 = new WorkType();
    workType2.setDescription("change tires");
    workType2.setPrice(455);

    WorkType workType3 = new WorkType();
    workType3.setDescription("change windshield wipers");
    workType3.setPrice(275);

    WorkType workType4 = new WorkType();
    workType4.setDescription("paint job");
    workType4.setPrice(8995);

    WorkType workType5 = new WorkType();
    workType5.setDescription("fender bender");
    workType5.setPrice(4995);

    WorkType workType6 = new WorkType();
    workType6.setDescription("change carborator");
    workType6.setPrice(2495);

    carRepository.save(car1);
    carRepository.save(car2);
    carRepository.save(car3);
    carRepository.save(car4);
    carRepository.save(car5);
    carRepository.save(car6);
    carRepository.save(car7);
    carRepository.save(car8);
    carRepository.save(car9);

    customer1.getOwnedCars().add(car1);
    customer2.getOwnedCars().add(car2);
    customer3.getOwnedCars().add(car3);
    customer4.getOwnedCars().add(car4);
    customer5.getOwnedCars().add(car5);
    customer4.getOwnedCars().add(car6);
    customer5.getOwnedCars().add(car7);
    customer5.getOwnedCars().add(car8);
    customer6.getOwnedCars().add(car9);

    customerRepository.save(customer1);
    customerRepository.save(customer2);
    customerRepository.save(customer3);
    customerRepository.save(customer4);
    customerRepository.save(customer5);
    customerRepository.save(customer6);

    mechanicRepository.save(mechanic1);
    mechanicRepository.save(mechanic2);
    mechanicRepository.save(mechanic3);

    workTypeRepository.save(workType1);
    workTypeRepository.save(workType2);
    workTypeRepository.save(workType3);
    workTypeRepository.save(workType4);
    workTypeRepository.save(workType5);
    workTypeRepository.save(workType6);

    ServiceOrder serviceOrder1 = new ServiceOrder();
    serviceOrder1.setCustomer(customer1);
    serviceOrder1.setCar(car1);
    serviceOrder1.setMechanic(mechanic3);
    serviceOrder1.setRegistrationDate(Date.valueOf("2015-02-11"));
    serviceOrder1.setServiceDate(Date.valueOf("2015-02-18"));
    serviceOrder1.setPickupDate(Date.valueOf("2015-02-25"));
    serviceOrder1.setActive(false);

    ServiceOrder serviceOrder2 = new ServiceOrder();
    serviceOrder2.setCustomer(customer2);
    serviceOrder2.setCar(car2);
    serviceOrder2.setMechanic(mechanic1);
    serviceOrder2.setRegistrationDate(Date.valueOf("2015-02-11"));
    serviceOrder2.setServiceDate(Date.valueOf("2015-02-18"));
    serviceOrder2.setPickupDate(Date.valueOf("2015-02-25"));
    serviceOrder2.setActive(false);

    ServiceOrder serviceOrder3 = new ServiceOrder();
    serviceOrder3.setCustomer(customer3);
    serviceOrder3.setCar(car3);
    serviceOrder3.setMechanic(mechanic2);
    serviceOrder3.setRegistrationDate(Date.valueOf("2015-02-13"));
    serviceOrder3.setServiceDate(Date.valueOf("2015-02-20"));
    serviceOrder3.setPickupDate(Date.valueOf("2015-02-27"));
    serviceOrder3.setActive(false);

    ServiceOrder serviceOrder4 = new ServiceOrder();
    serviceOrder4.setCustomer(customer4);
    serviceOrder4.setCar(car4);
    serviceOrder4.setMechanic(mechanic1);
    serviceOrder4.setRegistrationDate(Date.valueOf("2015-02-15"));
    serviceOrder4.setServiceDate(Date.valueOf("2015-02-22"));
    serviceOrder4.setPickupDate(Date.valueOf("2015-03-01"));
    serviceOrder4.setActive(false);

    ServiceOrder serviceOrder5 = new ServiceOrder();
    serviceOrder5.setCustomer(customer5);
    serviceOrder5.setCar(car5);
    serviceOrder5.setMechanic(mechanic2);
    serviceOrder5.setRegistrationDate(Date.valueOf("2015-02-21"));
    serviceOrder5.setServiceDate(Date.valueOf("2015-02-28"));
    serviceOrder5.setPickupDate(Date.valueOf("2015-03-07"));
    serviceOrder5.setActive(false);

    ServiceOrder serviceOrder6 = new ServiceOrder();
    serviceOrder6.setCustomer(customer4);
    serviceOrder6.setCar(car6);
    serviceOrder6.setMechanic(mechanic3);
    serviceOrder6.setRegistrationDate(Date.valueOf("2015-03-01"));
    serviceOrder6.setServiceDate(Date.valueOf("2015-03-08"));
    serviceOrder6.setPickupDate(Date.valueOf("2015-03-15"));
    serviceOrder6.setActive(false);

    ServiceOrder serviceOrder7 = new ServiceOrder();
    serviceOrder7.setCustomer(customer5);
    serviceOrder7.setCar(car7);
    serviceOrder7.setMechanic(mechanic1);
    serviceOrder7.setRegistrationDate(Date.valueOf("2015-03-12"));
    serviceOrder7.setServiceDate(Date.valueOf("2015-03-19"));
    serviceOrder7.setPickupDate(Date.valueOf("2015-03-26"));
    serviceOrder7.setActive(true);

    ServiceOrderRepository.save(serviceOrder1);
    ServiceOrderRepository.save(serviceOrder2);
    ServiceOrderRepository.save(serviceOrder3);
    ServiceOrderRepository.save(serviceOrder4);
    ServiceOrderRepository.save(serviceOrder5);
    ServiceOrderRepository.save(serviceOrder6);
    ServiceOrderRepository.save(serviceOrder7);

    int totalPriceServiceOrder1 = 0;
    serviceOrder1.getWorkTypes().add(workType1);
    totalPriceServiceOrder1 += workType1.getPrice();
    serviceOrder1.getWorkTypes().add(workType3);
    totalPriceServiceOrder1 += workType3.getPrice();
    serviceOrder1.getWorkTypes().add(workType5);
    totalPriceServiceOrder1 += workType5.getPrice();
    serviceOrder1.getWorkTypes().add(workType6);
    totalPriceServiceOrder1 += workType6.getPrice();
    serviceOrder1.setTotalPrice(totalPriceServiceOrder1);

    int totalPriceServiceOrder2 = 0;
    serviceOrder2.getWorkTypes().add(workType2);
    totalPriceServiceOrder2 += workType2.getPrice();
    serviceOrder2.getWorkTypes().add(workType3);
    totalPriceServiceOrder2 += workType3.getPrice();
    serviceOrder2.getWorkTypes().add(workType5);
    totalPriceServiceOrder2 += workType5.getPrice();
    serviceOrder2.setTotalPrice(totalPriceServiceOrder2);

    int totalPriceServiceOrder3 = 0;
    serviceOrder3.getWorkTypes().add(workType4);
    totalPriceServiceOrder3 += workType4.getPrice();
    serviceOrder3.getWorkTypes().add(workType5);
    totalPriceServiceOrder3 += workType5.getPrice();
    serviceOrder3.getWorkTypes().add(workType6);
    totalPriceServiceOrder3 += workType6.getPrice();
    serviceOrder3.setTotalPrice(totalPriceServiceOrder3);

    int totalPriceServiceOrder4 = 0;
    serviceOrder4.getWorkTypes().add(workType1);
    totalPriceServiceOrder4 += workType1.getPrice();
    serviceOrder4.getWorkTypes().add(workType3);
    totalPriceServiceOrder4 += workType3.getPrice();
    serviceOrder4.setTotalPrice(totalPriceServiceOrder4);

    int totalPriceServiceOrder5 = 0;
    serviceOrder5.getWorkTypes().add(workType1);
    totalPriceServiceOrder5 += workType1.getPrice();
    serviceOrder5.getWorkTypes().add(workType2);
    totalPriceServiceOrder5 += workType2.getPrice();
    serviceOrder5.getWorkTypes().add(workType3);
    totalPriceServiceOrder5 += workType3.getPrice();
    serviceOrder5.setTotalPrice(totalPriceServiceOrder5);

    int totalPriceServiceOrder6 = 0;
    serviceOrder6.getWorkTypes().add(workType3);
    totalPriceServiceOrder6 += workType3.getPrice();
    serviceOrder6.getWorkTypes().add(workType4);
    totalPriceServiceOrder6 += workType4.getPrice();
    serviceOrder6.setTotalPrice(totalPriceServiceOrder6);

    int totalPriceServiceOrder7 = 0;
    serviceOrder7.getWorkTypes().add(workType1);
    totalPriceServiceOrder7 += workType1.getPrice();
    serviceOrder7.getWorkTypes().add(workType3);
    totalPriceServiceOrder7 += workType3.getPrice();
    serviceOrder7.getWorkTypes().add(workType4);
    totalPriceServiceOrder7 += workType4.getPrice();
    serviceOrder7.setTotalPrice(totalPriceServiceOrder7);

    ServiceOrderRepository.save(serviceOrder1);
    ServiceOrderRepository.save(serviceOrder2);
    ServiceOrderRepository.save(serviceOrder3);
    ServiceOrderRepository.save(serviceOrder4);
    ServiceOrderRepository.save(serviceOrder5);
    ServiceOrderRepository.save(serviceOrder6);
    ServiceOrderRepository.save(serviceOrder7);

    Complaint complaint1 = new Complaint();
    complaint1.setIncompleteServiceOrder(serviceOrder5);
    complaint1.setActive(false);

    Complaint complaint2 = new Complaint();
    complaint2.setIncompleteServiceOrder(serviceOrder6);
    complaint2.setActive(false);

    Complaint complaint3 = new Complaint();
    complaint3.setIncompleteServiceOrder(serviceOrder4);
    complaint3.setActive(true);

    complaintRepository.save(complaint1);
    complaintRepository.save(complaint2);
    complaintRepository.save(complaint3);

    complaint1.setWorkTypes(serviceOrder5.getWorkTypes());
    complaint2.getWorkTypes().add(workType3);
    complaint2.getWorkTypes().add(workType4);
    complaint3.getWorkTypes().add(workType3);

    complaintRepository.save(complaint1);
    complaintRepository.save(complaint2);
    complaintRepository.save(complaint3);

    ServiceOrder serviceOrder8 = new ServiceOrder();
    serviceOrder8.setCustomer(customer5);
    serviceOrder8.setCar(car5);
    serviceOrder8.setMechanic(mechanic3);
    serviceOrder8.setRegistrationDate(Date.valueOf("2015-03-14"));
    serviceOrder8.setServiceDate(Date.valueOf("2015-03-21"));
    serviceOrder8.setPickupDate(Date.valueOf("2015-03-28"));
    serviceOrder8.setActive(true);

    ServiceOrder serviceOrder9 = new ServiceOrder();
    serviceOrder9.setCustomer(customer4);
    serviceOrder9.setCar(car6);
    serviceOrder9.setMechanic(mechanic3);
    serviceOrder9.setRegistrationDate(Date.valueOf("2015-03-15"));
    serviceOrder9.setServiceDate(Date.valueOf("2015-03-22"));
    serviceOrder9.setPickupDate(Date.valueOf("2015-03-29"));
    serviceOrder9.setActive(true);

    ServiceOrderRepository.save(serviceOrder8);
    ServiceOrderRepository.save(serviceOrder9);

    int totalPriceServiceOrder8 = 0;
    serviceOrder8.getWorkTypes().add(workType1);
    totalPriceServiceOrder8 += workType1.getPrice();
    serviceOrder8.getWorkTypes().add(workType2);
    totalPriceServiceOrder8 += workType2.getPrice();
    serviceOrder8.getWorkTypes().add(workType3);
    totalPriceServiceOrder8 += workType3.getPrice();
    serviceOrder8.setTotalPrice(totalPriceServiceOrder8);
    serviceOrder8.setComplaint(complaint1);

    int totalPriceServiceOrder9 = 0;
    serviceOrder9.getWorkTypes().add(workType4);
    totalPriceServiceOrder9 += workType4.getPrice();
    serviceOrder9.setTotalPrice(totalPriceServiceOrder9);
    serviceOrder9.setComplaint(complaint2);

    ServiceOrderRepository.save(serviceOrder8);
    ServiceOrderRepository.save(serviceOrder9);
}

From source file:org.apache.hawq.pxf.plugins.hive.HiveResolver.java

int initPartitionFields(StringBuilder parts) {
    if (partitionKeys.equals(HiveDataFragmenter.HIVE_NO_PART_TBL)) {
        return 0;
    }/* w w w  . j av  a  2  s  .c om*/
    String[] partitionLevels = partitionKeys.split(HiveDataFragmenter.HIVE_PARTITIONS_DELIM);
    for (String partLevel : partitionLevels) {
        String[] levelKey = partLevel.split(HiveDataFragmenter.HIVE_1_PART_DELIM);
        String type = levelKey[1];
        String val = levelKey[2];
        parts.append(delimiter);

        if (isDefaultPartition(type, val)) {
            parts.append(nullChar);
        } else {
            // ignore the type's parameters
            String typeName = type.replaceAll("\\(.*\\)", "");
            switch (typeName) {
            case serdeConstants.STRING_TYPE_NAME:
            case serdeConstants.VARCHAR_TYPE_NAME:
            case serdeConstants.CHAR_TYPE_NAME:
                parts.append(val);
                break;
            case serdeConstants.BOOLEAN_TYPE_NAME:
                parts.append(Boolean.parseBoolean(val));
                break;
            case serdeConstants.TINYINT_TYPE_NAME:
            case serdeConstants.SMALLINT_TYPE_NAME:
                parts.append(Short.parseShort(val));
                break;
            case serdeConstants.INT_TYPE_NAME:
                parts.append(Integer.parseInt(val));
                break;
            case serdeConstants.BIGINT_TYPE_NAME:
                parts.append(Long.parseLong(val));
                break;
            case serdeConstants.FLOAT_TYPE_NAME:
                parts.append(Float.parseFloat(val));
                break;
            case serdeConstants.DOUBLE_TYPE_NAME:
                parts.append(Double.parseDouble(val));
                break;
            case serdeConstants.TIMESTAMP_TYPE_NAME:
                parts.append(Timestamp.valueOf(val));
                break;
            case serdeConstants.DATE_TYPE_NAME:
                parts.append(Date.valueOf(val));
                break;
            case serdeConstants.DECIMAL_TYPE_NAME:
                parts.append(HiveDecimal.create(val).bigDecimalValue());
                break;
            case serdeConstants.BINARY_TYPE_NAME:
                Utilities.byteArrayToOctalString(val.getBytes(), parts);
                break;
            default:
                throw new UnsupportedTypeException("Unsupported partition type: " + type);
            }
        }
    }
    return partitionLevels.length;
}

From source file:org.jumpmind.db.model.Column.java

/**
 * Tries to parse the default value of the column and returns it as an
 * object of the corresponding java type. If the value could not be parsed,
 * then the original definition is returned.
 * //from  ww w . j a v a  2 s  .com
 * @return The parsed default value
 */
public Object getParsedDefaultValue() {
    if ((defaultValue != null) && (defaultValue.length() > 0)) {
        try {
            switch (mappedTypeCode) {
            case Types.TINYINT:
            case Types.SMALLINT:
                return new Short(defaultValue);
            case Types.INTEGER:
                try {
                    return new Integer(defaultValue);
                } catch (NumberFormatException e) {
                    return new Long(defaultValue);
                }
            case Types.BIGINT:
                return new Long(defaultValue);
            case Types.DECIMAL:
            case Types.NUMERIC:
                return new BigDecimal(defaultValue);
            case Types.REAL:
                return new Float(defaultValue);
            case Types.DOUBLE:
            case Types.FLOAT:
                return new Double(defaultValue);
            case Types.DATE:
                return Date.valueOf(defaultValue);
            case Types.TIME:
                return Time.valueOf(defaultValue);
            case Types.TIMESTAMP:
                return Timestamp.valueOf(defaultValue);
            case Types.BIT:
                return FormatUtils.toBoolean(defaultValue);
            default:
                if (PlatformUtils.supportsJava14JdbcTypes()
                        && (mappedTypeCode == PlatformUtils.determineBooleanTypeCode())) {
                    return FormatUtils.toBoolean(defaultValue);
                }
                break;
            }
        } catch (NumberFormatException ex) {
            return null;
        } catch (IllegalArgumentException ex) {
            return null;
        }
    }
    return defaultValue;
}

From source file:org.apache.synapse.mediators.db.AbstractDBMediator.java

/**
 * Return a Prepared statement for the given Statement object, which is ready to be executed
 *
 * @param stmnt  SQL stataement to be executed
 * @param con    The connection to be used
 * @param msgCtx Current message context
 * @return a PreparedStatement// w w  w .  jav  a 2 s.  c  o m
 * @throws SQLException on error
 */
protected PreparedStatement getPreparedStatement(Statement stmnt, Connection con, MessageContext msgCtx)
        throws SQLException {

    SynapseLog synLog = getLog(msgCtx);

    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Getting a connection from DataSource " + getDSName()
                + " and preparing statement : " + stmnt.getRawStatement());
    }

    if (con == null) {
        String msg = "Connection from DataSource " + getDSName() + " is null.";
        log.error(msg);
        throw new SynapseException(msg);
    }

    if (dataSource instanceof BasicDataSource) {

        BasicDataSource basicDataSource = (BasicDataSource) dataSource;
        int numActive = basicDataSource.getNumActive();
        int numIdle = basicDataSource.getNumIdle();
        String connectionId = Integer.toHexString(con.hashCode());

        DBPoolView dbPoolView = getDbPoolView();
        if (dbPoolView != null) {
            dbPoolView.setNumActive(numActive);
            dbPoolView.setNumIdle(numIdle);
            dbPoolView.updateConnectionUsage(connectionId);
        }

        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("[ DB Connection : " + con + " ]");
            synLog.traceOrDebug("[ DB Connection instance identifier : " + connectionId + " ]");
            synLog.traceOrDebug("[ Number of Active Connection : " + numActive + " ]");
            synLog.traceOrDebug("[ Number of Idle Connection : " + numIdle + " ]");
        }
    }

    PreparedStatement ps = con.prepareStatement(stmnt.getRawStatement());

    // set parameters if any
    List<Statement.Parameter> params = stmnt.getParameters();
    int column = 1;

    for (Statement.Parameter param : params) {
        if (param == null) {
            continue;
        }
        String value = (param.getPropertyName() != null ? param.getPropertyName()
                : param.getXpath().stringValueOf(msgCtx));

        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Setting as parameter : " + column + " value : " + value + " as JDBC Type : "
                    + param.getType() + "(see java.sql.Types for valid " + "types)");
        }

        switch (param.getType()) {
        // according to J2SE 1.5 /docs/guide/jdbc/getstart/mapping.html
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR: {
            if (value != null && value.length() != 0) {
                ps.setString(column++, value);
            } else {
                ps.setString(column++, null);
            }
            break;
        }
        case Types.NUMERIC:
        case Types.DECIMAL: {
            if (value != null && value.length() != 0) {
                ps.setBigDecimal(column++, new BigDecimal(value));
            } else {
                ps.setBigDecimal(column++, null);
            }
            break;
        }
        case Types.BIT: {
            if (value != null && value.length() != 0) {
                ps.setBoolean(column++, Boolean.parseBoolean(value));
            } else {
                ps.setNull(column++, Types.BIT);
            }
            break;
        }
        case Types.TINYINT: {
            if (value != null && value.length() != 0) {
                ps.setByte(column++, Byte.parseByte(value));
            } else {
                ps.setNull(column++, Types.TINYINT);
            }
            break;
        }
        case Types.SMALLINT: {
            if (value != null && value.length() != 0) {
                ps.setShort(column++, Short.parseShort(value));
            } else {
                ps.setNull(column++, Types.SMALLINT);
            }
            break;
        }
        case Types.INTEGER: {
            if (value != null && value.length() != 0) {
                ps.setInt(column++, Integer.parseInt(value));
            } else {
                ps.setNull(column++, Types.INTEGER);
            }
            break;
        }
        case Types.BIGINT: {
            if (value != null && value.length() != 0) {
                ps.setLong(column++, Long.parseLong(value));
            } else {
                ps.setNull(column++, Types.BIGINT);
            }
            break;
        }
        case Types.REAL: {
            if (value != null && value.length() != 0) {
                ps.setFloat(column++, Float.parseFloat(value));
            } else {
                ps.setNull(column++, Types.REAL);
            }
            break;
        }
        case Types.FLOAT: {
            if (value != null && value.length() != 0) {
                ps.setDouble(column++, Double.parseDouble(value));
            } else {
                ps.setNull(column++, Types.FLOAT);
            }
            break;
        }
        case Types.DOUBLE: {
            if (value != null && value.length() != 0) {
                ps.setDouble(column++, Double.parseDouble(value));
            } else {
                ps.setNull(column++, Types.DOUBLE);
            }
            break;
        }
        // skip BINARY, VARBINARY and LONGVARBINARY
        case Types.DATE: {
            if (value != null && value.length() != 0) {
                ps.setDate(column++, Date.valueOf(value));
            } else {
                ps.setNull(column++, Types.DATE);
            }
            break;
        }
        case Types.TIME: {
            if (value != null && value.length() != 0) {
                ps.setTime(column++, Time.valueOf(value));
            } else {
                ps.setNull(column++, Types.TIME);
            }
            break;
        }
        case Types.TIMESTAMP: {
            if (value != null && value.length() != 0) {
                ps.setTimestamp(column++, Timestamp.valueOf(value));
            } else {
                ps.setNull(column++, Types.TIMESTAMP);
            }
            break;
        }
        // skip CLOB, BLOB, ARRAY, DISTINCT, STRUCT, REF, JAVA_OBJECT
        default: {
            String msg = "Trying to set an un-supported JDBC Type : " + param.getType() + " against column : "
                    + column + " and statement : " + stmnt.getRawStatement()
                    + " used by a DB mediator against DataSource : " + getDSName()
                    + " (see java.sql.Types for valid type values)";
            handleException(msg, msgCtx);
        }
        }
    }

    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Successfully prepared statement : " + stmnt.getRawStatement()
                + " against DataSource : " + getDSName());
    }
    return ps;
}

From source file:org.rti.zcore.dar.transfer.access.ImportMshData.java

/**
 * Creates Current Health Record./*from   www  .  ja  va 2  s. com*/
 * @param conn
 * @param siteId
 * @param mshPatientMaster
 * @return
 * @throws NumberFormatException
 * @throws Exception
 */
private static EncounterData createCurrentHealthRecord(Connection conn, Long siteId,
        MshPatientMaster mshPatientMaster) throws NumberFormatException, Exception {
    Form formDef = null;
    Long formId = (Long) DynaSiteObjects.getFormNameMap().get("PatientCondition");
    formDef = (Form) DynaSiteObjects.getForms().get(new Long(formId));
    PatientCondition formData = new PatientCondition();
    formData.setSiteId(siteId);
    formData.setCreatedBy("zepadmin");
    formData.setFlowId(formDef.getFlowId());
    formData.setFormId(formId);
    formData.setPatientId(mshPatientMaster.getPatientId());
    formData.setSessionPatient(mshPatientMaster.getSessionPatient());
    formData.setEvent(mshPatientMaster.getEvent());
    formData.setEventId(mshPatientMaster.getEventId());
    formData.setEventUuid(mshPatientMaster.getEventUuid());

    Integer dateOffset = mshPatientMaster.getDaysToNextAppointment();
    Date dateVisit = null;
    Date initialvisit = DateUtils.toDateSql(mshPatientMaster.getDateTherapyStarted());
    if ((mshPatientMaster.getDateOfNextAppointment() != null) && (dateOffset != null)) {
        Date dateNextAppt = DateUtils.toDateSql(mshPatientMaster.getDateOfNextAppointment());
        String datePastVisitStr = DateUtils.createFutureDate(dateNextAppt, 0 - dateOffset);
        Date datePastVisit = Date.valueOf(datePastVisitStr);
        if (datePastVisit.getTime() > initialvisit.getTime()) {
            dateVisit = datePastVisit;
        } else {
            dateVisit = initialvisit;
        }
    } else {
        dateVisit = initialvisit;
    }
    formData.setDateVisit(dateVisit);
    if (dateVisit != null) {
        Timestamp ts = new Timestamp(dateVisit.getTime());
        formData.setCreated(ts);
        formData.setLastModified(ts);
    }
    formData.setWeight(mshPatientMaster.getCurrentWeight());
    formData.setHeight(mshPatientMaster.getCurrentHeight());
    if (mshPatientMaster.getTB() == 1) {
        formData.setTb_status(3297); //Under treatment
    } else if (mshPatientMaster.getNoTB() == 1) {
        formData.setTb_status(3296); // None
    }
    StringBuffer sbuf = new StringBuffer();
    if (mshPatientMaster.getCotrimoxazole() == 1) {
        sbuf.append("Taking Cotrimoxazole. ");
    }
    if (mshPatientMaster.getNoCotrimoxazole() == 1) {
        sbuf.append("Not taking Cotrimoxazole. ");
    }
    formData.setOi_indications(sbuf.toString());

    EncounterData enc = FormDAO.create(conn, formData, formData.getCreatedBy(), formData.getSiteId(), formDef,
            formData.getFlowId(), null);
    return enc;
}

From source file:org.apache.hadoop.hive.ql.exec.vector.RandomRowObjectSource.java

public static Date getRandDate(Random r) {
    String dateStr = String.format("%d-%02d-%02d", Integer.valueOf(1800 + r.nextInt(500)), // year
            Integer.valueOf(1 + r.nextInt(12)), // month
            Integer.valueOf(1 + r.nextInt(28))); // day
    Date dateVal = Date.valueOf(dateStr);
    return dateVal;
}

From source file:org.openurp.thesis.service.impl.CnkiThesisCheckServiceImpl.java

/**
 * ?//ww  w .  ja  va2  s.co  m
 * 
 * @param text
 * @return
 */
protected List<CheckResult> extract(String text) {
    Matcher m = checkPattern.matcher(text);
    List<CheckResult> results = new ArrayList<CheckResult>();
    // [2]id:value="id"
    // [5]article:<a>article</a>
    // [8]author:<a>author</a>
    // [11]content:<div title="?">0%</div><div title="??">0</div>
    // [14]date
    // [17]downloadurl:<a target="_blank"
    // href=" http://checkdownload.cnki.net/thesisdownload/?downType=0&user=yourname&userServerID=1&fileID=fileId&check=5f6cad62f7fa352955321bc1b4989912"
    // >
    while (m.find()) {
        String content = m.group(11);
        long id = Long.valueOf(StringUtils.substringBetween(m.group(2), "value=\"", "\""));
        String thesis = StringUtils.substringBetween(m.group(5), ">", "</a>");
        String author = StringUtils.substringBetween(m.group(8), ">", "</a>");
        if (content.contains("?")) {
            String ratioStr = StringUtils.substringBetween(content, "?\">", "%</div>");
            float ratio = Float.valueOf(ratioStr) / 100;
            int count = Integer.valueOf(StringUtils.substringBetween(content, "??\">", "</div>"));
            Date checkOn = Date.valueOf(m.group(14).trim());
            String checksum = StringUtils.substringBetween(m.group(17), "check=", "\"");
            results.add(new CheckResult(id, thesis, author, checksum, checkOn, ratio, count));
        } else {
            Date checkOn = Date.valueOf(m.group(14).trim());
            String checksum = StringUtils.substringBetween(m.group(17), "check=", "\"");
            results.add(new CheckResult(id, thesis, author, checksum, checkOn));
        }

    }
    return results;
}

From source file:idgs.IdgsDriver.java

@SuppressWarnings("unchecked")
@Override//from   ww w . j  a v  a2 s  . c om
public boolean getResults(@SuppressWarnings("rawtypes") List result)
        throws IOException, CommandNeedRetryException {
    int maxRows = 100;
    try {
        maxRows = (Integer) maxRowsField.get(this);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    ResultSet resultSet = getResultSet();
    if (resultSet == null) {
        return super.getResults(result);
    }

    List<RowData> results = resultSet.getResults(maxRows);
    if (results == null) {
        return false;
    }

    List<FieldSchema> fieldSchemas = getSchema().getFieldSchemas();
    for (RowData rowData : results) {
        Object[] row = new Object[fieldSchemas.size()];

        for (int i = 0; i < fieldSchemas.size(); ++i) {
            FieldSchema schema = fieldSchemas.get(i);
            Object value = rowData.getFieldValue(schema.getName());
            row[i] = null;

            if (value != null) {
                String type = schema.getType();
                if (type.equalsIgnoreCase("smallint")) {
                    if (value instanceof Integer) {
                        row[i] = ((Integer) value).shortValue();
                    }
                    row[i] = Short.valueOf(value.toString());
                } else if (type.equalsIgnoreCase("tinyint")) {
                    if (value instanceof Integer) {
                        row[i] = ((Integer) value).byteValue();
                    }
                } else if (type.equalsIgnoreCase("binary")) {
                    if (value instanceof String) {
                        row[i] = ((String) value).getBytes();
                    }
                } else if (type.equalsIgnoreCase("timestamp")) {
                    if (value instanceof String) {
                        try {
                            row[i] = Timestamp.valueOf((String) value);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                } else if (type.equalsIgnoreCase("date")) {
                    if (value instanceof String) {
                        try {
                            row[i] = Date.valueOf((String) value);
                        } catch (Exception e) {
                        }
                    }
                } else {
                    row[i] = value;
                }
            }
        }

        result.add(row);
    }

    return true;
}

From source file:mondrian.spi.impl.JdbcDialectImpl.java

public void quoteDateLiteral(StringBuilder buf, String value) {
    // NOTE jvs 1-Jan-2007: Check that the supplied literal is in valid
    // SQL:2003 date format.  A hack in
    // RolapSchemaReader.lookupMemberChildByName looks for
    // NumberFormatException to suppress it, so that is why
    // we convert the exception here.
    final Date date;
    try {/*from ww  w.  j ava  2s  . co  m*/
        date = Date.valueOf(value);
    } catch (IllegalArgumentException ex) {
        throw new NumberFormatException("Illegal DATE literal:  " + value);
    }
    quoteDateLiteral(buf, value, date);
}