Example usage for org.joda.time LocalDateTime fromDateFields

List of usage examples for org.joda.time LocalDateTime fromDateFields

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static LocalDateTime fromDateFields(Date date) 

Source Link

Document

Constructs a LocalDateTime from a java.util.Date using exactly the same field values.

Usage

From source file:energy.usef.core.model.PlanboardMessage.java

License:Apache License

public LocalDateTime getCreationDateTime() {
    if (creationDateTime == null) {
        return null;
    }//  ww  w . j  a  v a2 s  .c o  m
    return LocalDateTime.fromDateFields(creationDateTime);
}

From source file:graphene.util.time.JodaTimeUtil.java

License:Apache License

public static LocalDateTime toLocalDateTime(final java.sql.Timestamp ts) {
    // TODO - confirm this conversion always works, esp. across timezones
    final LocalDateTime ldt = (ts == null ? null : LocalDateTime.fromDateFields(ts));
    return ldt;/*from  www.j  av a 2 s. c o  m*/
}

From source file:graphene.util.time.JodaTimeUtil.java

License:Apache License

public static LocalDateTime toLocalDateTime(final java.util.Date d) {
    // TODO - confirm this conversion always works, esp. across timezones
    final LocalDateTime ldt = (d == null ? null : LocalDateTime.fromDateFields(d));
    return ldt;//  w  w w. ja  v  a 2  s  .  co m
}

From source file:griffon.plugins.jodatime.editors.LocalDateTimePropertyEditor.java

License:Apache License

protected void setValueInternal(Object value) {
    if (null == value) {
        super.setValueInternal(null);
    } else if (value instanceof LocalDateTime) {
        super.setValueInternal(value);
    } else if (value instanceof LocalDate) {
        super.setValueInternal(((LocalDate) value).toDateTimeAtStartOfDay());
    } else if (value instanceof LocalTime) {
        super.setValueInternal(((LocalTime) value).toDateTimeToday());
    } else if (value instanceof DateMidnight) {
        super.setValueInternal(((DateMidnight) value).toDateTime().toLocalDateTime());
    } else if (value instanceof CharSequence) {
        handleAsString(String.valueOf(value));
    } else if (value instanceof Calendar) {
        super.setValueInternal(LocalDateTime.fromCalendarFields((Calendar) value));
    } else if (value instanceof Date) {
        super.setValueInternal(LocalDateTime.fromDateFields((Date) value));
    } else if (value instanceof Number) {
        super.setValueInternal(new LocalDateTime(((Number) value).longValue()));
    } else {//  www  .  j  av  a  2s  .  c  o  m
        throw illegalValue(value, LocalDateTime.class);
    }
}

From source file:org.apache.sqoop.connector.hbase.HbaseExtractor.java

License:Apache License

@Override
public void extract(ExtractorContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig,
        GenericJdbcPartition partition) {
    HbaseExecutor executor = new HbaseExecutor(linkConfig.linkConfig);

    String query = context.getString(HbaseConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL);
    String conditions = partition.getConditions();
    query = query.replace(HbaseConnectorConstants.SQL_CONDITIONS_TOKEN, conditions);
    LOG.info("Using query: " + query);

    rowsRead = 0;/* w w  w.j  av a  2  s .  c  om*/
    ResultSet resultSet = executor.executeQuery(query);

    Schema schema = context.getSchema();
    Column[] schemaColumns = schema.getColumnsArray();
    try {
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();
        if (schemaColumns.length != columnCount) {
            throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0021,
                    schemaColumns.length + ":" + columnCount);
        }
        while (resultSet.next()) {
            Object[] array = new Object[columnCount];
            for (int i = 0; i < columnCount; i++) {
                if (resultSet.getObject(i + 1) == null) {
                    array[i] = null;
                    continue;
                }
                // check type of the column
                Column schemaColumn = schemaColumns[i];
                switch (schemaColumn.getType()) {
                case DATE:
                    // convert the sql date to JODA time as prescribed the Sqoop IDF spec
                    array[i] = LocalDate.fromDateFields((java.sql.Date) resultSet.getObject(i + 1));
                    break;
                case DATE_TIME:
                    // convert the sql date time to JODA time as prescribed the Sqoop IDF spec
                    array[i] = LocalDateTime.fromDateFields((java.sql.Timestamp) resultSet.getObject(i + 1));
                    break;
                case TIME:
                    // convert the sql time to JODA time as prescribed the Sqoop IDF spec
                    array[i] = LocalTime.fromDateFields((java.sql.Time) resultSet.getObject(i + 1));
                    break;
                default:
                    //for anything else
                    array[i] = resultSet.getObject(i + 1);

                }
            }
            context.getDataWriter().writeArrayRecord(array);
            rowsRead++;
        }
    } catch (SQLException e) {
        throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0004, e);

    } finally {
        executor.close();
    }
}

From source file:org.apache.sqoop.connector.jdbc.GenericJdbcExtractor.java

License:Apache License

@Override
public void extract(ExtractorContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig,
        GenericJdbcPartition partition) {
    GenericJdbcExecutor executor = new GenericJdbcExecutor(linkConfig.linkConfig);

    String query = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL);
    String conditions = partition.getConditions();
    query = query.replace(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN, conditions);
    LOG.info("Using query: " + query);

    rowsRead = 0;//ww  w  .  java  2  s. c  om
    ResultSet resultSet = executor.executeQuery(query);

    Schema schema = context.getSchema();
    Column[] schemaColumns = schema.getColumnsArray();
    try {
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();
        if (schemaColumns.length != columnCount) {
            throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0021,
                    schemaColumns.length + ":" + columnCount);
        }
        while (resultSet.next()) {
            Object[] array = new Object[columnCount];
            for (int i = 0; i < columnCount; i++) {
                if (resultSet.getObject(i + 1) == null) {
                    array[i] = null;
                    continue;
                }
                // check type of the column
                Column schemaColumn = schemaColumns[i];
                switch (schemaColumn.getType()) {
                case DATE:
                    // convert the sql date to JODA time as prescribed the Sqoop IDF spec
                    array[i] = LocalDate.fromDateFields((java.sql.Date) resultSet.getObject(i + 1));
                    break;
                case DATE_TIME:
                    // convert the sql date time to JODA time as prescribed the Sqoop IDF spec
                    array[i] = LocalDateTime.fromDateFields((java.sql.Timestamp) resultSet.getObject(i + 1));
                    break;
                case TIME:
                    // convert the sql time to JODA time as prescribed the Sqoop IDF spec
                    array[i] = LocalTime.fromDateFields((java.sql.Time) resultSet.getObject(i + 1));
                    break;
                default:
                    //for anything else
                    array[i] = resultSet.getObject(i + 1);

                }
            }
            context.getDataWriter().writeArrayRecord(array);
            rowsRead++;
        }
    } catch (SQLException e) {
        throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0004, e);

    } finally {
        executor.close();
    }
}

From source file:org.apache.sqoop.connector.jdbc.oracle.OracleJdbcExtractor.java

License:Apache License

private Object getObjectAtName(ResultSet resultSet, OracleTableColumn column, Column sqoopColumn)
        throws SQLException {
    Object result = null;/*from  www . ja v  a  2  s.c om*/
    if (sqoopColumn.getType() == ColumnType.TEXT) {
        result = resultSet.getString(column.getName());
    } else if (column.getOracleType() == OracleQueries.getOracleType("TIMESTAMP")) {
        Timestamp timestamp = resultSet.getTimestamp(column.getName());
        if (timestamp != null) {
            result = LocalDateTime.fromDateFields(timestamp);
        }
    } else if (column.getOracleType() == OracleQueries.getOracleType("TIMESTAMPTZ")
            || column.getOracleType() == OracleQueries.getOracleType("TIMESTAMPLTZ")) {
        Timestamp timestamp = resultSet.getTimestamp(column.getName());
        if (timestamp != null) {
            //TODO: BC dates
            String dateTimeStr = resultSet.getString(column.getName());
            result = DateTime.parse(dateTimeStr, TIMESTAMP_TIMEZONE);
        }
    } else {
        result = resultSet.getObject(column.getName());
    }
    return result;
}

From source file:org.codehaus.mojo.unix.deb.DpkgDebTool.java

License:Open Source License

private static List<UnixFsObject> process(InputStream is) throws IOException {
    TarArchiveInputStream tarInputStream = new TarArchiveInputStream(is);

    List<UnixFsObject> objects = new ArrayList<UnixFsObject>();

    TarArchiveEntry entry = (TarArchiveEntry) tarInputStream.getNextEntry();

    while (entry != null) {
        Option<UnixFileMode> mode = some(UnixFileMode.fromInt(entry.getMode()));
        FileAttributes attributes = new FileAttributes(some(entry.getUserName()), some(entry.getGroupName()),
                mode);/*from   w w  w  .j  a va 2s  .c  o m*/
        RelativePath path = relativePath(entry.getName());
        LocalDateTime lastModified = LocalDateTime.fromDateFields(entry.getModTime());

        UnixFsObject object;

        if (entry.isDirectory()) {
            object = directory(path, lastModified, attributes);
        } else if (entry.isSymbolicLink()) {
            object = symlink(path, lastModified, some(entry.getUserName()), some(entry.getGroupName()),
                    entry.getLinkName());
        } else if (entry.isFile()) {
            object = regularFile(path, lastModified, entry.getSize(), attributes);
        } else {
            throw new IOException("Unsupported link type: name=" + entry.getName());
        }

        objects.add(object);

        entry = (TarArchiveEntry) tarInputStream.getNextEntry();
    }

    return objects;
}

From source file:org.devgateway.eudevfin.ui.common.models.DateToLocalDateTimeModel.java

License:Open Source License

@Override
public void setObject(Date object) {
    if (object == null)
        originalModel.setObject(null);//from w  w w  . j  a  v a2  s.c o  m
    else
        originalModel.setObject(LocalDateTime.fromDateFields(object));
}

From source file:org.jtwig.functions.builtin.DateFunctions.java

License:Apache License

@JtwigFunction(name = "date_modify")
public Date modifyDate(@Parameter Date input, @Parameter String modifyString) throws FunctionException {
    return modify(modifyString, LocalDateTime.fromDateFields(input));
}