-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>
- Loading branch information
1 parent
4b09c74
commit fda3425
Showing
18 changed files
with
355 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2018-2022 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.db; | ||
|
||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import marquez.db.mappers.DatasetSymlinksRowMapper; | ||
import marquez.db.models.DatasetSymlinkRow; | ||
import org.jdbi.v3.sqlobject.config.RegisterRowMapper; | ||
import org.jdbi.v3.sqlobject.statement.SqlQuery; | ||
import org.jdbi.v3.sqlobject.statement.SqlUpdate; | ||
|
||
@RegisterRowMapper(DatasetSymlinksRowMapper.class) | ||
public interface DatasetSymlinkDao extends BaseDao { | ||
|
||
default DatasetSymlinkRow upsertDatasetSymlinkRow( | ||
UUID uuid, String name, UUID namespaceUuid, boolean isPrimary, Instant now) { | ||
doUpsertDatasetSymlinkRow(uuid, name, namespaceUuid, isPrimary, now); | ||
return findDatasetSymlinkByNamespaceUidAndName(namespaceUuid, name).orElseThrow(); | ||
} | ||
|
||
@SqlQuery("SELECT * FROM dataset_symlinks WHERE namespace_uuid = :namespaceUuid and name = :name") | ||
Optional<DatasetSymlinkRow> findDatasetSymlinkByNamespaceUidAndName( | ||
UUID namespaceUuid, String name); | ||
|
||
@SqlUpdate( | ||
"INSERT INTO dataset_symlinks (" | ||
+ "dataset_uuid, " | ||
+ "name, " | ||
+ "namespace_uuid, " | ||
+ "is_primary, " | ||
+ "created_at, " | ||
+ "updated_at" | ||
+ ") VALUES ( " | ||
+ ":uuid, " | ||
+ ":name, " | ||
+ ":namespaceUuid, " | ||
+ ":isPrimary, " | ||
+ ":now, " | ||
+ ":now) " | ||
+ "ON CONFLICT (name, namespace_uuid) DO NOTHING") | ||
void doUpsertDatasetSymlinkRow( | ||
UUID uuid, String name, UUID namespaceUuid, boolean isPrimary, Instant now); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
api/src/main/java/marquez/db/mappers/DatasetSymlinksRowMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2018-2022 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.db.mappers; | ||
|
||
import static marquez.db.Columns.booleanOrDefault; | ||
import static marquez.db.Columns.stringOrNull; | ||
import static marquez.db.Columns.stringOrThrow; | ||
import static marquez.db.Columns.timestampOrThrow; | ||
import static marquez.db.Columns.uuidOrThrow; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import lombok.NonNull; | ||
import marquez.db.Columns; | ||
import marquez.db.models.DatasetSymlinkRow; | ||
import org.jdbi.v3.core.mapper.RowMapper; | ||
import org.jdbi.v3.core.statement.StatementContext; | ||
|
||
public class DatasetSymlinksRowMapper implements RowMapper<DatasetSymlinkRow> { | ||
|
||
@Override | ||
public DatasetSymlinkRow map(@NonNull ResultSet results, @NonNull StatementContext context) | ||
throws SQLException { | ||
return new DatasetSymlinkRow( | ||
uuidOrThrow(results, Columns.DATASET_UUID), | ||
stringOrThrow(results, Columns.NAME), | ||
uuidOrThrow(results, Columns.NAMESPACE_UUID), | ||
stringOrNull(results, Columns.TYPE), | ||
booleanOrDefault(results, Columns.IS_PRIMARY, false), | ||
timestampOrThrow(results, Columns.CREATED_AT), | ||
timestampOrThrow(results, Columns.UPDATED_AT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
api/src/main/java/marquez/db/models/DatasetSymlinkRow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2018-2022 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.db.models; | ||
|
||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import javax.annotation.Nullable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
@Value | ||
public class DatasetSymlinkRow { | ||
@NonNull UUID uuid; | ||
@NonNull String name; | ||
@NonNull UUID namespaceUuid; | ||
@Nullable String type; | ||
@NonNull boolean isPrimary; | ||
@Getter @NonNull private final Instant createdAt; | ||
@Getter @NonNull private final Instant updatedAt; | ||
|
||
public Optional<String> getType() { | ||
return Optional.ofNullable(type); | ||
} | ||
} |
Oops, something went wrong.