-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2279 - Return generated IDs from INSERT statement.
Signed-off-by: Tomáš Kraus <[email protected]>
- Loading branch information
1 parent
bc1ea3d
commit 9d0e722
Showing
35 changed files
with
937 additions
and
11 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
dbclient/dbclient/src/main/java/io/helidon/dbclient/DbResultDml.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,51 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.helidon.dbclient; | ||
|
||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Result of DML statement execution. | ||
*/ | ||
public interface DbResultDml extends AutoCloseable { | ||
|
||
/** | ||
* Retrieves any auto-generated keys created as a result of executing this DML statement. | ||
* | ||
* @return the auto-generated keys | ||
*/ | ||
Stream<DbRow> generatedKeys(); | ||
|
||
/** | ||
* Retrieve statement execution result. | ||
* | ||
* @return row count for Data Manipulation Language (DML) statements or {@code 0} | ||
* for statements that return nothing. | ||
*/ | ||
long result(); | ||
|
||
/** | ||
* Create new instance of DML statement execution result. | ||
* | ||
* @param generatedKeys the auto-generated keys | ||
* @param result the statement execution result | ||
* @return new instance of DML statement execution result | ||
*/ | ||
static DbResultDml create(Stream<DbRow> generatedKeys, long result) { | ||
return new DbResultDmlImpl(generatedKeys, result); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
dbclient/dbclient/src/main/java/io/helidon/dbclient/DbResultDmlImpl.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 (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.helidon.dbclient; | ||
|
||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
// DbResultDml implementation | ||
record DbResultDmlImpl(Stream<DbRow> generatedKeys, long result) implements DbResultDml { | ||
|
||
DbResultDmlImpl { | ||
Objects.requireNonNull(generatedKeys, "List of auto-generated keys value is null"); | ||
if (result < 0) { | ||
throw new IllegalArgumentException("Statement execution result value is less than 0"); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
generatedKeys.close(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.