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