use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class SnapshotTableDao method createColumns.
private void createColumns(UUID tableId, Collection<Column> columns) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("table_id", tableId);
DaoKeyHolder keyHolder = new DaoKeyHolder();
for (Column column : columns) {
params.addValue("name", column.getName());
params.addValue("type", column.getType());
params.addValue("array_of", column.isArrayOf());
jdbcTemplate.update(sqlInsertColumn, params, keyHolder);
UUID columnId = keyHolder.getId();
column.id(columnId);
}
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class GoogleResourceDao method createProject.
public UUID createProject(GoogleProjectResource project) {
try {
String sql = "INSERT INTO project_resource " + "(google_project_id, google_project_number, profile_id, service_ids) VALUES " + "(:google_project_id, :google_project_number, :profile_id, :service_ids)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("google_project_id", project.getGoogleProjectId()).addValue("google_project_number", project.getGoogleProjectNumber()).addValue("profile_id", project.getProfileId()).addValue("service_ids", DaoUtils.createSqlStringArray(connection, project.getServiceIds()));
DaoKeyHolder keyHolder = new DaoKeyHolder();
jdbcTemplate.update(sql, params, keyHolder);
return keyHolder.getId();
} catch (SQLException e) {
throw new GoogleResourceException("Can't save project resource: " + project.getGoogleProjectId(), e);
}
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class GoogleResourceDao method createAndLockBucket.
/**
* Insert a new row into the bucket_resource metadata table and give the provided flight the lock by setting the
* flightid column. If there already exists a row with this bucket name, return null instead of throwing an
* exception.
* @param bucketRequest
* @param flightId
* @return a reference to the bucket as a POJO GoogleBucketResource if the insert succeeded, null otherwise
*/
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE)
public GoogleBucketResource createAndLockBucket(GoogleBucketRequest bucketRequest, String flightId) {
GoogleProjectResource projectResource = Optional.ofNullable(bucketRequest.getGoogleProjectResource()).orElseThrow(IllegalArgumentException::new);
// Put an end to serialization errors here. We only come through here if we really need to create
// the bucket, so this is not on the path of most bucket lookups.
jdbcTemplate.getJdbcTemplate().execute("LOCK TABLE bucket_resource IN EXCLUSIVE MODE");
String sql = "INSERT INTO bucket_resource (project_resource_id, name, flightid) VALUES " + "(:project_resource_id, :name, :flightid) " + "ON CONFLICT ON CONSTRAINT bucket_resource_name_key DO NOTHING";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("project_resource_id", projectResource.getRepositoryId()).addValue("name", bucketRequest.getBucketName()).addValue("flightid", flightId);
DaoKeyHolder keyHolder = new DaoKeyHolder();
// Lock the table to avoid serialization failures during bulk load
jdbcTemplate.getJdbcTemplate().execute("LOCK TABLE bucket_resource IN EXCLUSIVE MODE");
int numRowsUpdated = jdbcTemplate.update(sql, params, keyHolder);
if (numRowsUpdated == 1) {
return (new GoogleBucketResource(bucketRequest)).projectResource(projectResource).name(bucketRequest.getBucketName()).resourceId(keyHolder.getId()).flightId(flightId);
} else {
return null;
}
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class ProfileDao method createBillingProfile.
public UUID createBillingProfile(BillingProfile billingProfile) {
String sql = "INSERT INTO billing_profile (name, biller, billing_account_id) VALUES " + " (:name, :biller, :billing_account_id)";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("name", billingProfile.getName()).addValue("biller", billingProfile.getBiller()).addValue("billing_account_id", billingProfile.getBillingAccountId());
DaoKeyHolder keyHolder = new DaoKeyHolder();
jdbcTemplate.update(sql, params, keyHolder);
return keyHolder.getId();
}
use of bio.terra.common.DaoKeyHolder in project jade-data-repo by DataBiosphere.
the class DatasetTableDao method createColumns.
private void createColumns(UUID tableId, Collection<Column> columns) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("table_id", tableId);
DaoKeyHolder keyHolder = new DaoKeyHolder();
for (Column column : columns) {
params.addValue("name", column.getName());
params.addValue("type", column.getType());
params.addValue("array_of", column.isArrayOf());
jdbcTemplate.update(sqlInsertColumn, params, keyHolder);
UUID columnId = keyHolder.getId();
column.id(columnId);
}
}
Aggregations