use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class SqlDataStorePlugin method put.
/**
* @param entity Objet à persiter
* @param insert Si opération de type insert (update sinon)
*/
private void put(final Entity entity, final boolean insert) {
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(entity);
final String tableName = getTableName(dtDefinition);
final String taskName = (insert ? TASK.TK_INSERT : TASK.TK_UPDATE) + "_" + tableName;
final String request = insert ? sqlDialect.createInsertQuery(dtDefinition.getIdField().get().getName(), getDataFields(dtDefinition), sequencePrefix, tableName) : createUpdateQuery(dtDefinition);
final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(getTaskEngineClass(insert)).withDataSpace(dataSpace).withRequest(request).addInRequired("DTO", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTO", Domain.class)).withOutRequired(AbstractTaskEngineSQL.SQL_ROWCOUNT, integerDomain).build();
final Task task = Task.builder(taskDefinition).addValue("DTO", entity).build();
final int sqlRowCount = taskManager.execute(task).getResult();
if (sqlRowCount > 1) {
throw new VSystemException("more than one row has been " + (insert ? "created" : "updated"));
}
if (sqlRowCount == 0) {
throw new VSystemException("no data " + (insert ? "created" : "updated"));
}
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class AbstractDbFileStorePlugin method getValue.
/**
* Retourne une valeur d'un champ à partir du DtObject.
* @param <V> Type de la valeur *
* @param dto DtObject
* @param fieldName Nom du champ
* @param valueClass Type du champ
* @return Valeur typé du champ
*/
protected static <V> V getValue(final DtObject dto, final DtFieldName fieldName, final Class<V> valueClass) {
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(dto);
final DtField dtField = dtDefinition.getField(fieldName.name());
return valueClass.cast(dtField.getDataAccessor().getValue(dto));
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class AbstractDbFileStorePlugin method setValue.
/**
* Fixe une valeur d'un champ d'un DtObject.
*
* @param dto DtObject
* @param fieldName Nom du champs
* @param value Valeur
*/
protected static void setValue(final DtObject dto, final DtFieldName fieldName, final Object value) {
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(dto);
final DtField dtField = dtDefinition.getField(fieldName.name());
dtField.getDataAccessor().setValue(dto, value);
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class FsFileStorePlugin method getValue.
/**
* Retourne une valeur d'un champ à partir du DtObject.
*
* @param dto DtObject
* @param field Nom du champs
* @return Valeur typé du champ
*/
private static <V> V getValue(final DtObject dto, final DtoFields field, final Class<V> valueClass) {
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(dto);
final DtField dtField = dtDefinition.getField(field.name());
return valueClass.cast(dtField.getDataAccessor().getValue(dto));
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class TaskEngineInsertWithGeneratedKeys method doExecute.
/**
* {@inheritDoc}
*/
@Override
public OptionalInt doExecute(final SqlStatement sqlStatement, final SqlConnection connection) throws SQLException {
Assertion.checkNotNull(sqlStatement);
Assertion.checkNotNull(connection);
// --
final GenerationMode generationMode = connection.getDataBase().getSqlDialect().getGenerationMode();
// gestion de generatedKey
final Entity entity = getValue("DTO");
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(entity);
final DtField idField = dtDefinition.getIdField().get();
final Tuples.Tuple2<Integer, ?> result = getDataBaseManager().executeUpdateWithGeneratedKey(sqlStatement, generationMode, idField.getName(), idField.getDomain().getJavaClass(), connection);
final Object id = result.getVal2();
idField.getDataAccessor().setValue(entity, id);
// ---
return /*sqlRowcount*/
OptionalInt.of(result.getVal1());
}
Aggregations