use of com.fathomdb.jpa.impl.JoinedQueryResult in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method findRoots.
@Override
@JdbcTransaction
public List<ItemBase> findRoots(ProjectId project, boolean fetchTags, SecretProvider secretProvider) throws RepositoryException {
DbHelper db = new DbHelper(project);
try {
// TODO: Push-down logic for item selection as well
JoinedQueryResult result = db.listRoots();
List<ItemBase> roots = mapItemsAndTags(project, secretProvider, db, result);
for (ItemBase root : roots) {
// A little bit of paranoia
boolean isRoot = true;
for (Tag tag : root.getTags()) {
boolean tagIsParent = Tag.PARENT.getKey().equals(tag.getKey());
if (tagIsParent) {
isRoot = false;
break;
}
}
assert isRoot;
if (!isRoot) {
throw new IllegalStateException();
}
}
return roots;
} catch (SQLException e) {
throw new RepositoryException("Error fetching items", e);
} finally {
db.close();
}
}
use of com.fathomdb.jpa.impl.JoinedQueryResult in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method findAll.
@Override
@JdbcTransaction
public <T extends ItemBase> List<T> findAll(ModelClass<T> modelClass, ProjectId project, boolean fetchTags, SecretProvider secretProvider, Filter filter) throws RepositoryException {
DbHelper db = new DbHelper(modelClass, project);
try {
int projectId = db.mapToValue(project);
int modelId = db.mapToValue(modelClass.getItemType());
int serviceId = db.mapToValue(modelClass.getServiceType());
String filterKey = null;
JoinedQueryResult result = db.queries.listItems(serviceId, modelId, projectId, filterKey);
List<T> items = mapItemsAndTags(project, secretProvider, db, result);
return applyFilter(items, filter);
} catch (SQLException e) {
throw new RepositoryException("Error fetching items", e);
} finally {
db.close();
}
}
use of com.fathomdb.jpa.impl.JoinedQueryResult in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method fetchItem.
private <T extends ItemBase> T fetchItem(DbHelper db, ServiceType serviceType, ItemType itemType, ProjectId project, ManagedItemId itemId, Class<T> modelClass, SecretProvider secretProvider, boolean fetchTags) throws SQLException, RepositoryException {
int projectId = db.mapToValue(project);
int modelId = db.mapToValue(itemType);
int serviceId = db.mapToValue(serviceType);
String filterKey = itemId.getKey();
JoinedQueryResult result = db.queries.listItems(serviceId, modelId, projectId, filterKey);
List<T> items = mapItemsAndTags(project, secretProvider, db, result);
if (items.size() == 0) {
return null;
}
if (items.size() != 1) {
throw new IllegalStateException();
}
return items.get(0);
}
use of com.fathomdb.jpa.impl.JoinedQueryResult in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method listAll.
@Override
@JdbcTransaction
public List<ItemBase> listAll(ProjectId project, Filter filter, SecretProvider secretProvider) throws RepositoryException {
DbHelper db = new DbHelper(project);
try {
log.debug("listAll with filter: {}", filter);
// TODO: Use this logic for item selection as well
List<Tag> requiredTags = filter.getRequiredTags();
JoinedQueryResult result;
if (!requiredTags.isEmpty()) {
Tag requiredTag = requiredTags.get(0);
int projectId = db.mapToValue(project);
result = db.queries.listAllItemsWithTag(projectId, projectId, requiredTag.getKey(), requiredTag.getValue());
} else {
log.warn("Unable to optimize filter; selecting all items. Filter={}", filter);
result = db.listAllItems();
}
List<ItemBase> items = mapItemsAndTags(project, secretProvider, db, result);
return applyFilter(items, filter);
} catch (SQLException e) {
throw new RepositoryException("Error fetching items", e);
} finally {
db.close();
}
}
Aggregations