Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
62f2e9a2
Commit
62f2e9a2
authored
4 years ago
by
juanf
Browse files
Options
Downloads
Patches
Plain Diff
SSDM-9478 : Framework to execute SQL
parent
c1f929a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openbis_benchmark/src/main/java/ch/ethz/sis/benchmark/impl/jdbc/SQLQueries.java
+53
-4
53 additions, 4 deletions
...main/java/ch/ethz/sis/benchmark/impl/jdbc/SQLQueries.java
with
53 additions
and
4 deletions
openbis_benchmark/src/main/java/ch/ethz/sis/benchmark/impl/jdbc/SQLQueries.java
+
53
−
4
View file @
62f2e9a2
...
...
@@ -93,10 +93,59 @@ public class SQLQueries {
return
(
Long
)
personId
.
get
(
"id"
);
}
private
static
final
String
SAMPLE_INSERT
=
"INSERT INTO samples_all(id, perm_id, code, proj_id, expe_id, saty_id, registration_timestamp, modification_timestamp, pers_id_registerer, pers_id_modifier, space_id) VALUES(nextval('sample_id_seq'), ?, ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?)"
;
public
static
int
insertSamples
(
Connection
connection
,
List
<
List
<
Object
>>
sampleInsertArgs
)
{
return
SQLExecutor
.
executeUpdate
(
connection
,
SAMPLE_INSERT
,
sampleInsertArgs
);
/*
* samples_all table has several CONSTRAINTS that get executed on INSERT that chain more inserts that ara impossible due to a missing FK
* Because of that, all this contraints are actually doing nothing more than forcing the system to first insert the row and then do an update
*
* Example:
* INSERT INTO samples_all(id, perm_id, code, proj_id, expe_id, saty_id, registration_timestamp, modification_timestamp, pers_id_registerer, pers_id_modifier, space_id) VALUES(nextval('sample_id_seq'), 'fd4e9cec-ed92-455a-accd-8ff41ed83c6b', 'SAMPLE_lcd_nascar_adams', 17, 17, 2, NOW(), NOW(), 2, 2, 14) was aborted: ERROR: insert or update on table "experiment_relationships_history" violates foreign key constraint "exrelh_samp_fk"
* Detail: Key (samp_id)=(6) is not present in table "samples_all". Call getNextException to see other errors in the batch.
*/
private
static
final
String
SAMPLE_INITIAL_INSERT
=
"INSERT INTO samples_all(id, perm_id, code, saty_id, registration_timestamp, modification_timestamp, pers_id_registerer, pers_id_modifier) VALUES(nextval('sample_id_seq'), ?, ?, ?, NOW(), NOW(), ?, ?)"
;
private
static
final
String
SAMPLE_UPDATE_INSERT
=
"UPDATE samples_all SET proj_id = ?, expe_id = ?, space_id = ? WHERE perm_id = ?"
;
// private static final String SAMPLE_INSERT = "INSERT INTO samples_all(id, perm_id, code, proj_id, expe_id, saty_id, registration_timestamp, modification_timestamp, pers_id_registerer, pers_id_modifier, space_id) VALUES(nextval('sample_id_seq'), ?, ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?)";
public
static
int
insertSamples
(
Connection
connection
,
List
<
List
<
Object
>>
samplesInsertArgs
)
{
List
<
List
<
Object
>>
SAMPLE_INITIAL_INSERT_ARGS
=
new
ArrayList
<>();
List
<
List
<
Object
>>
SAMPLE_UPDATE_INSERT_ARGS
=
new
ArrayList
<>();
// perm_id, code, proj_id, expe_id, saty_id, pers_id_registerer, pers_id_modifier, space_id
for
(
List
<
Object
>
sampleInsertArgs:
samplesInsertArgs
)
{
// perm_id, code, saty_id, pers_id_registerer, pers_id_modifier
List
<
Object
>
SAMPLE_INITIAL_INSERT_ARG
=
new
ArrayList
<>();
SAMPLE_INITIAL_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
0
));
SAMPLE_INITIAL_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
1
));
SAMPLE_INITIAL_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
4
));
SAMPLE_INITIAL_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
5
));
SAMPLE_INITIAL_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
6
));
SAMPLE_INITIAL_INSERT_ARGS
.
add
(
SAMPLE_INITIAL_INSERT_ARG
);
// proj_id = ?, expe_id, = ?, space_id = ? WHERE permId = ?
List
<
Object
>
SAMPLE_UPDATE_INSERT_ARG
=
new
ArrayList
<>();
SAMPLE_UPDATE_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
2
));
SAMPLE_UPDATE_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
3
));
SAMPLE_UPDATE_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
7
));
SAMPLE_UPDATE_INSERT_ARG
.
add
(
sampleInsertArgs
.
get
(
0
));
SAMPLE_UPDATE_INSERT_ARGS
.
add
(
SAMPLE_UPDATE_INSERT_ARG
);
}
try
{
connection
.
setAutoCommit
(
false
);
SQLExecutor
.
executeUpdate
(
connection
,
SAMPLE_INITIAL_INSERT
,
SAMPLE_INITIAL_INSERT_ARGS
);
SQLExecutor
.
executeUpdate
(
connection
,
SAMPLE_UPDATE_INSERT
,
SAMPLE_UPDATE_INSERT_ARGS
);
connection
.
commit
();
}
catch
(
Exception
ex
)
{
try
{
connection
.
rollback
();
}
catch
(
Exception
ex2
)
{}
}
finally
{
try
{
connection
.
setAutoCommit
(
true
);
}
catch
(
Exception
ex3
)
{}
}
return
samplesInsertArgs
.
size
();
}
//
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment