Skip to content

Commit cc02648

Browse files
committed
Added copy/consume constructors.
1 parent 7f04674 commit cc02648

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/main/java/com/softwareverde/database/query/BatchedInsertQuery.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package com.softwareverde.database.query;
22

33
public class BatchedInsertQuery extends Query {
4+
protected BatchedInsertQuery(final Query query, final Boolean shouldConsumeQuery) {
5+
super(query, shouldConsumeQuery);
6+
}
7+
48
public BatchedInsertQuery(final String query) {
59
super(query);
610
}
711

12+
public BatchedInsertQuery(final Query query) {
13+
super(query);
14+
}
15+
816
@Override
917
public String getQueryString() {
1018
final Integer parameterCount = _parameters.size();

src/main/java/com/softwareverde/database/query/BatchedUpdateQuery.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
import java.util.regex.Pattern;
55

66
public class BatchedUpdateQuery extends Query {
7+
protected BatchedUpdateQuery(final Query query, final Boolean shouldConsumeQuery) {
8+
super(query, shouldConsumeQuery);
9+
}
10+
711
public BatchedUpdateQuery(final String query) {
812
super(query);
913
}
1014

15+
public BatchedUpdateQuery(final Query query) {
16+
super(query);
17+
}
18+
1119
@Override
1220
public String getQueryString() {
1321
// UPDATE t SET v = x WHERE z IN (?)

src/main/java/com/softwareverde/database/query/Query.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,26 @@
99

1010
public class Query {
1111
protected final String _query;
12-
protected final List<TypedParameter> _parameters = new ArrayList<TypedParameter>();
12+
protected final List<TypedParameter> _parameters;
13+
14+
protected Query(final Query query, final Boolean shouldConsumeQuery) {
15+
if (shouldConsumeQuery) {
16+
_query = query._query;
17+
_parameters = query._parameters;
18+
}
19+
else {
20+
_query = query._query;
21+
_parameters = new ArrayList<TypedParameter>(query._parameters);
22+
}
23+
}
24+
25+
public Query(final Query query) {
26+
this(query, false);
27+
}
1328

1429
public Query(final String query) {
1530
_query = query;
31+
_parameters = new ArrayList<TypedParameter>();
1632
}
1733

1834
public Query setParameter(final Boolean value) {

0 commit comments

Comments
 (0)