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;
}
use of java.sql.Timestamp in project druid by alibaba.
the class MySqlMockExecuteHandlerImpl method executeQueryFromDual.
public ResultSet executeQueryFromDual(MockStatementBase statement, SQLSelectQueryBlock query) throws SQLException {
MockResultSet rs = statement.getConnection().getDriver().createMockResultSet(statement);
MockResultSetMetaData metaData = rs.getMockMetaData();
Object[] row = new Object[query.getSelectList().size()];
for (int i = 0, size = query.getSelectList().size(); i < size; ++i) {
ColumnMetaData column = new ColumnMetaData();
SQLSelectItem item = query.getSelectList().get(i);
SQLExpr expr = item.getExpr();
if (expr instanceof SQLIntegerExpr) {
row[i] = ((SQLNumericLiteralExpr) expr).getNumber();
column.setColumnType(Types.INTEGER);
} else if (expr instanceof SQLNumberExpr) {
row[i] = ((SQLNumericLiteralExpr) expr).getNumber();
column.setColumnType(Types.DECIMAL);
} else if (expr instanceof SQLCharExpr) {
row[i] = ((SQLCharExpr) expr).getText();
column.setColumnType(Types.VARCHAR);
} else if (expr instanceof SQLNCharExpr) {
row[i] = ((SQLNCharExpr) expr).getText();
column.setColumnType(Types.NVARCHAR);
} else if (expr instanceof SQLBooleanExpr) {
row[i] = ((SQLBooleanExpr) expr).getValue();
column.setColumnType(Types.NVARCHAR);
} else if (expr instanceof SQLNullExpr) {
row[i] = null;
} else if (expr instanceof SQLMethodInvokeExpr) {
SQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr) expr;
if ("NOW".equalsIgnoreCase(methodInvokeExpr.getMethodName())) {
row[i] = new Timestamp(System.currentTimeMillis());
} else {
throw new SQLException("TODO");
}
} else if (expr instanceof SQLVariantRefExpr) {
SQLVariantRefExpr varExpr = (SQLVariantRefExpr) expr;
int varIndex = varExpr.getIndex();
if (statement instanceof MockPreparedStatement) {
MockPreparedStatement mockPstmt = (MockPreparedStatement) statement;
row[i] = mockPstmt.getParameters().get(varIndex);
} else {
row[i] = null;
}
} else {
row[i] = null;
}
metaData.getColumns().add(column);
}
rs.getRows().add(row);
return rs;
}
use of java.sql.Timestamp in project druid by alibaba.
the class ResultSetProxyImpl method getTimestamp.
@Override
public Timestamp getTimestamp(int columnIndex) throws SQLException {
FilterChainImpl chain = createChain();
Timestamp value = chain.resultSet_getTimestamp(this, columnIndex);
recycleFilterChain(chain);
return value;
}
use of java.sql.Timestamp in project druid by alibaba.
the class ResultSetProxyImpl method getTimestamp.
@Override
public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
FilterChainImpl chain = createChain();
Timestamp value = chain.resultSet_getTimestamp(this, columnIndex, cal);
recycleFilterChain(chain);
return value;
}
use of java.sql.Timestamp in project druid by alibaba.
the class MockExecuteTest method test_2.
public void test_2() throws Exception {
Connection conn = DriverManager.getConnection("jdbc:mock:");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT NOW()");
Assert.assertTrue(rs.next());
Assert.assertTrue(rs.getObject(1) instanceof Timestamp);
rs.close();
stmt.close();
conn.close();
}
Aggregations