Search in sources :

Example 6 with DtDefinition

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"));
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) VSystemException(io.vertigo.lang.VSystemException)

Example 7 with DtDefinition

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));
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 8 with DtDefinition

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);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 9 with DtDefinition

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));
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 10 with DtDefinition

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());
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) GenerationMode(io.vertigo.database.sql.vendor.SqlDialect.GenerationMode) Tuples(io.vertigo.lang.Tuples) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)91 DtField (io.vertigo.dynamo.domain.metamodel.DtField)29 Test (org.junit.Test)21 URI (io.vertigo.dynamo.domain.model.URI)18 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Assertion (io.vertigo.lang.Assertion)12 Collectors (java.util.stream.Collectors)11 Home (io.vertigo.app.Home)10 Optional (java.util.Optional)10 Domain (io.vertigo.dynamo.domain.metamodel.Domain)9 Collections (java.util.Collections)8 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)7 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)7 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Inject (javax.inject.Inject)7 Authorization (io.vertigo.account.authorization.metamodel.Authorization)6 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)6 Criterions (io.vertigo.dynamo.criteria.Criterions)6 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)5