Search in sources :

Example 36 with Timestamp

use of java.sql.Timestamp in project OpenAttestation by OpenAttestation.

the class CertificateRepository method search.

@Override
public //    @RequiresPermissions("tag_certificates:search") 
CertificateCollection search(CertificateFilterCriteria criteria) {
    log.debug("Certificate:Search - Got request to search for the Certificates.");
    CertificateCollection objCollection = new CertificateCollection();
    try (JooqContainer jc = TagJdbi.jooq()) {
        DSLContext jooq = jc.getDslContext();
        SelectQuery sql = jooq.select().from(MW_TAG_CERTIFICATE).getQuery();
        if (criteria.filter) {
            if (criteria.id != null) {
                // when uuid is stored in database as the standard UUID string format (36 chars)
                sql.addConditions(MW_TAG_CERTIFICATE.ID.equalIgnoreCase(criteria.id.toString()));
            }
            if (criteria.subjectEqualTo != null && criteria.subjectEqualTo.length() > 0) {
                sql.addConditions(MW_TAG_CERTIFICATE.SUBJECT.equalIgnoreCase(criteria.subjectEqualTo));
            }
            if (criteria.subjectContains != null && criteria.subjectContains.length() > 0) {
                sql.addConditions(MW_TAG_CERTIFICATE.SUBJECT.lower().contains(criteria.subjectContains.toLowerCase()));
            }
            if (criteria.issuerEqualTo != null && criteria.issuerEqualTo.length() > 0) {
                sql.addConditions(MW_TAG_CERTIFICATE.ISSUER.equalIgnoreCase(criteria.issuerEqualTo));
            }
            if (criteria.issuerContains != null && criteria.issuerContains.length() > 0) {
                sql.addConditions(MW_TAG_CERTIFICATE.ISSUER.lower().contains(criteria.issuerContains.toLowerCase()));
            }
            if (criteria.sha1 != null) {
                sql.addConditions(MW_TAG_CERTIFICATE.SHA1.equalIgnoreCase(criteria.sha1.toHexString()));
            }
            if (criteria.sha256 != null) {
                sql.addConditions(MW_TAG_CERTIFICATE.SHA256.equalIgnoreCase(criteria.sha256.toHexString()));
            }
            if (criteria.validOn != null) {
                sql.addConditions(MW_TAG_CERTIFICATE.NOTBEFORE.lessOrEqual(new Timestamp(criteria.validOn.getTime())));
                sql.addConditions(MW_TAG_CERTIFICATE.NOTAFTER.greaterOrEqual(new Timestamp(criteria.validOn.getTime())));
            }
            if (criteria.validBefore != null) {
                sql.addConditions(MW_TAG_CERTIFICATE.NOTAFTER.greaterOrEqual(new Timestamp(criteria.validBefore.getTime())));
            }
            if (criteria.validAfter != null) {
                sql.addConditions(MW_TAG_CERTIFICATE.NOTBEFORE.lessOrEqual(new Timestamp(criteria.validAfter.getTime())));
            }
            if (criteria.revoked != null) {
                sql.addConditions(MW_TAG_CERTIFICATE.REVOKED.equal(criteria.revoked));
            }
        }
        sql.addOrderBy(MW_TAG_CERTIFICATE.SUBJECT);
        Result<Record> result = sql.fetch();
        log.debug("Got {} records", result.size());
        for (Record r : result) {
            Certificate certObj = new Certificate();
            try {
                certObj.setId(UUID.valueOf(r.getValue(MW_TAG_CERTIFICATE.ID)));
                // unlike other table queries, here we can get all the info from the certificate itself... except for the revoked flag
                certObj.setCertificate((byte[]) r.getValue(MW_TAG_CERTIFICATE.CERTIFICATE));
                certObj.setIssuer(r.getValue(MW_TAG_CERTIFICATE.ISSUER));
                certObj.setSubject(r.getValue(MW_TAG_CERTIFICATE.SUBJECT));
                certObj.setNotBefore(r.getValue(MW_TAG_CERTIFICATE.NOTBEFORE));
                certObj.setNotAfter(r.getValue(MW_TAG_CERTIFICATE.NOTAFTER));
                certObj.setSha1(Sha1Digest.valueOf(r.getValue(MW_TAG_CERTIFICATE.SHA1)));
                certObj.setSha256(Sha256Digest.valueOf(r.getValue(MW_TAG_CERTIFICATE.SHA256)));
                certObj.setRevoked(r.getValue(MW_TAG_CERTIFICATE.REVOKED));
                log.debug("Certificate:Search - Created certificate record in search result {}", certObj.getId().toString());
                objCollection.getCertificates().add(certObj);
            } catch (Exception e) {
                log.error("Certificate:Search - Cannot load certificate #{}", r.getValue(MW_TAG_CERTIFICATE.ID), e);
            }
        }
        sql.close();
    } catch (Exception ex) {
        log.error("Certificate:Search - Error during certificate search.", ex);
        throw new RepositorySearchException(ex, criteria);
    }
    log.debug("Certificate:Search - Returning back {} of results.", objCollection.getCertificates().size());
    return objCollection;
}
Also used : SelectQuery(org.jooq.SelectQuery) JooqContainer(com.intel.mtwilson.jooq.util.JooqContainer) CertificateCollection(com.intel.mtwilson.datatypes.CertificateCollection) DSLContext(org.jooq.DSLContext) Record(org.jooq.Record) RepositorySearchException(com.intel.mtwilson.tag.repository.RepositorySearchException) Timestamp(java.sql.Timestamp) RepositoryCreateException(com.intel.mtwilson.tag.repository.RepositoryCreateException) RepositoryDeleteException(com.intel.mtwilson.tag.repository.RepositoryDeleteException) RepositoryStoreException(com.intel.mtwilson.tag.repository.RepositoryStoreException) RepositoryStoreConflictException(com.intel.mtwilson.tag.repository.RepositoryStoreConflictException) RepositoryRetrieveException(com.intel.mtwilson.tag.repository.RepositoryRetrieveException) RepositoryException(com.intel.mtwilson.tag.repository.RepositoryException) RepositorySearchException(com.intel.mtwilson.tag.repository.RepositorySearchException) RepositoryCreateConflictException(com.intel.mtwilson.tag.repository.RepositoryCreateConflictException) Certificate(com.intel.mtwilson.datatypes.Certificate) X509AttributeCertificate(com.intel.mtwilson.datatypes.X509AttributeCertificate)

Example 37 with Timestamp

use of java.sql.Timestamp in project pinot by linkedin.

the class JobManagerImpl method deleteRecordsOlderThanDaysWithStatus.

@Override
@Transactional
public int deleteRecordsOlderThanDaysWithStatus(int days, JobStatus status) {
    DateTime expireDate = new DateTime().minusDays(days);
    Timestamp expireTimestamp = new Timestamp(expireDate.getMillis());
    Predicate statusPredicate = Predicate.EQ("status", status.toString());
    Predicate timestampPredicate = Predicate.LT("updateTime", expireTimestamp);
    List<JobBean> list = genericPojoDao.get(Predicate.AND(statusPredicate, timestampPredicate), JobBean.class);
    for (JobBean jobBean : list) {
        deleteById(jobBean.getId());
    }
    return list.size();
}
Also used : JobBean(com.linkedin.thirdeye.datalayer.pojo.JobBean) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate) Transactional(com.google.inject.persist.Transactional)

Example 38 with Timestamp

use of java.sql.Timestamp in project hibernate-orm by hibernate.

the class DbVersionTest method testCollectionVersion.

@Test
public void testCollectionVersion() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User steve = new User("steve");
    s.persist(steve);
    Group admin = new Group("admin");
    s.persist(admin);
    t.commit();
    s.close();
    Timestamp steveTimestamp = steve.getTimestamp();
    // For dialects (Oracle8 for example) which do not return "true
    // timestamps" sleep for a bit to allow the db date-time increment...
    Thread.sleep(1500);
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.class, steve.getId());
    admin = (Group) s.get(Group.class, admin.getId());
    steve.getGroups().add(admin);
    admin.getUsers().add(steve);
    t.commit();
    s.close();
    assertFalse("owner version not incremented", StandardBasicTypes.TIMESTAMP.isEqual(steveTimestamp, steve.getTimestamp()));
    steveTimestamp = steve.getTimestamp();
    Thread.sleep(1500);
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.class, steve.getId());
    steve.getGroups().clear();
    t.commit();
    s.close();
    assertFalse("owner version not incremented", StandardBasicTypes.TIMESTAMP.isEqual(steveTimestamp, steve.getTimestamp()));
    s = openSession();
    t = s.beginTransaction();
    s.delete(s.load(User.class, steve.getId()));
    s.delete(s.load(Group.class, admin.getId()));
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Timestamp(java.sql.Timestamp) Session(org.hibernate.Session) Test(org.junit.Test)

Example 39 with Timestamp

use of java.sql.Timestamp in project hibernate-orm by hibernate.

the class DbVersionTest method testCollectionNoVersion.

@Test
public void testCollectionNoVersion() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    User steve = new User("steve");
    s.persist(steve);
    Permission perm = new Permission("silly", "user", "rw");
    s.persist(perm);
    t.commit();
    s.close();
    Timestamp steveTimestamp = steve.getTimestamp();
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.class, steve.getId());
    perm = (Permission) s.get(Permission.class, perm.getId());
    steve.getPermissions().add(perm);
    t.commit();
    s.close();
    assertTrue("owner version was incremented", StandardBasicTypes.TIMESTAMP.isEqual(steveTimestamp, steve.getTimestamp()));
    s = openSession();
    t = s.beginTransaction();
    steve = (User) s.get(User.class, steve.getId());
    steve.getPermissions().clear();
    t.commit();
    s.close();
    assertTrue("owner version was incremented", StandardBasicTypes.TIMESTAMP.isEqual(steveTimestamp, steve.getTimestamp()));
    s = openSession();
    t = s.beginTransaction();
    s.delete(s.load(User.class, steve.getId()));
    s.delete(s.load(Permission.class, perm.getId()));
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Timestamp(java.sql.Timestamp) Session(org.hibernate.Session) Test(org.junit.Test)

Example 40 with Timestamp

use of java.sql.Timestamp in project Openfire by igniterealtime.

the class SessionEntry method getLast_activityAsDate.

public Date getLast_activityAsDate() {
    Timestamp stamp = new Timestamp(last_activity);
    Date date = new Date(stamp.getTime());
    return date;
}
Also used : Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

Timestamp (java.sql.Timestamp)3153 Test (org.junit.Test)526 Date (java.util.Date)458 PreparedStatement (java.sql.PreparedStatement)450 SQLException (java.sql.SQLException)367 ResultSet (java.sql.ResultSet)353 BigDecimal (java.math.BigDecimal)351 ArrayList (java.util.ArrayList)236 Date (java.sql.Date)218 Connection (java.sql.Connection)216 HashMap (java.util.HashMap)201 GenericValue (org.apache.ofbiz.entity.GenericValue)194 Calendar (java.util.Calendar)184 Time (java.sql.Time)173 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)167 Delegator (org.apache.ofbiz.entity.Delegator)157 SimpleDateFormat (java.text.SimpleDateFormat)150 IOException (java.io.IOException)129 Locale (java.util.Locale)129 Map (java.util.Map)111