Convert a value from Google representation to a Java value
@param entity the persistent {@link Entity} from the google datastore
420158
public <T> T datastoreToJava(Entity entity) {
		try {
			if (entity == null) {
				return null;
			}
			T result = (T) persistentClass.newInstance();
			populate(entity, result);
			return result;
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}
1051242
@Override
    public T apply(T entity) {

        switch (this.mode) {
            case NEW_VALUE_MODE:
                return value(entity, this.element, this.value, false);
            case MIN_MODE:
                return min(entity, this.element);
            case MAX_MODE:
                return max(entity, this.element);
            case FLOOR_MODE:
                return floor(entity, this.element);
            case CEILING_MODE:
                return ceiling(entity, this.element);
            case LENIENT_MODE:
                return value(entity, this.element, this.value, true);
            case DECREMENTING_MODE:
                return this.move(entity, false);
            case INCREMENTING_MODE:
                return this.move(entity, true);
            default:
                throw new UnsupportedOperationException(
                    "Unknown mode: " + this.mode);
        }

    }
1276170
@Override
	public void update(Object entity) {
		if (entity == null) {
			throw new IllegalArgumentException("'entity' must not be [" + entity + "]");
		}
		
		if (operation != Log.Operation.GET) {
			throw new IllegalStateException("Log [" + operation + "] -> ["
					+ Log.Operation.UPDATE
					+ "] is not allowed: previous operation must be ["
					+ Log.Operation.GET + "]");
		}
		
		operation = Log.Operation.UPDATE;
	}
1060259
private static void setFieldValue(Object entity, Attribute column, JsonElement value)
    {
        if (column.getJavaType().isAssignableFrom(byte[].class))
        {
            PropertyAccessorHelper.set(entity, (Field) column.getJavaMember(),
                    PropertyAccessorFactory.STRING.toBytes(value.getAsString()));
        }
        else
        {
            PropertyAccessorHelper.set(
                    entity,
                    (Field) column.getJavaMember(),
                    PropertyAccessorHelper.fromSourceToTargetClass(column.getJavaType(), String.class,
                            value.getAsString()));
        }
    }
173258
@SuppressWarnings("unchecked")
    public Object convertToEntity(Class entityType, String id, ObjectNode document) {
        try {
            if (ObjectNode.class.equals(entityType)) {
                return document;
            }

            Object defaultValue = InMemoryDocumentSessionOperations.getDefaultValue(entityType);
            Object entity = defaultValue;

            String documentType =_session.getConventions().getJavaClass(id, document);
            if (documentType != null) {
                Class type = Class.forName(documentType);
                if (entityType.isAssignableFrom(type)) {
                    entity = _session.getConventions().getEntityMapper().treeToValue(document, type);
                }
            }

            if (entity == defaultValue) {
                entity = _session.getConventions().getEntityMapper().treeToValue(document, entityType);
            }

            if (id != null) {
                _session.getGenerateEntityIdOnTheClient().trySetIdentity(entity, id);
            }

            return entity;
        } catch (Exception e) {
            throw new IllegalStateException("Could not convert document " + id + " to entity of type " + entityType.getName(), e);
        }
    }
1168636
public void populate(Entity entity) {
    // auto date
    generateAutoDateOrDateTime(singletonList(entity), entity.getEntityType().getAttributes());

    // auto id
    Attribute idAttr = entity.getEntityType().getIdAttribute();
    if (idAttr != null
        && idAttr.isAuto()
        && entity.getIdValue() == null
        && (idAttr.getDataType() == STRING)) {
      entity.set(idAttr.getName(), idGenerator.generateId());
    }
  }
947472
@Post("json")
    public final Representation postLogMessage(final Representation entity) {
        try {
            LOGGER.debug("postLogMessage: Log {}", entity.getText());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return handleLogRequest(entity);
    }
597223
private static void validateEntity(Entity entity) throws DbRuntimeException {
		if (null == entity) {
			throw new DbRuntimeException("Entity is null !");
		}
		if (StrUtil.isBlank(entity.getTableName())) {
			throw new DbRuntimeException("Entity`s table name is null !");
		}
		if (entity.isEmpty()) {
			throw new DbRuntimeException("No filed and value in this entity !");
		}
	}
493067
public void put(Entity entity) {
    int bytesHere = EntityTranslator.convertToPb(entity).getSerializedSize();

    // Do this before the add so that we guarantee that size is never > sizeLimit
    if (putsBytes + bytesHere >= params.getBytesLimit()) {
      flushPuts();
    }

    putsBytes += bytesHere;
    puts.add(entity);

    if (puts.size() >= params.getCountLimit()) {
      flushPuts();
    }
  }
243038
public static String generateEntityQualifiedName(SQLiteDaoDefinition dao, SQLiteEntity entity) {
		String entityName;
		if (entity == null) {
			M2MEntity m2mEntity = M2MEntity.extractEntityManagedByDAO(dao.getElement());
			entityName = m2mEntity.getQualifiedName();
		} else {
			entityName = entity.getName().toString();
		}
		return entityName;
	}
777509
protected Object transformEntity(Entity entity) {
		PropertyColumn propertyColumn = (PropertyColumn) entity;
		JRDesignField field = new JRDesignField();
		ColumnProperty columnProperty = propertyColumn.getColumnProperty();
		field.setName(columnProperty.getProperty());
		field.setValueClassName(columnProperty.getValueClassName());
		
		log.debug("Transforming column: " + propertyColumn.getName() + ", property: " + columnProperty.getProperty() + " (" + columnProperty.getValueClassName() +") " );

		field.setDescription(propertyColumn.getFieldDescription()); //hack for XML data source
		for (String key : columnProperty.getFieldProperties().keySet()) {
			field.getPropertiesMap().setProperty(key, columnProperty.getFieldProperties().get(key));
		}
		return field;
	}
907489
@Override
    public void persist(Object entity)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "em.persist(" + entity + ");\n" + toString());

        getEMInvocationInfo(true).persist(entity);
    }
324383
@Override
    public T apply(T entity) {

        double value = entity.get(this.element).doubleValue();
        double nv;

        if (this.up == null) {
            double high = Math.ceil(value / this.stepwidth) * this.stepwidth;
            double low = Math.floor(value / this.stepwidth) * this.stepwidth;
            nv = ((value - low < high - value) ? low : high);
        } else if (this.up.booleanValue()) {
            nv = Math.ceil(value / this.stepwidth) * this.stepwidth;
        } else {
            nv = Math.floor(value / this.stepwidth) * this.stepwidth;
        }

        Number num;

        if (this.longBased) {
            num = Long.valueOf((long) nv);
        } else {
            num = Integer.valueOf((int) nv);
        }

        return entity.with(lenient(this.element, num));

    }
999767
public void validateConstraints(Entity entity) {
		for (String propertyName : requiredProperties) {
            Object value = entity.getProperty(propertyName);
			if (value == null || (value instanceof String && ((String) value).length() == 0)) {
				throw new RequiredFieldException("Required property '" + this.persistentClass.getSimpleName() + "." + propertyName + "' is not set");
			}
		}
	}
800544
public void put(Entity entity) {
    EntityType entityType = entity.getEntityType();
    cache.put(
        EntityKey.create(entityType, entity.getIdValue()),
        CacheHit.of(entityHydration.dehydrate(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());
		}
	}
851160
protected Object transformEntity(Entity entity) throws JRException {
		//log.debug("transforming group...");
		DJGroup djgroup = (DJGroup) entity;
		PropertyColumn column = djgroup.getColumnToGroupBy();
		JRDesignGroup group = new JRDesignGroup();


		group.setName(djgroup.getName());
		
		getLayoutManager().getReferencesMap().put(group.getName(), djgroup);

		group.setCountVariable(new JRDesignVariable());

        JRDesignSection gfs = (JRDesignSection) group.getGroupFooterSection();
        gfs.getBandsList().add(new JRDesignBand());


        JRDesignSection ghs = (JRDesignSection) group.getGroupHeaderSection();
        ghs.getBandsList().add(new JRDesignBand());

		JRDesignExpression jrExpression = new JRDesignExpression();
		
		CustomExpression expressionToGroupBy = column.getExpressionToGroupBy();
		
		if (expressionToGroupBy != null) { //new in 3.0.7-b5
			useVariableForCustomExpression(group, jrExpression, expressionToGroupBy);
			
		} else {
			if (column instanceof ExpressionColumn){
				ExpressionColumn col = (ExpressionColumn)column;
				CustomExpression customExpression = col.getExpression();
				useVariableForCustomExpression(group, jrExpression, customExpression);
			} else {
				jrExpression.setText(column.getTextForExpression());
				jrExpression.setValueClassName(column.getValueClassNameForExpression());
			}
		}
		

		group.setExpression(jrExpression);

		return group;
	}