use of io.syndesis.common.model.Kind in project syndesis by syndesisio.
the class DataManager method fetchIds.
@SuppressWarnings("unchecked")
public <T extends WithId<T>> Set<String> fetchIds(Class<T> model) {
if (getDataAccessObject(model) != null) {
return doWithDataAccessObject(model, d -> d.fetchIds());
} else {
Kind kind = Kind.from(model);
Map<String, T> cache = caches.getCache(kind.getModelName());
return cache.keySet();
}
}
use of io.syndesis.common.model.Kind in project syndesis by syndesisio.
the class DataStoreConfiguration method jsonDB.
@Bean
@Autowired
@SuppressWarnings("PMD.EmptyCatchBlock")
public SqlJsonDB jsonDB(DBI dbi, Optional<List<Index>> beanIndexes) {
ArrayList<Index> indexes = new ArrayList<>();
if (beanIndexes.isPresent()) {
indexes.addAll(beanIndexes.get());
}
for (Kind kind : Kind.values()) {
addIndex(indexes, kind, kind.getModelClass().getAnnotation(UniqueProperty.class));
UniqueProperty.Multiple ump = kind.getModelClass().getAnnotation(UniqueProperty.Multiple.class);
if (ump != null) {
for (UniqueProperty p : ump.value()) {
addIndex(indexes, kind, p);
}
}
addIndex(indexes, kind, kind.getModelClass().getAnnotation(IndexedProperty.class));
IndexedProperty.Multiple imp = kind.getModelClass().getAnnotation(IndexedProperty.Multiple.class);
if (imp != null) {
for (IndexedProperty p : imp.value()) {
addIndex(indexes, kind, p);
}
}
}
SqlJsonDB jsondb = new SqlJsonDB(dbi, null, indexes);
try {
jsondb.createTables();
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ignore) {
LOG.debug("Could not create tables", ignore);
}
return jsondb;
}
use of io.syndesis.common.model.Kind in project syndesis by syndesisio.
the class DataManager method delete.
public <T extends WithId<T>> boolean delete(Class<T> model, String id) {
if (id == null || id.equals("")) {
throw new EntityNotFoundException("Setting the id on the entity is required for updates");
}
Kind kind = Kind.from(model);
Map<String, WithId<T>> cache = caches.getCache(kind.getModelName());
// Remove it out of the cache
WithId<T> entity = cache.remove(id);
boolean deletedInCache = entity != null;
// And out of the DAO
boolean deletedFromDAO = Boolean.TRUE.equals(doWithDataAccessObject(model, d -> d.delete(id)));
// Return true if the entity was found in any of the two.
if (deletedInCache || deletedFromDAO) {
broadcast(EventBus.Action.DELETED, kind.getModelName(), id);
return true;
}
return false;
}
use of io.syndesis.common.model.Kind in project syndesis by syndesisio.
the class DataManager method store.
public <T extends WithId<T>> void store(ModelData<T> modelData) {
try {
final Kind kind = modelData.getKind();
final T entity = modelData.getData();
LOGGER.debug("{}:{}", kind, modelData.getDataAsJson());
store(entity, kind.getModelClass());
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
LOGGER.warn("Cannot load entity from file: ", e);
throw SyndesisServerException.launderThrowable(e);
}
}
use of io.syndesis.common.model.Kind in project syndesis by syndesisio.
the class DataManager method set.
public <T extends WithId<T>> void set(T entity) {
Optional<String> id = entity.getId();
if (!id.isPresent()) {
throw new EntityNotFoundException("Setting the id on the entity is required for set");
}
String idVal = id.get();
Kind kind = entity.getKind();
this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> {
d.set(entity);
return null;
});
Map<String, T> cache = caches.getCache(kind.getModelName());
cache.put(idVal, entity);
broadcast(EventBus.Action.UPDATED, kind.getModelName(), idVal);
}
Aggregations