Example usage for javax.persistence TemporalType TIMESTAMP

List of usage examples for javax.persistence TemporalType TIMESTAMP

Introduction

In this page you can find the example usage for javax.persistence TemporalType TIMESTAMP.

Prototype

TemporalType TIMESTAMP

To view the source code for javax.persistence TemporalType TIMESTAMP.

Click Source Link

Document

Map as java.sql.Timestamp

Usage

From source file:org.syncope.core.util.ImportExport.java

private void setParameters(final String tableName, final Attributes atts, final Query query) {

    Map<String, Integer> colTypes = new HashMap<String, Integer>();

    Connection conn = DataSourceUtils.getConnection(dataSource);
    ResultSet rs = null;/*from w ww .j  a v  a  2  s  .c o m*/
    Statement stmt = null;
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT * FROM " + tableName);
        for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
            colTypes.put(rs.getMetaData().getColumnName(i + 1).toUpperCase(),
                    rs.getMetaData().getColumnType(i + 1));
        }
    } catch (SQLException e) {
        LOG.error("While", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                LOG.error("While closing statement", e);
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.error("While closing result set", e);
            }
        }
        DataSourceUtils.releaseConnection(conn, dataSource);
    }

    for (int i = 0; i < atts.getLength(); i++) {
        Integer colType = colTypes.get(atts.getQName(i).toUpperCase());
        if (colType == null) {
            LOG.warn("No column type found for {}", atts.getQName(i).toUpperCase());
            colType = Types.VARCHAR;
        }

        switch (colType) {
        case Types.NUMERIC:
        case Types.REAL:
        case Types.INTEGER:
        case Types.TINYINT:
            try {
                query.setParameter(i + 1, Integer.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Integer '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DECIMAL:
        case Types.BIGINT:
            try {
                query.setParameter(i + 1, Long.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Long '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DOUBLE:
            try {
                query.setParameter(i + 1, Double.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Double '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.FLOAT:
            try {
                query.setParameter(i + 1, Float.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Float '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            try {
                query.setParameter(i + 1, DateUtils.parseDate(atts.getValue(i), SyncopeConstants.DATE_PATTERNS),
                        TemporalType.TIMESTAMP);
            } catch (ParseException e) {
                LOG.error("Unparsable Date '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            query.setParameter(i + 1, "1".equals(atts.getValue(i)) ? Boolean.TRUE : Boolean.FALSE);
            break;

        default:
            query.setParameter(i + 1, atts.getValue(i));
        }
    }
}

From source file:org.syncope.core.persistence.dao.impl.UserSearchDAOImpl.java

private void fillWithParameters(final Query query, final List<Object> parameters) {

    for (int i = 0; i < parameters.size(); i++) {
        if (parameters.get(i) instanceof Date) {
            query.setParameter(i + 1, (Date) parameters.get(i), TemporalType.TIMESTAMP);
        } else if (parameters.get(i) instanceof Boolean) {
            query.setParameter(i + 1, ((Boolean) parameters.get(i)) ? 1 : 0);
        } else {//from   www .ja  v  a2  s  . c om
            query.setParameter(i + 1, parameters.get(i));
        }
    }
}

From source file:org.opennms.netmgt.model.OnmsIpInterface.java

/**
 * <p>getIpLastCapsdPoll</p>
 *
 * @return a {@link java.util.Date} object.
 *//* w ww.ja v  a2 s .c  om*/
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "ipLastCapsdPoll")
@XmlElement(name = "lastCapsdPoll")
public Date getIpLastCapsdPoll() {
    return m_ipLastCapsdPoll;
}

From source file:com.infinities.skyport.compute.entity.Disk.java

@Override
@Column(name = "CREATIONDATE")
@Temporal(TemporalType.TIMESTAMP)
public Date getCreationdate() {
    return creationdate;
}

From source file:com.doculibre.constellio.entities.RecordCollection.java

@Temporal(TemporalType.TIMESTAMP)
public Date getLastIndexingDate() {
    return lastIndexingDate;
}

From source file:org.apache.syncope.core.util.ImportExport.java

private void setParameters(final String tableName, final Attributes attrs, final Query query) {

    Map<String, Integer> colTypes = new HashMap<String, Integer>();

    final Table table = getTable(tableName);

    for (int i = 0; i < attrs.getLength(); i++) {
        Integer colType = table.getColumn(QualifiedDBIdentifier.newColumn(attrs.getQName(i))).getType();
        if (colType == null) {
            LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase());
            colType = Types.VARCHAR;
        }/*w  ww  .ja v  a  2 s . c  om*/

        switch (colType) {
        case Types.INTEGER:
        case Types.TINYINT:
        case Types.SMALLINT:
            try {
                query.setParameter(i + 1, Integer.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Integer '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.NUMERIC:
        case Types.DECIMAL:
        case Types.BIGINT:
            try {
                query.setParameter(i + 1, Long.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Long '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.DOUBLE:
            try {
                query.setParameter(i + 1, Double.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Double '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.REAL:
        case Types.FLOAT:
            try {
                query.setParameter(i + 1, Float.valueOf(attrs.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Float '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            try {
                query.setParameter(i + 1,
                        DateUtils.parseDate(attrs.getValue(i), SyncopeConstants.DATE_PATTERNS),
                        TemporalType.TIMESTAMP);
            } catch (ParseException e) {
                LOG.error("Unparsable Date '{}'", attrs.getValue(i));
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            query.setParameter(i + 1, "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE);
            break;

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            try {
                query.setParameter(i + 1, Hex.decode(attrs.getValue(i)));
            } catch (IllegalArgumentException e) {
                query.setParameter(i + 1, attrs.getValue(i));
            }
            break;

        case Types.BLOB:
            try {
                query.setParameter(i + 1, Hex.decode(attrs.getValue(i)));
            } catch (IllegalArgumentException e) {
                LOG.warn("Error decoding hex string to specify a blob parameter", e);
                query.setParameter(i + 1, attrs.getValue(i));
            } catch (Exception e) {
                LOG.warn("Error creating a new blob parameter", e);
            }
            break;

        default:
            query.setParameter(i + 1, attrs.getValue(i));
        }
    }
}

From source file:gov.nih.nci.caarray.domain.sample.AbstractBioMaterial.java

/**
 * @return the date when the data of this sample was last modified.
 *///from  w  ww  . j  a  va2s  .com
@Temporal(TemporalType.TIMESTAMP)
public Date getLastModifiedDataTime() {
    return this.lastModifiedDataTime;
}

From source file:org.apache.syncope.core.persistence.dao.impl.UserDAOImpl.java

@Override
public List<SyncopeUser> findByAttrValue(final String schemaName, final UAttrValue attrValue) {

    USchema schema = schemaDAO.find(schemaName, USchema.class);
    if (schema == null) {
        LOG.error("Invalid schema name '{}'", schemaName);
        return Collections.emptyList();
    }//from  w  ww . j a  v  a  2 s  .c  om

    final String entityName = schema.isUniqueConstraint() ? UAttrUniqueValue.class.getName()
            : UAttrValue.class.getName();

    Query query = entityManager
            .createQuery("SELECT e FROM " + entityName + " e" + " WHERE e.attribute.schema.name = :schemaName "
                    + " AND (e.stringValue IS NOT NULL" + " AND e.stringValue = :stringValue)"
                    + " OR (e.booleanValue IS NOT NULL" + " AND e.booleanValue = :booleanValue)"
                    + " OR (e.dateValue IS NOT NULL" + " AND e.dateValue = :dateValue)"
                    + " OR (e.longValue IS NOT NULL" + " AND e.longValue = :longValue)"
                    + " OR (e.doubleValue IS NOT NULL" + " AND e.doubleValue = :doubleValue)");

    query.setParameter("schemaName", schemaName);
    query.setParameter("stringValue", attrValue.getStringValue());
    query.setParameter("booleanValue", attrValue.getBooleanValue() == null ? null
            : attrValue.getBooleanAsInteger(attrValue.getBooleanValue()));
    if (attrValue.getDateValue() != null) {
        query.setParameter("dateValue", attrValue.getDateValue(), TemporalType.TIMESTAMP);
    } else {
        query.setParameter("dateValue", null);
    }
    query.setParameter("longValue", attrValue.getLongValue());
    query.setParameter("doubleValue", attrValue.getDoubleValue());

    List<SyncopeUser> result = new ArrayList<SyncopeUser>();
    SyncopeUser user;
    for (AbstractAttrValue value : (List<AbstractAttrValue>) query.getResultList()) {

        user = (SyncopeUser) value.getAttribute().getOwner();
        if (!result.contains(user)) {
            result.add(user);
        }
    }

    return result;
}

From source file:gov.nih.nci.cabig.caaers.domain.report.ReportVersion.java

/**
 * Gets the created on.
 *
 * @return the created on
 */
@Temporal(value = TemporalType.TIMESTAMP)
public Date getCreatedOn() {
    return createdOn;
}

From source file:com.syncnapsis.data.model.User.java

/**
 * Datum der Registrierung/*  www .ja  va2 s .  c om*/
 * 
 * @return registrationDate
 */
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
public Date getRegistrationDate() {
    return registrationDate;
}