line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Neo4j::Bolt::Txn; |
2
|
4
|
|
|
4
|
|
25
|
use Carp qw/croak/; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
289
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { |
5
|
4
|
|
|
4
|
|
13
|
our $VERSION = "0.4203"; |
6
|
4
|
|
|
|
|
16
|
require Neo4j::Bolt::CTypeHandlers; |
7
|
4
|
|
|
|
|
15
|
require Neo4j::Bolt::ResultStream; |
8
|
4
|
|
|
|
|
10
|
require XSLoader; |
9
|
4
|
|
|
|
|
4154
|
XSLoader::load(); |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
0
|
0
|
0
|
|
sub default_db () { $Neo4j::Bolt::DEFAULT_DB // "" } |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
0
|
|
sub errnum { shift->errnum_ } |
15
|
0
|
|
|
0
|
0
|
|
sub errmsg { shift->errmsg_ } |
16
|
0
|
|
|
0
|
0
|
|
sub cxn { shift->get_connection_ } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
20
|
0
|
|
|
|
|
|
my ($cxn, $params, $db) = @_; |
21
|
0
|
|
0
|
|
|
|
$params //= {}; |
22
|
0
|
0
|
0
|
|
|
|
unless ($cxn && (ref($cxn) =~ /Cxn$/)) { |
23
|
0
|
|
|
|
|
|
die "Arg 1 should be a Neo4j::Bolt::Cxn"; |
24
|
|
|
|
|
|
|
} |
25
|
0
|
0
|
|
|
|
|
unless ($cxn->connected) { |
26
|
0
|
|
|
|
|
|
warn "Not connected"; |
27
|
0
|
|
|
|
|
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
0
|
|
|
|
my $txn = $class->begin_($cxn, $params->{tx_timeout} // -1, $params->{mode} // "w", $db // default_db ); |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
croak "Failed to create transaction (BEGIN failed): ".$txn->errmsg_ if ($txn->errnum_); |
32
|
0
|
|
|
|
|
|
return $txn; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
0
|
1
|
|
sub commit { !shift->commit_ } |
36
|
0
|
|
|
0
|
1
|
|
sub rollback { !shift->rollback_ } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub run_query { |
39
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
my ($query, $parms) = @_; |
41
|
0
|
0
|
|
|
|
|
unless ($query) { |
42
|
0
|
|
|
|
|
|
die "Arg 1 should be Cypher query string"; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
0
|
0
|
|
|
|
if ($parms && !(ref $parms == 'HASH')) { |
45
|
0
|
|
|
|
|
|
die "Arg 2 should be a hashref of { param => $value, ... }"; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
utf8::upgrade($query); |
48
|
0
|
0
|
|
|
|
|
return $self->run_query_($query, $parms ? $parms : {}, 0); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub send_query { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
my ($query, $parms) = @_; |
54
|
0
|
0
|
|
|
|
|
unless ($query) { |
55
|
0
|
|
|
|
|
|
die "Arg 1 should be Cypher query string"; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
0
|
0
|
|
|
|
if ($parms && !(ref $parms == 'HASH')) { |
58
|
0
|
|
|
|
|
|
die "Arg 2 should be a hashref of { param => $value, ... }"; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
utf8::upgrade($query); |
61
|
0
|
|
0
|
|
|
|
return $self->run_query_($query, $parms // {}, 1); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub do_query { |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my $stream = $self->run_query(@_); |
67
|
0
|
|
|
|
|
|
my @results; |
68
|
0
|
0
|
|
|
|
|
if ($stream->success_) { |
69
|
0
|
|
|
|
|
|
while (my @row = $stream->fetch_next_) { |
70
|
0
|
|
|
|
|
|
push @results, [@row]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
0
|
0
|
|
|
|
|
return wantarray ? ($stream, @results) : $stream; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Neo4j::Bolt::Txn - Container for a Neo4j Bolt explicit transaction |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Neo4j::Bolt; |
83
|
|
|
|
|
|
|
$cxn = Neo4j::Bolt->connect("bolt://localhost:7687"); |
84
|
|
|
|
|
|
|
unless ($cxn->connected) { |
85
|
|
|
|
|
|
|
print STDERR "Problem connecting: ".$cxn->errmsg; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
$txn = Neo4j::Bolt::Txn->new($cxn); |
88
|
|
|
|
|
|
|
$stream = $txn->run_query( |
89
|
|
|
|
|
|
|
"CREATE (a:booga {this:'that'}) RETURN a;" |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
if ($stream->failure) { |
92
|
|
|
|
|
|
|
print STDERR "Problem with query run: ". |
93
|
|
|
|
|
|
|
($stream->client_errmsg || $stream->server_errmsg); |
94
|
|
|
|
|
|
|
$txn->rollback; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
|
|
|
|
|
|
$txn->commit; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L is a container for a Bolt explicit transaction, a feature |
103
|
|
|
|
|
|
|
available in Bolt versions 3.0 and greater. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 METHODS |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item new() |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Create (begin) a new transaction. Execute within the transaction with run_query(), send_query(), do_query(). |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item commit() |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Commit the changes staged by execution in the transaction. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item rollback() |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Rollback all changes. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item run_query(), send_query(), do_query() |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Completely analogous to same functions in L. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Mark A. Jensen |
130
|
|
|
|
|
|
|
CPAN: MAJENSEN |
131
|
|
|
|
|
|
|
majensen -at- cpan -dot- org |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This software is Copyright (c) 2019-2021 by Mark A. Jensen. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This is free software, licensed under: |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |