set audit informations, doesn't modify createdDate and createdBy once set.
Only works with DomainObjects that implement the Auditable interface. In other cases
a IllegalArgumentException is thrown.

@param entity
@return
162410
@PreUpdate
    @PrePersist
    private void changeAuditInformation(Auditable auditableEntity) {
        Timestamp lastUpdated = new Timestamp(System.currentTimeMillis());
        auditableEntity.setLastUpdated(lastUpdated);
        String lastUpdatedBy = ServiceContextStore.getCurrentUser();
        auditableEntity.setLastUpdatedBy(lastUpdatedBy);
        if (auditableEntity.getCreatedDate() == null)
            auditableEntity.setCreatedDate(lastUpdated);
        if (auditableEntity.getCreatedBy() == null)
            auditableEntity.setCreatedBy(lastUpdatedBy);
    }
145710
@Override
	public void update(Object entity) {
		if (entity == null) {
			throw new IllegalArgumentException("'entity' must not be [" + entity + "]");
		}
		
		assertTransactional();
		List<Log> logs = transaction.get().logs();
		
		if (logs.isEmpty()) {
			throw new IllegalStateException("Log ["
					+ Log.Operation.UPDATE
					+ "] is not allowed: previous operation must be ["
					+ Log.Operation.GET + "]");
		}
		
		for (int i = logs.size() - 1; i >= 0; i--) {
			Log log = logs.get(i);
			
			if (keyValue(entity).equals(keyValue(log.entity()))) {
				if (log.operation() == Log.Operation.GET) {
					break;
				} else {
					throw new IllegalStateException("Log [" + log.operation() 
							+ "] -> [" + Log.Operation.UPDATE
							+ "] is not allowed: previous operation must be ["
							+ Log.Operation.GET + "]");
				}
			}
		}
		
		Transaction tx = transaction.get().transaction();
		datastore.put(tx, Translation.toEntities(entity));
		Log log = new Log(logs.size() + 1, Log.Operation.UPDATE, entity);
		log.state(State.UNCOMMITTED);
		logs.add(log);
	}
1299077
public static AuditEntryBean clientRegistered(ClientVersionBean bean,
            ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(bean.getClient().getOrganization().getId(), AuditEntityType.Client, securityContext);
        entry.setEntityId(bean.getClient().getId());
        entry.setEntityVersion(bean.getVersion());
        entry.setWhat(AuditEntryType.Register);
        return entry;
    }
149961
public static AuditEntryBean apiUpdated(ApiBean bean, EntityUpdatedData data,
            ISecurityContext securityContext) {
        if (data.getChanges().isEmpty()) {
            return null;
        }
        AuditEntryBean entry = newEntry(bean.getOrganization().getId(), AuditEntityType.Api, securityContext);
        entry.setEntityId(bean.getId());
        entry.setEntityVersion(null);
        entry.setWhat(AuditEntryType.Update);
        entry.setData(toJSON(data));
        return entry;
    }
602523
public boolean deleteEntity(Entity entity) {
        String entityName = entity.getName();
        checkEntityIsEmpty(entityName);
        QueryPart<Entity> queryPart = new Query<Entity>("entities")
                .path(entityName, true);
        return httpClientManager.updateMetaData(queryPart, delete());
    }
337477
public T update(T entity) throws RowNotFoundException, OptimisticLockException {

        if (!hasPrimaryKey(entity)) {
            throw new RuntimeException(String.format("Tried to update entity of type %s without a primary key", entity
                    .getClass().getSimpleName()));
        }

        UpdateCreator update = new UpdateCreator(table);

        update.whereEquals(idColumn.getColumnName(), getPrimaryKey(entity));

        if (versionColumn != null) {
            update.set(versionColumn.getColumnName() + " = " + versionColumn.getColumnName() + " + 1");
            update.whereEquals(versionColumn.getColumnName(), getVersion(entity));
        }

        for (Column column : columns) {
            if (!column.isReadOnly()) {
                update.setValue(column.getColumnName(), getFieldValueAsColumn(entity, column));
            }
        }

        int rows = new JdbcTemplate(ormConfig.getDataSource()).update(update);

        if (rows == 1) {

            if (versionColumn != null) {
                ReflectionUtils.setFieldValue(entity, versionColumn.getFieldName(), getVersion(entity) + 1);
            }

            return entity;

        } else if (rows > 1) {

            throw new RuntimeException(
                    String.format("Updating table %s with id %s updated %d rows. There must be a mapping problem. Is column %s really the primary key?",
                            table, getPrimaryKey(entity), rows, idColumn));

        } else {

            //
            // Updated zero rows. This could be because our ID is wrong, or
            // because our object is out-of date. Let's try querying just by ID.
            //

            SelectCreator selectById = new SelectCreator()
            .column("count(*)")
            .from(table)
            .whereEquals(idColumn.getColumnName(), getPrimaryKey(entity));

            rows = new JdbcTemplate(ormConfig.getDataSource()).query(selectById, new ResultSetExtractor<Integer>() {
                @Override
                public Integer extractData(ResultSet rs) throws SQLException, DataAccessException {
                    rs.next();
                    return rs.getInt(1);
                }
            });

            if (rows == 0) {
                throw new RowNotFoundException(table, getPrimaryKey(entity));
            } else {
                throw new OptimisticLockException(table, getPrimaryKey(entity));
            }
        }
    }
834704
public boolean updateEntity(Entity entity) {
        String entityName = entity.getName();
        checkEntityIsEmpty(entityName);
        QueryPart<Entity> queryPart = new Query<Entity>("entities")
                .path(entityName, true);
        return httpClientManager.updateMetaData(queryPart, patch(entity));
    }
970817
@SuppressWarnings("unchecked")
	public <T> T save(T entity) {
		if (entity == null) {
			throw new ApitraryOrmException("Cannot persist null entity");
		}
		log.debug("Saving " + entity.getClass());

		PostRequest request = new PostRequest();
		request.setEntity(resolveApitraryEntity(entity));

		String payload = marshall(entity);

		request.setRequestPayload(payload);

		PostResponse response = resolveApitraryClient().send(request);

		if (HttpStatus.Created.ordinal() == response.getStatusCode()) {
			return (T) new PostResponseUnmarshaller().unMarshall(response, entity);
		} else {
			throw new ApitraryOrmException(response.getResult());
		}
	}
310742
public static Lock toLock(Entity entity) {
		return new Lock(entity.getKey().getName(), 
				(String) entity.getProperty(TRANSACTION_PROPERTY), 
				(Date) entity.getProperty(TIMESTAMP_PROPERTY));
	}
964994
public List<Audit> getAllNotifications(JPAEntity entity) {
		return _auditService.findByEntityHostnameMessage(entity.getId(), null, "Triggering event value:");
	}
423838
public DBObject toDBObject(final Object entity) {
        try {
            return mapper.toDBObject(entity);
        } catch (Exception e) {
            throw new MappingException("Could not map entity to DBObject", e);
        }
    }
1248933
private static AuditEntryBean newEntry(String orgId, AuditEntityType type, ISecurityContext securityContext) {
        // Wait for 1 ms to guarantee that two audit entries are never created at the same moment in time (which would
        // result in non-deterministic sorting by the storage layer)
        try { Thread.sleep(1); } catch (InterruptedException e) { throw new RuntimeException(e); }

        AuditEntryBean entry = new AuditEntryBean();
        entry.setOrganizationId(orgId);
        entry.setEntityType(type);
        entry.setCreatedOn(new Date());
        entry.setWho(securityContext.getCurrentUser());
        return entry;
    }
392175
public static EntitySet getEntitySetByEntity(EntityDataModel entityDataModel, Object entity)
            throws ODataEdmException {
        return getEntitySetByEntityTypeName(entityDataModel,
                getAndCheckEntityType(entityDataModel, entity.getClass()).getFullyQualifiedName());
    }
204935
@Override
    @SuppressWarnings("unchecked")
    public PlainDate apply(PlainDate entity) {

        ChronoOperator<PlainDate> operator = (ChronoOperator<PlainDate>) this.opDelegate;
        return operator.apply(entity);

    }
885622
@Override
	public void put(Object entity) {
		if (entity == null) {
			throw new IllegalArgumentException("'entity' must not be [" + entity + "]");
		}
		
		if (operation != null) {
			throw new IllegalStateException("Log [" + operation + "] -> ["
					+ Log.Operation.PUT
					+ "] is not allowed: This operation must be first");
		}
		
		Key id = Keys.create(Translation.toKind(entity.getClass()), Entities.keyValue(entity));
		Entity e = datastore.get(local, id);
		
		if (e != null) {
			throw new EntityExistsException(id);
		}
		
		this.entity = entity;
		operation = Log.Operation.PUT;
	}
433313
public static AuditEntryBean apiPublished(ApiVersionBean bean,
            ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(bean.getApi().getOrganization().getId(), AuditEntityType.Api, securityContext);
        entry.setEntityId(bean.getApi().getId());
        entry.setEntityVersion(bean.getVersion());
        entry.setWhat(AuditEntryType.Publish);
        return entry;
    }
313913
public CroquetRestBuilder<T> addJpaEntity(final Class<? extends Serializable> entity) {
        // check to ensure the class has the @Entity annotation
        if(entity.getAnnotation(Entity.class) == null) {
            throw new IllegalArgumentException("Only classes marked with @Entity can be added");
        }

        settings.getDatabaseSettings().addEntity(entity);
        return this;
    }