List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:org.apache.hadoop.hive.metastore.ObjectStore.java
private String createDbGuidAndPersist() throws MetaException { boolean success = false; Query query = null;/*from w ww. j ava2s .c o m*/ try { openTransaction(); MMetastoreDBProperties prop = new MMetastoreDBProperties(); prop.setPropertykey("guid"); final String guid = UUID.randomUUID().toString(); LOG.debug("Attempting to add a guid " + guid + " for the metastore db"); prop.setPropertyValue(guid); prop.setDescription("Metastore DB GUID generated on " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))); pm.makePersistent(prop); success = commitTransaction(); if (success) { LOG.info("Metastore db guid " + guid + " created successfully"); return guid; } } catch (Exception e) { LOG.warn(e.getMessage(), e); } finally { rollbackAndCleanup(success, query); } // it possible that some other HMS instance could have created the guid // at the same time due which this instance could not create a guid above // in such case return the guid already generated final String guid = getGuidFromDB(); if (guid == null) { throw new MetaException("Unable to create or fetch the metastore database uuid"); } return guid; }
From source file:org.cgiar.ccafs.marlo.action.BaseAction.java
/** * Common logic for setting the Modification Justification * // w ww. j a va 2 s . c o m * @param entity */ protected void setModificationJustification(MarloAuditableEntity entity) { /** * Hibernate will not save unchanged entities, so having the localDateTime ensures a unique entry is created each * save. */ if (StringUtils.isEmpty(this.justification)) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd,yyyy HH:mm"); entity.setModificationJustification( "No justification provided at : " + LocalDateTime.now().format(formatter)); } else if (this.justification.equals(entity.getModificationJustification())) { /** * We have the same justification text as before - which can lead to the entity not being saved if no other fields * have been saved. Add a * character to ensure that they are different. */ entity.setModificationJustification(this.justification + "*"); } else { entity.setModificationJustification(this.justification); } }