Search in sources :

Example 16 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class BerkeleyDatabase method put.

/**
 * @param id key
 * @param object value
 */
void put(final String id, final Object object) {
    Assertion.checkArgNotEmpty(id);
    Assertion.checkNotNull(object);
    Assertion.checkArgument(object instanceof Serializable, "Value must be Serializable {0}", object.getClass().getSimpleName());
    // -----
    // -----
    final DatabaseEntry idEntry = new DatabaseEntry();
    final DatabaseEntry dataEntry = new DatabaseEntry();
    keyBinding.objectToEntry(id, idEntry);
    dataBinding.objectToEntry(Serializable.class.cast(object), dataEntry);
    final OperationStatus status;
    try {
        status = database.put(getCurrentBerkeleyTransaction(), idEntry, dataEntry);
    } catch (final DatabaseException e) {
        throw WrappedException.wrap(e);
    }
    if (!OperationStatus.SUCCESS.equals(status)) {
        throw new VSystemException("put has failed");
    }
}
Also used : Serializable(java.io.Serializable) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) VSystemException(io.vertigo.lang.VSystemException)

Example 17 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class BerkeleyDatabase method find.

/**
 * Récupération d'un Objet par sa clé.
 * @param <C> D Type des objets à récupérer
 * @param id Id de l'objet à récupérer
 * @param clazz Type des objets à récupérer
 * @return Objet correspondant à la clé
 */
<C> Optional<C> find(final String id, final Class<C> clazz) {
    Assertion.checkNotNull(id);
    Assertion.checkNotNull(clazz);
    // -----
    final DatabaseEntry idEntry = new DatabaseEntry();
    final DatabaseEntry dataEntry = new DatabaseEntry();
    keyBinding.objectToEntry(id, idEntry);
    final OperationStatus status;
    try {
        status = database.get(getCurrentBerkeleyTransaction(), idEntry, dataEntry, LockMode.DEFAULT);
    } catch (final DatabaseException e) {
        throw WrappedException.wrap(e);
    }
    if (status == OperationStatus.NOTFOUND) {
        // Si on n'a rien trouvé
        return Optional.empty();
    }
    if (!OperationStatus.SUCCESS.equals(status)) {
        throw new VSystemException("find has failed");
    }
    return Optional.ofNullable(clazz.cast(dataBinding.entryToObject(dataEntry)));
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) VSystemException(io.vertigo.lang.VSystemException)

Example 18 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class DateQueryParserUtil method format.

private static Date format(final String dateExpression, final String datePattern) {
    // We are expecting a date respectig pattern
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
    try {
        final Calendar calendar = new GregorianCalendar();
        calendar.setTime(simpleDateFormat.parse(dateExpression));
        return calendar.getTime();
    } catch (final ParseException e) {
        throw new VSystemException("La date " + dateExpression + " ne respecte pas le pattern : " + simpleDateFormat.toPattern());
    }
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) VSystemException(io.vertigo.lang.VSystemException)

Example 19 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class Param method parse.

private static Object parse(final String paramName, final Class<?> paramType, final String paramValue) {
    Assertion.checkNotNull(paramName);
    Assertion.checkNotNull(paramType);
    Assertion.checkNotNull(paramValue);
    // -----
    try {
        if (String.class.equals(paramType)) {
            return paramValue;
        } else if (Boolean.class.equals(paramType) || boolean.class.equals(paramType)) {
            return toBoolean(paramName, paramValue);
        } else if (Integer.class.equals(paramType) || int.class.equals(paramType)) {
            return Integer.valueOf(paramValue);
        } else if (Long.class.equals(paramType) || long.class.equals(paramType)) {
            return Long.valueOf(paramValue);
        } else {
            throw new IllegalArgumentException("type '" + paramType + "' unsupported");
        }
    } catch (final Exception e) {
        throw new VSystemException(e, "Param :{0} with value :{1} can't be cast into '{2}'", paramName, paramValue, paramType);
    }
}
Also used : VSystemException(io.vertigo.lang.VSystemException) VSystemException(io.vertigo.lang.VSystemException)

Example 20 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class BeanUtil method setValue.

/**
 * Définit la valeur d'une propriété d'un bean
 * (ex : "name" -> object.setName(value) ou "country.name" -> object.getCountry().setName(value)).
 * @param object java.lang.Object
 * @param propertyName java.lang.String
 * @param value java.lang.Object
 */
public static void setValue(final Object object, final String propertyName, final Object value) {
    Assertion.checkNotNull(object);
    Assertion.checkNotNull(propertyName);
    Assertion.checkArgument(propertyName.indexOf('.') == -1, "the dot notation is forbidden");
    // -----
    final PropertyDescriptor pd = getPropertyDescriptor(propertyName, object.getClass());
    final Method writeMethod = pd.getWriteMethod();
    if (writeMethod == null) {
        throw new VSystemException("no setter found for property '{0}' on class '{1}'", propertyName, object.getClass().getName());
    }
    ClassUtil.invoke(object, writeMethod, value);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method) VSystemException(io.vertigo.lang.VSystemException)

Aggregations

VSystemException (io.vertigo.lang.VSystemException)22 DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 DatabaseException (com.sleepycat.je.DatabaseException)3 OperationStatus (com.sleepycat.je.OperationStatus)3 Method (java.lang.reflect.Method)3 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)3 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 URI (io.vertigo.dynamo.domain.model.URI)2 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)2 Task (io.vertigo.dynamo.task.model.Task)2 AnonymousAccessAllowed (io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed)2 GET (io.vertigo.vega.webservice.stereotype.GET)2 PropertyDescriptor (java.beans.PropertyDescriptor)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AspectConfig (io.vertigo.app.config.AspectConfig)1 ComponentConfig (io.vertigo.app.config.ComponentConfig)1