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.opennms.netmgt.model.OnmsEvent.java

/**
 * <p>getEventAckTime</p>/*w  w  w  .j  a  va2  s .c o m*/
 *
 * @return a {@link java.util.Date} object.
 */
@XmlElement(name = "ackTime")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "eventAckTime")
public Date getEventAckTime() {
    return m_eventAckTime;
}

From source file:com.mmnaseri.dragonfly.metadata.impl.AnnotationTableMetadataResolver.java

private static int getColumnType(Class<?> javaType, Method method, ColumnMetadata foreignReference) {
    final int dimensions = ReflectionUtils.getArrayDimensions(javaType);
    javaType = ReflectionUtils.mapType(ReflectionUtils.getComponentType(javaType));
    if (dimensions > 1) {
        throw new UnsupportedColumnTypeError("Arrays of dimension > 1 are not supported");
    }/*from  www  .  ja va  2  s .c  o m*/
    if (Byte.class.equals(javaType) && dimensions == 0) {
        return Types.TINYINT;
    } else if (Short.class.equals(javaType)) {
        return Types.SMALLINT;
    } else if (Integer.class.equals(javaType)) {
        return Types.INTEGER;
    } else if (Long.class.equals(javaType)) {
        return Types.BIGINT;
    } else if (Float.class.equals(javaType)) {
        return Types.FLOAT;
    } else if (Double.class.equals(javaType)) {
        return Types.DOUBLE;
    } else if (BigDecimal.class.equals(javaType)) {
        return Types.DECIMAL;
    } else if (BigInteger.class.equals(javaType)) {
        return Types.NUMERIC;
    } else if (Character.class.equals(javaType)) {
        return Types.CHAR;
    } else if (String.class.equals(javaType) || Class.class.equals(javaType)) {
        if (method != null && method.isAnnotationPresent(Column.class)
                && method.getAnnotation(Column.class).length() > 0) {
            return Types.VARCHAR;
        } else {
            return Types.LONGVARCHAR;
        }
    } else if (Date.class.isAssignableFrom(javaType)) {
        if (javaType.equals(java.sql.Date.class)) {
            return Types.DATE;
        } else if (javaType.equals(Time.class)) {
            return Types.TIME;
        } else if (javaType.equals(java.sql.Timestamp.class)) {
            return Types.TIMESTAMP;
        }
        final TemporalType temporalType = method != null && method.isAnnotationPresent(Temporal.class)
                ? method.getAnnotation(Temporal.class).value()
                : null;
        return (temporalType == null || temporalType.equals(TemporalType.TIMESTAMP)) ? Types.TIMESTAMP
                : (temporalType.equals(TemporalType.DATE) ? Types.DATE : Types.TIME);
    } else if (Byte.class.equals(javaType) && dimensions > 0) {
        return Types.VARBINARY;
    } else if (Enum.class.isAssignableFrom(javaType)) {
        return Types.VARCHAR;
    } else if (Boolean.class.equals(javaType)) {
        return Types.BOOLEAN;
    } else if (Collection.class.isAssignableFrom(javaType)
            && method.isAnnotationPresent(BasicCollection.class)) {
        return Types.LONGVARCHAR;
    }
    if (foreignReference != null) {
        return Integer.MIN_VALUE;
    }
    return Types.LONGVARCHAR;
}

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

/**
 * Gets the graded date, aka the awareness date.
 *
 * @return the graded date//from   w  w w.j a  v  a 2 s  .c o  m
 */
@Temporal(TemporalType.TIMESTAMP)
@NotNullConstraint(groups = AdverseEventGroup.class, fieldPath = "adverseEvents[].gradedDate")
public Date getGradedDate() {
    return gradedDate;
}

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

/**
 * Gets the post submission updated date.
 *
 * @return the post submission updated date
 *//*from  w  w w . ja  v  a2 s  .c o  m*/
@Temporal(TemporalType.TIMESTAMP)
public Date getPostSubmissionUpdatedDate() {
    return postSubmissionUpdatedDate;
}

From source file:ca.uhn.fhir.jpa.dao.BaseFhirResourceDao.java

@Override
public IBundleProvider history(final IdDt theId, final Date theSince) {
    final InstantDt end = createHistoryToTimestamp();
    final String resourceType = getContext().getResourceDefinition(myResourceType).getName();

    T currentTmp;//from   w  w w .j  a  v  a  2  s  .  c o  m
    try {
        BaseHasResource entity = readEntity(theId.toVersionless(), false);
        validateResourceType(entity);
        currentTmp = toResource(myResourceType, entity);
        if (ResourceMetadataKeyEnum.UPDATED.get(currentTmp).after(end.getValue())) {
            currentTmp = null;
        }
    } catch (ResourceNotFoundException e) {
        currentTmp = null;
    }

    final T current = currentTmp;

    String querySring = "SELECT count(h) FROM ResourceHistoryTable h "
            + "WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE" + " AND h.myUpdated < :END"
            + (theSince != null ? " AND h.myUpdated >= :SINCE" : "");
    TypedQuery<Long> countQuery = myEntityManager.createQuery(querySring, Long.class);
    countQuery.setParameter("PID", translateForcedIdToPid(theId));
    countQuery.setParameter("RESTYPE", resourceType);
    countQuery.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
    if (theSince != null) {
        countQuery.setParameter("SINCE", theSince, TemporalType.TIMESTAMP);
    }
    int historyCount = countQuery.getSingleResult().intValue();

    final int offset;
    final int count;
    if (current != null) {
        count = historyCount + 1;
        offset = 1;
    } else {
        offset = 0;
        count = historyCount;
    }

    if (count == 0) {
        throw new ResourceNotFoundException(theId);
    }

    return new IBundleProvider() {

        @Override
        public InstantDt getPublished() {
            return end;
        }

        @Override
        public List<IResource> getResources(int theFromIndex, int theToIndex) {
            ArrayList<IResource> retVal = new ArrayList<IResource>();
            if (theFromIndex == 0 && current != null) {
                retVal.add(current);
            }

            TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery(
                    "SELECT h FROM ResourceHistoryTable h WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE AND h.myUpdated < :END "
                            + (theSince != null ? " AND h.myUpdated >= :SINCE" : "")
                            + " ORDER BY h.myUpdated ASC",
                    ResourceHistoryTable.class);
            q.setParameter("PID", translateForcedIdToPid(theId));
            q.setParameter("RESTYPE", resourceType);
            q.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
            if (theSince != null) {
                q.setParameter("SINCE", theSince, TemporalType.TIMESTAMP);
            }

            int firstResult = Math.max(0, theFromIndex - offset);
            q.setFirstResult(firstResult);

            int maxResults = (theToIndex - theFromIndex) + 1;
            q.setMaxResults(maxResults);

            List<ResourceHistoryTable> results = q.getResultList();
            for (ResourceHistoryTable next : results) {
                if (retVal.size() == maxResults) {
                    break;
                }
                retVal.add(toResource(myResourceType, next));
            }

            return retVal;
        }

        @Override
        public Integer preferredPageSize() {
            return null;
        }

        @Override
        public int size() {
            return count;
        }
    };

}

From source file:org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingSerializer.java

/**
 * Return field's temporal type./*  w  ww .j  av  a2s .co m*/
 */
private TemporalType getTemporal(FieldMapping field) {
    if (field.getDeclaredTypeCode() != JavaTypes.DATE && field.getDeclaredTypeCode() != JavaTypes.CALENDAR)
        return null;

    DBDictionary dict = ((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance();
    int def = dict.getJDBCType(field.getTypeCode(), false);
    for (Column col : (List<Column>) field.getValueInfo().getColumns()) {
        if (col.getType() == def)
            continue;
        switch (col.getType()) {
        case Types.DATE:
            return TemporalType.DATE;
        case Types.TIME:
            return TemporalType.TIME;
        case Types.TIMESTAMP:
            return TemporalType.TIMESTAMP;
        }
    }
    return null;
}

From source file:org.apache.ranger.audit.entity.AuthzAuditEventDbObj.java

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "event_time")
public Date getTimeStamp() {
    return this.timeStamp;
}

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

@Override
public <T extends AbstractSubject> List<T> findByAttrValue(final String schemaName,
        final AbstractAttrValue attrValue, final AttributableUtil attrUtil) {

    AbstractNormalSchema schema = schemaDAO.find(schemaName, attrUtil.schemaClass());
    if (schema == null) {
        LOG.error("Invalid schema name '{}'", schemaName);
        return Collections.<T>emptyList();
    }//w ww.ja va2s  .  c  o m

    final String entityName = schema.isUniqueConstraint() ? attrUtil.attrUniqueValueClass().getName()
            : attrUtil.attrValueClass().getName();

    TypedQuery<AbstractAttrValue> query = findByAttrValueQuery(entityName);

    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", null);
    } else {
        query.setParameter("dateValue", attrValue.getDateValue(), TemporalType.TIMESTAMP);
    }
    query.setParameter("longValue", attrValue.getLongValue());
    query.setParameter("doubleValue", attrValue.getDoubleValue());

    List<T> result = new ArrayList<T>();
    for (AbstractAttrValue value : query.getResultList()) {
        T subject = value.getAttribute().getOwner();
        if (!result.contains(subject)) {
            result.add(subject);
        }
    }

    return result;
}

From source file:org.apache.syncope.core.persistence.dao.impl.SubjectSearchDAOImpl.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 {/*ww w  . j  ava  2 s .co  m*/
            query.setParameter(i + 1, parameters.get(i));
        }
    }
}

From source file:org.apache.syncope.core.persistence.jpa.dao.AbstractAnyDAO.java

@Override
@SuppressWarnings("unchecked")
public List<A> findByPlainAttrValue(final String schemaKey, final PlainAttrValue attrValue) {
    PlainSchema schema = plainSchemaDAO().find(schemaKey);
    if (schema == null) {
        LOG.error("Invalid schema name '{}'", schemaKey);
        return Collections.<A>emptyList();
    }/* ww w.java  2 s.  c  om*/

    String entityName = schema.isUniqueConstraint() ? anyUtils().plainAttrUniqueValueClass().getName()
            : anyUtils().plainAttrValueClass().getName();
    Query query = findByPlainAttrValueQuery(entityName);
    query.setParameter("schemaKey", schemaKey);
    query.setParameter("stringValue", attrValue.getStringValue());
    query.setParameter("booleanValue", attrValue.getBooleanValue() == null ? null
            : ((AbstractPlainAttrValue) attrValue).getBooleanAsInteger(attrValue.getBooleanValue()));
    if (attrValue.getDateValue() == null) {
        query.setParameter("dateValue", null);
    } else {
        query.setParameter("dateValue", attrValue.getDateValue(), TemporalType.TIMESTAMP);
    }
    query.setParameter("longValue", attrValue.getLongValue());
    query.setParameter("doubleValue", attrValue.getDoubleValue());

    List<A> result = new ArrayList<>();
    ((List<PlainAttrValue>) query.getResultList()).stream().forEach(value -> {
        A any = (A) value.getAttr().getOwner();
        if (!result.contains(any)) {
            result.add(any);
        }
    });

    return result;
}