use of io.vertigo.lang.VSystemException 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.lang.VSystemException in project vertigo by KleeGroup.
the class ESStatement method putAll.
/**
* @param indexCollection Collection des indexes à insérer
*/
void putAll(final Collection<SearchIndex<K, I>> indexCollection) {
// Injection spécifique au moteur d'indexation.
try {
final BulkRequestBuilder bulkRequest = esClient.prepareBulk().setRefreshPolicy(BULK_REFRESH);
for (final SearchIndex<K, I> index : indexCollection) {
try (final XContentBuilder xContentBuilder = esDocumentCodec.index2XContentBuilder(index)) {
bulkRequest.add(esClient.prepareIndex().setIndex(indexName).setType(typeName).setId(index.getURI().urn()).setSource(xContentBuilder));
}
}
final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
throw new VSystemException("Can't putAll {0} into {1} index.\nCause by {2}", typeName, indexName, bulkResponse.buildFailureMessage());
}
} catch (final IOException e) {
handleIOException(e);
}
}
use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.
the class BrokerNNImpl method removeNN.
/**
* Supprime une association.
* @param nn description de la nn
* @param targetValue targetValue
*/
private void removeNN(final DescriptionNN nn, final Object targetValue) {
// FieldName
final String sourceFieldName = nn.sourceField.getName();
final String targetFieldName = nn.targetField.getName();
final String taskName = "TK_DELETE_" + nn.tableName;
final String request = String.format("delete from %s where %s = #%s# and %s = #%s#", nn.tableName, sourceFieldName, sourceFieldName, targetFieldName, targetFieldName);
final int sqlRowCount = processNN(taskName, request, nn.dataSpace, nn.sourceField, nn.sourceValue, nn.targetField, targetValue);
if (sqlRowCount > 1) {
throw new VSystemException("More than one row removed");
} else if (sqlRowCount == 0) {
throw new VSystemException("No row removed");
}
}
use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.
the class BerkeleyDatabase method delete.
/**
* @param id Element id to remove
*/
void delete(final String id) {
Assertion.checkArgNotEmpty(id);
// -----
final DatabaseEntry idEntry = new DatabaseEntry();
keyBinding.objectToEntry(id, idEntry);
final OperationStatus status;
try {
status = database.delete(getCurrentBerkeleyTransaction(), idEntry);
} catch (final DatabaseException e) {
throw WrappedException.wrap(e);
}
if (OperationStatus.NOTFOUND.equals(status)) {
throw new VSystemException("delete has failed because no data found with key : {0}", id);
}
if (!OperationStatus.SUCCESS.equals(status)) {
throw new VSystemException("delete has failed");
}
}
use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.
the class DateQueryParserUtil method parse.
/**
* Retourne la date correspondant à l'expression passée en parametre.
* La syntaxe est de type now((+/-)eeeUNIT) ou une date au format dd/MM/yy
*
* @param dateExpression Expression
* @param datePattern Pattern used to define a date (dd/MM/YYYY)
* @return date
*/
static Date parse(final String dateExpression, final String datePattern) {
Assertion.checkArgNotEmpty(dateExpression);
Assertion.checkArgNotEmpty(datePattern, "you must define a valid datePattern such as dd/MM/yyyy or MM/dd/yy");
// ---
if (NOW.equals(dateExpression)) {
// today is gonna be the day
return new Date();
}
if (dateExpression.startsWith(NOW)) {
final int index = NOW.length();
final char operator = dateExpression.charAt(index);
final int sign = buildSign(dateExpression, operator);
// ---
// operand = 21d
final String operand = dateExpression.substring(index + 1);
// NOW+21DAY or NOW-12MONTH
final Matcher matcher = PATTERN.matcher(operand);
Assertion.checkState(matcher.matches(), "Le second operande ne respecte pas le pattern {0}", PATTERN.toString());
// ---
final int unitCount = sign * Integer.parseInt(matcher.group(1));
final String calendarUnit = matcher.group(2);
// We check that we have found a real unit Calendar and not 'NOW+15DAL'
if (!CALENDAR_UNITS.containsKey(calendarUnit)) {
throw new VSystemException("unit '" + calendarUnit + "' is not allowed. You must use a unit among : " + CALENDAR_UNITS.keySet());
}
// ---
final Calendar calendar = new GregorianCalendar();
calendar.add(CALENDAR_UNITS.get(calendarUnit), unitCount);
return calendar.getTime();
}
return format(dateExpression, datePattern);
}
Aggregations