Try to find an asset in the asset cache or create one for this entity.

@param entity asset will be found for.
@return An asset that will exist in the asset cache.
197531
private Asset getAsset(Entity entity) {
        return getAsset(entity.getInstanceKey(), getAssetTypeToken(entity.getClass()));
    }
893674
public static void fill(Object entity) {
        final Class<?> entityClass = entity.getClass();

        if (N.isEntity(entityClass) == false) {
            throw new IllegalArgumentException(entityClass.getCanonicalName() + " is not a valid entity class with property getter/setter method");
        }

        Type<Object> type = null;
        Class<?> parameterClass = null;
        Object propValue = null;

        for (Method method : ClassUtil.getPropSetMethodList(entityClass).values()) {
            parameterClass = method.getParameterTypes()[0];
            type = N.typeOf(parameterClass);

            if (String.class.equals(parameterClass)) {
                propValue = N.uuid().substring(0, 16);
            } else if (boolean.class.equals(parameterClass) || Boolean.class.equals(parameterClass)) {
                propValue = RAND.nextInt() % 2 == 0 ? false : true;
            } else if (char.class.equals(parameterClass) || Character.class.equals(parameterClass)) {
                propValue = (char) ('a' + RAND.nextInt() % 26);
            } else if (int.class.equals(parameterClass) || Integer.class.equals(parameterClass)) {
                propValue = RAND.nextInt();
            } else if (long.class.equals(parameterClass) || Long.class.equals(parameterClass)) {
                propValue = RAND.nextLong();
            } else if (float.class.equals(parameterClass) || Float.class.equals(parameterClass)) {
                propValue = RAND.nextFloat();
            } else if (double.class.equals(parameterClass) || Double.class.equals(parameterClass)) {
                propValue = RAND.nextDouble();
            } else if (byte.class.equals(parameterClass) || Byte.class.equals(parameterClass)) {
                propValue = Integer.valueOf(RAND.nextInt()).byteValue();
            } else if (short.class.equals(parameterClass) || Short.class.equals(parameterClass)) {
                propValue = Integer.valueOf(RAND.nextInt()).shortValue();
            } else if (Number.class.isAssignableFrom(parameterClass)) {
                propValue = type.valueOf(String.valueOf(RAND.nextInt()));
            } else if (java.util.Date.class.isAssignableFrom(parameterClass) || Calendar.class.isAssignableFrom(parameterClass)) {
                propValue = type.valueOf(String.valueOf(System.currentTimeMillis()));
            } else if (N.isEntity(parameterClass)) {
                propValue = fill(parameterClass);
            } else {
                propValue = type.defaultValue();
            }

            ClassUtil.setPropValue(entity, method, propValue);
        }
    }
533406
public ApiResponse createEntity(Entity entity) {
        assertValidApplicationId();
        if (isEmpty(entity.getType())) {
            throw new IllegalArgumentException("Missing entity type");
        }
        ApiResponse response = apiRequest(HttpMethod.POST, null, entity,
                organizationId, applicationId, entity.getType());
        return response;
    }
594281
@Override
    public T update(T entity) {
        EntityManager entityManager = getEntityManager();
        T result = entityManager.merge(entity);
        return result;
    }
400940
private LoadingCache<Object, Optional<Map<String, Object>>> createEntityCache(
      Repository<Entity> repository) {
    Caffeine<Object, Object> cacheBuilder =
        Caffeine.newBuilder().recordStats().expireAfterAccess(10, MINUTES);
    if (!MetaDataService.isMetaEntityType(repository.getEntityType())) {
      cacheBuilder.maximumSize(MAX_CACHE_SIZE_PER_ENTITY);
    }
    LoadingCache<Object, Optional<Map<String, Object>>> cache =
        CaffeinatedGuava.build(cacheBuilder, createCacheLoader(repository));
    GuavaCacheMetrics.monitor(meterRegistry, cache, "l2." + repository.getEntityType().getId());
    return cache;
  }
283544
protected <T> String resolveApitraryEntity(T entity) {
		String entityName = ClassUtil.getClassAnnotationValue(entity.getClass(), Entity.class, "value", String.class);
		if (entityName == null || entityName.isEmpty()) {
			entityName = StringUtil.toVerb(entity.getClass().getSimpleName());
		}
		return entityName;
	}
953664
@SuppressWarnings("unchecked")
    public ModelNode fromEntity(T entity)
    {

        ModelNode operation = new ModelNode();
        List<PropertyBinding> properties = metaData.getBeanMetaData(getType()).getProperties();
        Mutator mutator = metaData.getMutator(getType());

        for(PropertyBinding property : properties)
        {
            String[] splitDetypedName = property.getDetypedName().split("/");

            /**
             * KEYS
             */
            //      if(property.isKey()) continue;

            Object propertyValue = mutator.getValue(entity, property.getJavaName());

            /**
             * EXPRESSIONS
             */
            if(property.doesSupportExpression())
            {
                String exprValue = ExpressionAdapter.getExpressionValue(
                        entity, property.getJavaName()
                );

                if(exprValue!=null)
                {
                    operation.get(splitDetypedName).setExpression(exprValue);
                    continue; // expression have precedence over real values
                }
            }

            /**
             * VALUES
             */
            if(propertyValue!=null)
            {
                try {
                    ModelType modelType = resolveModelType(property.getJavaTypeName());
                    if ((modelType == ModelType.LIST) && (property.getListType() == PropertyBinding.class)) {
                        operation.get(splitDetypedName).set(modelType, property.getEntityAdapterForList().fromEntityPropertyList((List) propertyValue));
                    } else if (modelType == ModelType.LIST) {
                        operation.get(splitDetypedName).set(modelType,
                                property.getEntityAdapterForList().fromEntityList((List) propertyValue));
                    } else if (modelType == ModelType.OBJECT) {
                        // Only Map<String, String> is supported!
                        Map<String, String> map = (Map<String, String>) propertyValue;
                        for (Map.Entry<String, String> entry : map.entrySet()) {
                            operation.get(splitDetypedName).get(entry.getKey()).set(entry.getValue());
                        }
                    } else {
                        operation.get(splitDetypedName).set(modelType, propertyValue);
                    }
                } catch (RuntimeException e) {
                    throw new RuntimeException("Failed to get value "+property.getJavaName(), e);
                }
            }
        }

        return operation;
    }
368540
@Override
  public Entity findOne(Query<Entity> query) {
    if (transactionInformation.isRepositoryCompletelyClean(getEntityType()) && cacheable) {
      // pageSize is irrelevant for findOne, would be a waste to cache them in different entries
      // sort may affect which of the results is the first result, so cannot ignore that.
      QueryImpl<Entity> cacheKey = new QueryImpl<>(query).setPageSize(1);
      List<Object> ids = l3Cache.get(delegate(), cacheKey);
      if (ids.isEmpty()) {
        return null;
      }
      return delegate().findOneById(ids.get(0), query.getFetch());
    }
    return delegate().findOne(query);
  }
15469
function getAsset(key) {
  return new Promise((resolve, reject) => {
    return instance.assets.then(db => {
      const req = db.transaction(db.name)
        .objectStore(db.name).get(key);
      req.onsuccess = event => {
        const undef = event.target.result === undefined;
        const value = undef ? undefined : event.target.result.value;
        resolve(value);
      };
      req.onerror = event => reject(event);
    });
  });
}
6518
public Entity wrap(Entity entity){
		if(null == entity) {
			return null;
		}
		
		final Entity wrapedEntity = new Entity();
		
		//wrap table name
		wrapedEntity.setTableName(wrap(entity.getTableName()));
		
		//wrap fields
		for (Entry<String, Object> entry : entity.entrySet()) {
			wrapedEntity.set(wrap(entry.getKey()), entry.getValue());
		}
		
		return wrapedEntity;
	}
870611
@Override
    public Long get(Entity entity) {
        Objects.requireNonNull(entity, "entity cannot be null");
        // return id()
        return entity.id();
    }
1370411
protected boolean isEmptyEntity(Object entity) {
        return entity == null || (entity instanceof Collection && ((Collection) entity).isEmpty());
    }
1263619
public static boolean isEmpty(Entity<?> entity, boolean ignoreDefault) {
    try {
      for (final String attr : PropertyUtils.getWritableProperties(entity.getClass())) {
        Object value = PropertyUtils.getProperty(entity, attr);
        if (null == value) continue;
        if (ignoreDefault) {
          if (value instanceof Number) {
            if (((Number) value).intValue() != 0) { return false; }
          } else if (value instanceof String) {
            String str = (String) value;
            if (Strings.isNotEmpty(str)) { return false; }
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
    } catch (Exception e) {
      logger.error("isEmpty error", e);
    }
    return true;
  }
540240
public function findOrCreateFor(AbstractEntity $entity)
    {
        $seo = $this->findFor($entity);

        if (is_null($seo)) {
            $seo = new Seo();
            $seo->setRef($entity);
        }

        return $seo;
    }
1154407
public static Key marshalKey(DefaultEntityManager entityManager, Object entity) {
    Marshaller marshaller = new Marshaller(entityManager, entity, Intent.DELETE);
    marshaller.marshalKey();
    return (Key) marshaller.key;
  }
366803
public <T> String resolveApitraryEntityId(T entity) {
		if (entity == null) {
			throw new ApitraryOrmIdDefinitionsException("Apitrary entity has not to be null.");
		}
		List<java.lang.reflect.Field> fields = ClassUtil.getAnnotatedFields(entity.getClass(), Id.class);
		if (fields.isEmpty()) {
			throw new ApitraryOrmIdDefinitionsException("Apitrary entity must own an annotated ID field.");
		}
		if (fields.size() > 1) {
			throw new ApitraryOrmIdDefinitionsException("Apitrary entity can not have more than one ID field.");
		}

		java.lang.reflect.Field field = fields.get(0);
		String id = ClassUtil.getValueOf(field, entity, entity.getClass(), String.class);
		if (id == null || id.isEmpty()) {
			throw new ApitraryOrmIdException("Entity lacks ID and is probably not persisted.");
		}
		return id;
	}
359902
public static EntityGetOperation<AssetInfo> get(String assetId) {
        return new DefaultGetOperation<AssetInfo>(ENTITY_SET, assetId,
                AssetInfo.class);
    }