use of io.jmix.core.entity.KeyValueEntity in project jmix-docs by Haulmont.
the class OrderService method getCustomerPurchases.
// end::load-by-query[]
// tag::load-values[]
String getCustomerPurchases(LocalDate toDate) {
List<KeyValueEntity> kvEntities = dataManager.loadValues("select o.customer, sum(o.amount) from sample_Order o " + "where o.date >= :date group by o.customer").store(// <1>
"main").properties("customer", // <2>
"sum").parameter("date", toDate).list();
StringBuilder sb = new StringBuilder();
for (KeyValueEntity kvEntity : kvEntities) {
// <3>
Customer customer = kvEntity.getValue("customer");
// <3>
BigDecimal sum = kvEntity.getValue("sum");
sb.append(customer.getName()).append(" : ").append(sum);
}
return sb.toString();
}
use of io.jmix.core.entity.KeyValueEntity in project jmix-docs by Haulmont.
the class KeyValueTest method test.
@Test
void test() {
// tag::load[]
List<KeyValueEntity> entities = dataManager.loadValues("select e.customer, sum(e.amount) from sample_Order e group by e.customer").properties("customer", "total").list();
// end::load[]
assertEquals(2, entities.size());
// tag::get-value[]
for (KeyValueEntity entity : entities) {
Customer customer = entity.getValue("customer");
BigDecimal totalAmount = entity.getValue("total");
// ...
}
// end::get-value[]
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class ValueDatasourceDelegate method afterLoadValues.
protected void afterLoadValues(Map<String, Object> params, ValueLoadContext context, List<KeyValueEntity> entities) {
ds.detachListener(ds.data.values());
ds.data.clear();
boolean hasEnumerations = ds.metaClass.getOwnProperties().stream().anyMatch(p -> p.getRange().isEnum());
if (!hasEnumerations) {
for (KeyValueEntity entity : entities) {
ds.data.put(entity.getId(), entity);
ds.attachListener(entity);
entity.setInstanceMetaClass(ds.metaClass);
}
} else {
List<MetaProperty> enumProperties = getEnumProperties(ds.metaClass);
for (KeyValueEntity entity : entities) {
convertEnumValues(entity, enumProperties);
ds.data.put(entity.getId(), entity);
ds.attachListener(entity);
entity.setInstanceMetaClass(ds.metaClass);
}
}
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class EntityListValueFragment method editEntityValue.
@Subscribe("entitiesTable.edit")
public void editEntityValue(Action.ActionPerformedEvent event) {
KeyValueEntity item = entitiesDc.getItemOrNull();
if (item != null) {
oldValue = item;
openEntityValueScreen(tableValues.get(item));
}
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class OracleEntityIdsLoader method loadValues.
protected List<KeyValueEntity> loadValues(ValueLoadContext valueLoadContext) {
String storeName = valueLoadContext.getStoreName();
valueLoadContext.setJoinTransaction(true);
TransactionTemplate transactionTemplate = storeAwareLocator.getTransactionTemplate(storeName);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
List<KeyValueEntity> loadedValues = transactionTemplate.execute(status -> {
EntityManager entityManager = storeAwareLocator.getEntityManager(storeName);
Query selectParametersQuery = entityManager.createNativeQuery("SELECT PARAMETER, value FROM nls_session_parameters WHERE parameter IN ('NLS_COMP', 'NLS_SORT')");
List<?> resultList = selectParametersQuery.getResultList();
Map<String, String> originalValues = new HashMap<>();
resultList.forEach(item -> {
Object[] row = (Object[]) item;
String name = (String) row[0];
String value = (String) row[1];
if (!"BINARY".equalsIgnoreCase(value)) {
originalValues.put(name, value);
}
});
originalValues.keySet().forEach(name -> {
Query alterSessionQuery = entityManager.createNativeQuery("ALTER SESSION SET " + name + " = BINARY");
alterSessionQuery.executeUpdate();
});
List<KeyValueEntity> result = dataManager.loadValues(valueLoadContext);
originalValues.forEach((name, value) -> {
Query alterSessionQuery = entityManager.createNativeQuery("ALTER SESSION SET " + name + " = " + value);
alterSessionQuery.executeUpdate();
});
return result;
});
return loadedValues == null ? Collections.emptyList() : loadedValues;
}
Aggregations