Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rosettaExitStrategy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
rosettaExitStrategy
Commits
45b756a9
Commit
45b756a9
authored
3 years ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- refactoring, moved SQL statement preparation in prepare_addsql() to avoid multiple preparation
parent
ac71aee2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
perl/exit_strategy.pl
+48
-37
48 additions, 37 deletions
perl/exit_strategy.pl
with
48 additions
and
37 deletions
perl/exit_strategy.pl
+
48
−
37
View file @
45b756a9
...
...
@@ -150,36 +150,7 @@ sub write_prepare_insert ($dbh) {
return
1
;
}
###############################################################################
# write add SQL entry, expects a hashref which contains ff. params
# (foreach file location/copy):
# INSERT INTO aip (ie_id) VALUES ($ieid);
# INSERT INTO iefile (aip_id, location, sourcetype) VALUES (
# (SELECT id FROM aip where aip.ieid = $ieid), $location, $sourcetype);
# INSERT INTO file (aip_id, name) VALUES (
# (SELECT id FROM aip where aip.ieid = $ieid), $name);
# INSERT INTO locat (file_id, location, sourcetype) VALUES (
# (SELECT file.aip_id FROM file where file.aip_id = aip.id
# AND aip.ie_id=$ieid), $location, $sourcetype)
# INSERT INTO dc (aip_id, element, value) VALUES (
# (SELECT id FROM aip where aip.ieid = $ieid), $element, $value);
# TODO: needs additional work
# expects a reference of an hash:
# $ret{"filename" } = $filename;
# $ret{"title"} = $title;
# $ret{"repid"} = $repid;
# $ret{"files"} = \@files;
# $ret{"dcrecords"} = \@dcrecords;
###############################################################################
sub
write_addsql
($dbh, $refhash) {
my
$iefile
=
path
(
$refhash
->
{"
filename
"})
->
basename
();
my
(
$ieid
,
$ieversion
);
if
(
$iefile
=~
m/^V(\d+)-(IE\d*)\.xml$/
)
{
$ieversion
=
$
1
;
$ieid
=
$
2
;
}
else
{
die
"
Could not detect PID and Version from IEFile '
$iefile
'
\n
";
}
sub
prepare_addsql
( $dbh) {
my
$sql_aip_plan
=
<<"SQL_AIP_PLAN";
INSERT INTO aip (ie_id, version) VALUES (\$1, \$2);
SQL_AIP_PLAN
...
...
@@ -205,27 +176,65 @@ SQL_LOCAT_PLAN
(SELECT id FROM aip WHERE aip.ie_id=\$1 AND aip.version=\$2), \$3, \$4
);
SQL_DC_PLAN
$dbh
->
begin_work
;
my
$sth_aip_plan
=
$dbh
->
prepare
(
$sql_aip_plan
);
my
$sth_ie_plan
=
$dbh
->
prepare
(
$sql_ie_plan
);
my
$sth_file_plan
=
$dbh
->
prepare
(
$sql_file_plan
);
my
$sth_locat_plan
=
$dbh
->
prepare
(
$sql_locat_plan
);
my
$sth_dc_plan
=
$dbh
->
prepare
(
$sql_dc_pan
);
my
$plans
;
$plans
->
{
aip
}
=
$sth_aip_plan
;
$plans
->
{
ie
}
=
$sth_ie_plan
;
$plans
->
{
file
}
=
$sth_file_plan
;
$plans
->
{
locat
}
=
$sth_locat_plan
;
$plans
->
{
dc
}
=
$sth_dc_plan
;
return
$plans
;
}
###############################################################################
# write add SQL entry, expects a hashref which contains ff. params
# (foreach file location/copy):
# INSERT INTO aip (ie_id) VALUES ($ieid);
# INSERT INTO iefile (aip_id, location, sourcetype) VALUES (
# (SELECT id FROM aip where aip.ieid = $ieid), $location, $sourcetype);
# INSERT INTO file (aip_id, name) VALUES (
# (SELECT id FROM aip where aip.ieid = $ieid), $name);
# INSERT INTO locat (file_id, location, sourcetype) VALUES (
# (SELECT file.aip_id FROM file where file.aip_id = aip.id
# AND aip.ie_id=$ieid), $location, $sourcetype)
# INSERT INTO dc (aip_id, element, value) VALUES (
# (SELECT id FROM aip where aip.ieid = $ieid), $element, $value);
# TODO: needs additional work
# expects a reference of an hash:
# $ret{"filename" } = $filename;
# $ret{"title"} = $title;
# $ret{"repid"} = $repid;
# $ret{"files"} = \@files;
# $ret{"dcrecords"} = \@dcrecords;
###############################################################################
sub
write_addsql
($dbh, $plans, $refhash) {
my
$iefile
=
path
(
$refhash
->
{"
filename
"})
->
basename
();
my
(
$ieid
,
$ieversion
);
if
(
$iefile
=~
m/^V(\d+)-(IE\d*)\.xml$/
)
{
$ieversion
=
$
1
;
$ieid
=
$
2
;
}
else
{
die
"
Could not detect PID and Version from IEFile '
$iefile
'
\n
";
}
$dbh
->
begin_work
;
# start SQL insert
$
sth_aip_plan
->
execute
(
$ieid
,
$ieversion
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
$
plans
->
{
aip
}
->
execute
(
$ieid
,
$ieversion
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
# FIXME if multiple locations exists
$
sth_ie_plan
->
execute
(
$ieid
,
$ieversion
,
$iefile
,
$sourcetype
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
$
plans
->
{
ie
}
->
execute
(
$ieid
,
$ieversion
,
$iefile
,
$sourcetype
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
foreach
my
$location
(
@
{
$refhash
->
{"
files
"}})
{
my
$file
=
path
(
$location
)
->
basename
();
# FIXME if multiple locations
$
sth_file_plan
->
execute
(
$ieid
,
$ieversion
,
$file
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
$
sth_locat_plan
->
execute
(
$ieid
,
$ieversion
,
$file
,
$location
,
$sourcetype
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
$
plans
->
{
file
}
->
execute
(
$ieid
,
$ieversion
,
$file
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
$
plans
->
{
locat
}
->
execute
(
$ieid
,
$ieversion
,
$file
,
$location
,
$sourcetype
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
}
foreach
my
$dcpair
(
@
{
$refhash
->
{"
dcrecords
"}})
{
my
(
$dckey
,
$dcvalue
)
=
@
{
$dcpair
};
# quote ' in dcvalue
$dcvalue
=~
tr/'/"/
;
$
sth_dc_plan
->
execute
(
$ieid
,
$ieversion
,
$dckey
,
$dcvalue
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
$
plans
->
{
dc
}
->
execute
(
$ieid
,
$ieversion
,
$dckey
,
$dcvalue
)
or
die
"
sql problem detected
",
$dbh
->
errstr
;
}
$dbh
->
commit
;
return
1
;
...
...
@@ -536,12 +545,14 @@ $dbh = DBI->connect("dbi:SQLite:dbname=$db_filename", "", "", {
RaiseError
=>
1
,
sqlite_unicode
=>
1
,
})
or
die
"
could not connect to database (file '
$db_filename
')
",
$
DBI::
errstr
;
my
$plans
=
prepare_addsql
(
$dbh
);
while
(
<
$fh_unsorted_IEs
>
)
{
chomp
;
print
$progressbar
->
report
("
parse IE files: %40b ETA: %E
\r
",
$count
++
);
s/V0*(\d+-IE)/V$1/
;
# revert fake version
my
$ret
=
parse_iexml
(
$_
,
$flag_recovery
);
write_addsql
(
$dbh
,
$ret
);
write_addsql
(
$dbh
,
$plans
,
$ret
);
}
$dbh
->
disconnect
or
warn
("
disconnecting problems,
",
$dbh
->
errstr
);
say
"
\r
processed
$count
uniq IEs
";
...
...
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