use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class DatasetRelationshipDao method create.
protected void create(Relationship relationship) {
String sql = "INSERT INTO dataset_relationship " + "(name, from_table, from_column, to_table, to_column) VALUES " + "(:name, :from_table, :from_column, :to_table, :to_column)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("name", relationship.getName()).addValue("from_table", relationship.getFromTable().getId()).addValue("from_column", relationship.getFromColumn().getId()).addValue("to_table", relationship.getToTable().getId()).addValue("to_column", relationship.getToColumn().getId());
DaoKeyHolder keyHolder = new DaoKeyHolder();
jdbcTemplate.update(sql, params, keyHolder);
UUID relationshipId = keyHolder.getId();
relationship.id(relationshipId);
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class SnapshotMapTableDao method createColumns.
protected void createColumns(UUID tableId, Collection<SnapshotMapColumn> columns) {
String sql = "INSERT INTO snapshot_map_column (map_table_id, from_column_id, to_column_id)" + " VALUES (:map_table_id, :from_column_id, :to_column_id)";
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("map_table_id", tableId);
DaoKeyHolder keyHolder = new DaoKeyHolder();
for (SnapshotMapColumn column : columns) {
params.addValue("from_column_id", column.getFromColumn().getId());
params.addValue("to_column_id", column.getToColumn().getId());
jdbcTemplate.update(sql, params, keyHolder);
UUID id = keyHolder.getId();
column.id(id);
}
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class SnapshotDao method createSnapshotSource.
private void createSnapshotSource(SnapshotSource snapshotSource) {
String sql = "INSERT INTO snapshot_source (snapshot_id, dataset_id, asset_id)" + " VALUES (:snapshot_id, :dataset_id, :asset_id)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("snapshot_id", snapshotSource.getSnapshot().getId()).addValue("dataset_id", snapshotSource.getDataset().getId());
if (snapshotSource.getAssetSpecification() != null) {
params.addValue("asset_id", snapshotSource.getAssetSpecification().getId());
} else {
params.addValue("asset_id", null);
}
DaoKeyHolder keyHolder = new DaoKeyHolder();
jdbcTemplate.update(sql, params, keyHolder);
UUID id = keyHolder.getId();
snapshotSource.id(id);
snapshotMapTableDao.createTables(id, snapshotSource.getSnapshotMapTables());
snapshotRelationshipDao.createSnapshotRelationships(snapshotSource.getSnapshot());
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class SnapshotDao method createAndLock.
/**
* Create a new snapshot object and lock it. An exception is thrown if the snapshot already exists.
* The correct order to call the SnapshotDao methods when creating a snapshot is: createAndLock, unlock.
* @param snapshot the snapshot object to create
* @return the id of the new snapshot
* @throws InvalidSnapshotException if a row already exists with this snapshot name
*/
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE)
public UUID createAndLock(Snapshot snapshot, String flightId) {
logger.debug("createAndLock snapshot " + snapshot.getName());
String sql = "INSERT INTO snapshot (name, description, profile_id, flightid) " + "VALUES (:name, :description, :profile_id, :flightid) ";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("name", snapshot.getName()).addValue("description", snapshot.getDescription()).addValue("profile_id", snapshot.getProfileId()).addValue("flightid", flightId);
DaoKeyHolder keyHolder = new DaoKeyHolder();
try {
jdbcTemplate.update(sql, params, keyHolder);
} catch (DuplicateKeyException dkEx) {
throw new InvalidSnapshotException("Snapshot name already exists: " + snapshot.getName(), dkEx);
}
UUID snapshotId = keyHolder.getId();
snapshot.id(snapshotId).createdDate(keyHolder.getCreatedDate());
snapshotTableDao.createTables(snapshotId, snapshot.getTables());
for (SnapshotSource snapshotSource : snapshot.getSnapshotSources()) {
createSnapshotSource(snapshotSource);
}
return snapshotId;
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class AssetDao method createAssetRelationships.
private void createAssetRelationships(AssetSpecification assetSpec) {
assetSpec.getAssetRelationships().forEach(assetRel -> {
String sql = "INSERT INTO asset_relationship (asset_id, relationship_id) " + "VALUES (:asset_id, :relationship_id)";
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("asset_id", assetSpec.getId());
params.addValue("relationship_id", assetRel.getDatasetRelationship().getId());
DaoKeyHolder keyHolder = new DaoKeyHolder();
jdbcTemplate.update(sql, params, keyHolder);
UUID assetRelId = keyHolder.getId();
assetRel.id(assetRelId);
});
}
Aggregations