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.apache.syncope.core.persistence.jpa.dao.AbstractSubjectDAO.java

@Override
@SuppressWarnings("unchecked")
public List<? extends Subject<P, D, V>> findByAttrValue(final String schemaName, final PlainAttrValue attrValue,
        final AttributableUtil attrUtil) {

    PlainSchema schema = plainSchemaDAO.find(schemaName, attrUtil.plainSchemaClass());
    if (schema == null) {
        LOG.error("Invalid schema name '{}'", schemaName);
        return Collections.<Subject<P, D, V>>emptyList();
    }//w  w  w  .j  a v a  2 s .  c o  m

    final String entityName = schema.isUniqueConstraint() ? attrUtil.plainAttrUniqueValueClass().getName()
            : attrUtil.plainAttrValueClass().getName();

    Query query = findByAttrValueQuery(entityName);

    query.setParameter("schemaName", schemaName);
    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<Subject<P, D, V>> result = new ArrayList<>();
    for (PlainAttrValue value : (List<PlainAttrValue>) query.getResultList()) {
        Subject<P, D, V> subject = (Subject<P, D, V>) value.getAttr().getOwner();
        if (!result.contains(subject)) {
            result.add(subject);
        }
    }

    return result;
}

From source file:org.batoo.jpa.core.impl.criteria.QueryImpl.java

/**
 * {@inheritDoc}//from w  ww  . ja  v  a2  s . c  o  m
 * 
 */
@Override
public TypedQuery<X> setParameter(String name, Object value) {
    if (value instanceof Date) {
        return this.setParameter(name, (Date) value, TemporalType.TIMESTAMP);
    }
    if (value instanceof Calendar) {
        return this.setParameter(name, (Calendar) value, TemporalType.TIMESTAMP);
    }

    return this.putParam(this.getParameter(name), value);
}

From source file:org.batoo.jpa.core.impl.model.attribute.BasicAttribute.java

/**
 * Constructor for version attributes.//w w w  .ja  v  a2s  .c  o m
 * 
 * @param declaringType
 *            the declaring type
 * @param metadata
 *            the metadata
 * 
 * @since 2.0.0
 */
public BasicAttribute(IdentifiableTypeImpl<X> declaringType, VersionAttributeMetadata metadata) {
    super(declaringType, metadata);

    this.version = true;
    this.optional = false;
    this.idType = null;
    this.generator = null;
    this.lob = false;
    this.enumType = null;
    this.index = null;
    this.columnTransformer = null;

    this.type = this.getDeclaringType().getMetamodel().createBasicType(this.getJavaType());

    if (this.getJavaType() == Timestamp.class) {
        this.temporalType = TemporalType.TIMESTAMP;
    } else if (this.getJavaType() == java.sql.Date.class) {
        this.temporalType = TemporalType.DATE;
    } else if (this.getJavaType() == java.sql.Time.class) {
        this.temporalType = TemporalType.TIME;
    } else if ((this.getJavaType() == Date.class) || (this.getJavaType() == Calendar.class)) {
        this.temporalType = metadata.getTemporalType() != null ? metadata.getTemporalType()
                : TemporalType.TIMESTAMP;
    } else {
        this.temporalType = null;
    }
}

From source file:org.batoo.jpa.core.impl.model.attribute.BasicAttribute.java

/**
 * Constructor for basic attributes.// w ww . j a v  a2  s.c  om
 * 
 * @param declaringType
 *            the declaring type
 * @param metadata
 *            the metadata
 * 
 * @since 2.0.0
 */
public BasicAttribute(ManagedTypeImpl<X> declaringType, BasicAttributeMetadata metadata) {
    super(declaringType, metadata);

    this.version = false;
    this.idType = null;
    this.generator = null;

    this.type = this.getDeclaringType().getMetamodel().createBasicType(this.getJavaType());
    this.optional = metadata.isOptional();
    this.index = metadata.getIndex();
    this.columnTransformer = metadata.getColumnTransformer();

    if (Date.class.isAssignableFrom(this.getJavaType())
            || Calendar.class.isAssignableFrom(this.getJavaType())) {
        if (metadata.getTemporalType() == null) {
            this.temporalType = TemporalType.TIMESTAMP;
        } else {
            this.temporalType = metadata.getTemporalType();
        }
    } else {
        this.temporalType = null;
    }

    if (this.getJavaType().getSuperclass() == Enum.class) {
        if (metadata.getEnumType() != null) {
            this.enumType = metadata.getEnumType();
        } else {
            this.enumType = EnumType.ORDINAL;
        }
    } else {
        this.enumType = null;
    }

    this.lob = this.inferLobType(metadata.isLob());
}

From source file:org.bonitasoft.engine.bdm.CodeGeneratorTest.java

@Test
public void shouldGenerate_CreatePojoFile() throws Exception {
    final JDefinedClass definedClass = codeGenerator.addClass("org.bonitasoft.Entity");
    final JFieldVar nameField = codeGenerator.addField(definedClass, "name", String.class);

    final JClass stringList = codeGenerator.getModel().ref(List.class).narrow(String.class);
    final JClass booleanList = codeGenerator.getModel().ref(List.class).narrow(Boolean.class);
    final JClass booleanField = codeGenerator.getModel().ref(Boolean.class);

    final JFieldVar booleanMultipleField = codeGenerator.addField(definedClass, "bools", booleanList);
    final JFieldVar booleanSingleField = codeGenerator.addField(definedClass, "bool", booleanField);

    final JFieldVar skillField = codeGenerator.addField(definedClass, "skills", stringList);
    final JFieldVar dateField = codeGenerator.addField(definedClass, "returnDate",
            codeGenerator.getModel().ref(Date.class));
    final JAnnotationUse tAnnotation = codeGenerator.addAnnotation(dateField, Temporal.class);
    tAnnotation.param("value", TemporalType.TIMESTAMP);

    codeGenerator.addGetter(definedClass, nameField);
    codeGenerator.addSetter(definedClass, nameField);
    codeGenerator.addAnnotation(definedClass, Entity.class);

    codeGenerator.addGetter(definedClass, skillField);
    codeGenerator.addSetter(definedClass, skillField);

    codeGenerator.addGetter(definedClass, booleanMultipleField);
    codeGenerator.addSetter(definedClass, booleanMultipleField);

    codeGenerator.addGetter(definedClass, booleanSingleField);
    codeGenerator.addSetter(definedClass, booleanSingleField);

    final File destDir = createTempDirectory("generatedPojo");
    try {/*from   ww w.j  a va  2s . c  o m*/
        codeGenerator.generate(destDir);
        final File rootFolder = new File(destDir, "org" + File.separatorChar + "bonitasoft");
        assertThat(rootFolder.listFiles()).isNotEmpty().contains(new File(rootFolder, "Entity.java"));
    } finally {
        FileUtils.deleteQuietly(destDir);
    }
}

From source file:org.eclipse.jubula.client.core.model.TestResultPO.java

/**
 * //  w  w w  .  j  a v a 2 s  .  c  o m
 * @return the timestamp
 */
@Basic
@Column(name = "TIMESTAMP")
@Temporal(value = TemporalType.TIMESTAMP)
public Date getTimestamp() {
    return m_timestamp;
}

From source file:org.kalypso.model.wspm.pdb.db.mapping.DhmIndex.java

@Override
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "creation_date", nullable = false, length = 22)
public Date getCreationDate() {
    return m_creationDate;
}

From source file:org.kalypso.model.wspm.pdb.db.mapping.DhmIndex.java

@Override
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "editing_date", nullable = false, length = 22)
public Date getEditingDate() {
    return m_editingDate;
}

From source file:org.kalypso.model.wspm.pdb.db.mapping.DhmIndex.java

@Override
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "measurement_date", length = 22)
public Date getMeasurementDate() {
    return m_measurementDate;
}

From source file:org.nuxeo.ecm.activity.ActivityImpl.java

@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
@Override
public Date getPublishedDate() {
    return publishedDate;
}