List of usage examples for org.joda.time Instant toDate
public Date toDate()
java.util.Date
. From source file:candlelight.joda.converters.JodaInstantConverter.java
License:Apache License
public Date convertToDatabaseColumn(Instant instant) { return instant.toDate(); }
From source file:com.netflix.metacat.main.services.search.ElasticSearchUtilImpl.java
License:Apache License
/** * Search the names by names and by the given marker. * @param type type/* w w w.ja v a2 s. c o m*/ * @param qualifiedNames names * @param marker marker * @param excludeQualifiedNames exclude names * @param valueType dto type * @param <T> dto type * @return dto */ public <T> List<T> getQualifiedNamesByMarkerByNames(final String type, final List<QualifiedName> qualifiedNames, final Instant marker, final List<QualifiedName> excludeQualifiedNames, final Class<T> valueType) { final List<T> result = Lists.newArrayList(); final List<String> names = qualifiedNames.stream().map(QualifiedName::toString) .collect(Collectors.toList()); final List<String> excludeNames = excludeQualifiedNames.stream().map(QualifiedName::toString) .collect(Collectors.toList()); // // Run the query and get the response. final QueryBuilder queryBuilder = QueryBuilders.boolQuery() .must(QueryBuilders.termsQuery("name.qualifiedName.tree", names)) .must(QueryBuilders.termQuery("deleted_", false)) .must(QueryBuilders.rangeQuery("_timestamp").lte(marker.toDate())) .mustNot(QueryBuilders.termsQuery("name.qualifiedName.tree", excludeNames)) .mustNot(QueryBuilders.termQuery("refreshMarker_", marker.toString())); final SearchRequestBuilder request = client.prepareSearch(esIndex).setTypes(type) .setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(queryBuilder).setSize(Integer.MAX_VALUE); final SearchResponse response = request.execute().actionGet(); if (response.getHits().hits().length != 0) { result.addAll(parseResponse(response, valueType)); } return result; }
From source file:com.sojanddesign.boxes.domain.model.user.DomainBoxesUserActivateSteps.java
License:Open Source License
@Given("$email of inactive user account created previously 4 days ago") public void givenEmailOfInactiveUserAccountCreatedPreviouslyFoorDaysAgo(String email) { this.email = email; try {/*from ww w. jav a2 s . c o m*/ User mockUser = new User(new UserId("4")); mockUser.setActive(false); Duration foorDays = Duration.standardDays(4); Instant fourDaysAgo = Instant.now().minus(foorDays); mockUser.setAccountSettings(new AccountSettings(email, null, null, fourDaysAgo.toDate())); when(mockUserRepository.findByEmail(email)).thenReturn(mockUser); } catch (DomainException e) { exception = e; e.printStackTrace(); } }
From source file:com.studium.joda.converters.JodaInstantConverter.java
License:Apache License
public Date convertToDatabaseColumn(Instant instant) { return instant == null ? null : instant.toDate(); }
From source file:com.trifork.stamdata.Fetcher.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Transactional//from www . ja va2 s . co m public <T extends TemporalEntity> T fetch(Instant instant, Class<T> type, Object id) throws SQLException { checkNotNull(instant, "instant"); checkNotNull(type, "type"); checkNotNull(id, "id"); // The database uses open/closed validity intervals: [a;b[ // When a record is 'closed' (no longer valid) its ValidTo // is set to the same value as its ValidFrom. Therefore the // ValidTo must be checked using the '<' operator. String keyColumn = Entities.getIdColumnName(type); String entityName = type.getCanonicalName(); Query query = session.createQuery(format( "FROM %s WHERE %s = :id AND ValidFrom <= :instant AND :instant < ValidTo", entityName, keyColumn)); query.setParameter("id", id); query.setTimestamp("instant", instant.toDate()); // This query should only ever return a single result or the database's // structure has been corrupted. So we want an exception to be thrown. return (T) query.uniqueResult(); }
From source file:com.trifork.stamdata.Fetcher.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Transactional/* www. java 2 s. c o m*/ public <T extends TemporalEntity> List<T> fetch(Instant instant, Class<T> type, String column, Object value, Type sqlType) { checkNotNull(instant, "instant"); checkNotNull(type, "type"); checkNotNull(column, "column"); checkNotNull(value, "value"); String entityName = type.getCanonicalName(); Query query = session.createQuery(format( "FROM %s WHERE %s = :value AND ValidFrom <= :instant AND :instant < ValidTo", entityName, column)); query.setParameter("value", value, sqlType); query.setTimestamp("instant", instant.toDate()); return (List<T>) query.list(); }
From source file:com.trifork.stamdata.Fetcher.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Transactional/*www . j a v a 2 s .c o m*/ public <T extends TemporalEntity> List<T> fetch(Instant instant, Class<T> type, String column, Object value) { checkNotNull(instant, "instant"); checkNotNull(type, "type"); checkNotNull(column, "column"); checkNotNull(value, "value"); String entityName = type.getCanonicalName(); Query query = session.createQuery(format( "FROM %s WHERE %s = :value AND ValidFrom <= :instant AND :instant < ValidTo", entityName, column)); query.setParameter("value", value); query.setTimestamp("instant", instant.toDate()); return (List<T>) query.list(); }
From source file:com.trifork.stamdata.Fetcher.java
License:Mozilla Public License
@SuppressWarnings("unchecked") @Transactional/*from w w w .j a v a 2 s . c o m*/ public <T extends TemporalEntity> List<T> fetch(Instant instant, Class<T> type, Map<String, Object> columnAndValue) { checkNotNull(instant, "instant"); checkNotNull(type, "type"); checkNotNull(columnAndValue, "columnAndValue"); Preconditions.checkArgument(!columnAndValue.isEmpty(), "You must specify a map containing column name -> value pairs"); StringBuffer whereClause = new StringBuffer(); for (String columnName : columnAndValue.keySet()) { if (whereClause.length() > 0) { whereClause.append(" AND "); } whereClause.append(columnName + " = :" + columnName); } whereClause.append(" AND ValidFrom <= :instant AND :instant < ValidTo"); String entityName = type.getCanonicalName(); Query query = session.createQuery(format("FROM %s WHERE " + whereClause.toString(), entityName)); query.setTimestamp("instant", instant.toDate()); // Set remaining variables on query for (String columnName : columnAndValue.keySet()) { query.setParameter(columnName, columnAndValue.get(columnName)); } return (List<T>) query.list(); }
From source file:com.trifork.stamdata.importer.jobs.ImportTimeManager.java
License:Mozilla Public License
public static void setLastImportTime(Class<? extends Parser> parserClass, Instant transactionTime, Connection connection) {/*from www . ja v a 2s .c om*/ String parserId = Parsers.getIdentifier(parserClass); setLastImportTime(parserId, transactionTime.toDate(), connection); }
From source file:de.jpaw.bonaparte.poi.BaseExcelComposer.java
License:Apache License
@Override public void addField(TemporalElementaryDataItem di, Instant t) { if (t != null) { newCell(di, csTimestamp).setCellValue(t.toDate()); } else {/*from w w w. j a va 2 s .c o m*/ writeNull(di); } }