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");
}
}
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)));
}
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());
}
}
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);
}
}
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);
}
Aggregations