Search in sources :

Example 16 with DaoKeyHolder

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);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DaoKeyHolder(bio.terra.common.DaoKeyHolder) UUID(java.util.UUID)

Example 17 with DaoKeyHolder

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);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DaoKeyHolder(bio.terra.common.DaoKeyHolder) UUID(java.util.UUID)

Example 18 with DaoKeyHolder

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());
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DaoKeyHolder(bio.terra.common.DaoKeyHolder) UUID(java.util.UUID)

Example 19 with DaoKeyHolder

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;
}
Also used : InvalidSnapshotException(bio.terra.service.snapshot.exception.InvalidSnapshotException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DaoKeyHolder(bio.terra.common.DaoKeyHolder) UUID(java.util.UUID) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with DaoKeyHolder

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);
    });
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) DaoKeyHolder(bio.terra.common.DaoKeyHolder) UUID(java.util.UUID)

Aggregations

DaoKeyHolder (bio.terra.common.DaoKeyHolder)20 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)20 UUID (java.util.UUID)14 Transactional (org.springframework.transaction.annotation.Transactional)5 Column (bio.terra.common.Column)2 SQLException (java.sql.SQLException)2 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)2 InvalidAssetException (bio.terra.service.dataset.exception.InvalidAssetException)1 InvalidDatasetException (bio.terra.service.dataset.exception.InvalidDatasetException)1 LoadLockedException (bio.terra.service.load.exception.LoadLockedException)1 GoogleResourceException (bio.terra.service.resourcemanagement.exception.GoogleResourceException)1 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)1 InvalidSnapshotException (bio.terra.service.snapshot.exception.InvalidSnapshotException)1 Array (java.sql.Array)1 Connection (java.sql.Connection)1