Skip to content

Commit 25cf341

Browse files
author
ehennum
committed
initial implementation of QueryDSL, SQL, and SPARQL SELECT requests #1280
1 parent 4206ee6 commit 25cf341

File tree

8 files changed

+285
-48
lines changed

8 files changed

+285
-48
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/impl/RowManagerImpl.java

Lines changed: 136 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,8 @@
5252
import com.marklogic.client.io.InputStreamHandle;
5353
import com.marklogic.client.io.StringHandle;
5454
import com.marklogic.client.io.XMLStreamReaderHandle;
55-
import com.marklogic.client.io.marker.AbstractReadHandle;
56-
import com.marklogic.client.io.marker.AbstractWriteHandle;
57-
import com.marklogic.client.io.marker.ContentHandle;
58-
import com.marklogic.client.io.marker.JSONWriteHandle;
59-
import com.marklogic.client.io.marker.StructureReadHandle;
60-
import com.marklogic.client.row.RawPlanDefinition;
61-
import com.marklogic.client.row.RowManager;
62-
import com.marklogic.client.row.RowRecord;
63-
import com.marklogic.client.row.RowSet;
55+
import com.marklogic.client.io.marker.*;
56+
import com.marklogic.client.row.*;
6457
import com.marklogic.client.type.PlanExprCol;
6558
import com.marklogic.client.type.PlanParamBindingVal;
6659
import com.marklogic.client.type.PlanParamExpr;
@@ -125,6 +118,19 @@ public RawPlanDefinition newRawPlanDefinition(JSONWriteHandle handle) {
125118
return new RawPlanDefinitionImpl(handle);
126119
}
127120

121+
@Override
122+
public RawQueryDSLPlan newQueryDSLPlan(TextWriteHandle handle) {
123+
return new RawQueryDSLPlanImpl(handle);
124+
}
125+
@Override
126+
public RawSQLPlanImpl newRawSQLPlan(TextWriteHandle handle) {
127+
return new RawSQLPlanImpl(handle);
128+
}
129+
@Override
130+
public RawSPARQLSelectPlanImpl newRawSPARQLSelectPlan(TextWriteHandle handle) {
131+
return new RawSPARQLSelectPlanImpl(handle);
132+
}
133+
128134
@Override
129135
public <T> T resultDocAs(Plan plan, Class<T> as) {
130136
return resultDocAs(plan, as, null);
@@ -1466,19 +1472,40 @@ private String getNameForColumn(PlanExprCol col) {
14661472
return ((PlanBuilderSubImpl.ColumnNamer) col).getColName();
14671473
}
14681474
}
1469-
static class RawPlanDefinitionImpl implements RawPlanDefinition, PlanBuilderBaseImpl.RequestPlan {
1475+
1476+
static abstract class RawPlanImpl<W extends AbstractWriteHandle> implements RawPlan, PlanBuilderBaseImpl.RequestPlan {
14701477
private Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params = null;
1471-
private JSONWriteHandle handle = null;
1472-
RawPlanDefinitionImpl(JSONWriteHandle handle) {
1478+
private W handle;
1479+
private RawPlanImpl(W handle) {
14731480
setHandle(handle);
14741481
}
1475-
private RawPlanDefinitionImpl(
1476-
JSONWriteHandle handle,
1477-
Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params) {
1482+
private RawPlanImpl(
1483+
W handle,
1484+
Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params) {
14781485
this(handle);
14791486
this.params = params;
14801487
}
14811488

1489+
abstract RawPlanImpl<W> parameterize(W handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params);
1490+
abstract void configHandle(BaseHandle handle);
1491+
1492+
@Override
1493+
public W getHandle() {
1494+
return handle;
1495+
}
1496+
public void setHandle(W handle) {
1497+
if (handle == null) {
1498+
throw new IllegalArgumentException("Must specify handle for reading raw plan");
1499+
}
1500+
if (!(handle instanceof BaseHandle)) {
1501+
throw new IllegalArgumentException(
1502+
"Cannot provide raw plan with invalid handle having class "+handle.getClass().getName()
1503+
);
1504+
}
1505+
configHandle((BaseHandle) handle);
1506+
this.handle = handle;
1507+
}
1508+
14821509
@Override
14831510
public Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> getParams() {
14841511
return params;
@@ -1564,26 +1591,104 @@ public Plan bindParam(PlanParamExpr param, PlanParamBindingVal literal) {
15641591

15651592
nextParams.put((PlanBuilderBaseImpl.PlanParamBase) param, (XsValueImpl.AnyAtomicTypeValImpl) literal);
15661593

1567-
return new RawPlanDefinitionImpl(getHandle(), nextParams);
1594+
return parameterize(getHandle(), nextParams);
1595+
}
1596+
}
1597+
static class RawSQLPlanImpl extends RawPlanImpl<TextWriteHandle> implements RawSQLPlan {
1598+
RawSQLPlanImpl(TextWriteHandle handle) {
1599+
super(handle);
1600+
}
1601+
RawSQLPlanImpl(
1602+
TextWriteHandle handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params
1603+
) {
1604+
super(handle, params);
15681605
}
15691606

1570-
@Override
1571-
public JSONWriteHandle getHandle() {
1572-
return handle;
1607+
RawSQLPlanImpl parameterize(
1608+
TextWriteHandle handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params
1609+
) {
1610+
return new RawSQLPlanImpl(handle, params);
15731611
}
1574-
@Override
1575-
public void setHandle(JSONWriteHandle handle) {
1576-
if (handle == null) {
1577-
throw new IllegalArgumentException("Must specify handle for reading raw plan");
1578-
}
1579-
if (!(handle instanceof BaseHandle)) {
1580-
throw new IllegalArgumentException(
1581-
"Cannot provide raw plan definition with invalid handle having class "+handle.getClass().getName()
1582-
);
1583-
}
1584-
((BaseHandle) handle).setFormat(Format.JSON);
1585-
this.handle = handle;
1612+
void configHandle(BaseHandle handle) {
1613+
handle.setFormat(Format.TEXT);
1614+
handle.setMimetype("application/sql");
1615+
}
1616+
1617+
public RawSQLPlan withHandle(TextWriteHandle handle) {
1618+
setHandle(handle);
1619+
return this;
1620+
}
1621+
}
1622+
static class RawSPARQLSelectPlanImpl extends RawPlanImpl<TextWriteHandle> implements RawSPARQLSelectPlan {
1623+
RawSPARQLSelectPlanImpl(TextWriteHandle handle) {
1624+
super(handle);
1625+
}
1626+
RawSPARQLSelectPlanImpl(
1627+
TextWriteHandle handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params
1628+
) {
1629+
super(handle, params);
1630+
}
1631+
1632+
RawSPARQLSelectPlanImpl parameterize(
1633+
TextWriteHandle handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params
1634+
) {
1635+
return new RawSPARQLSelectPlanImpl(handle, params);
1636+
}
1637+
void configHandle(BaseHandle handle) {
1638+
handle.setFormat(Format.TEXT);
1639+
handle.setMimetype("application/sparql-query");
1640+
}
1641+
1642+
public RawSPARQLSelectPlan withHandle(TextWriteHandle handle) {
1643+
setHandle(handle);
1644+
return this;
1645+
}
1646+
}
1647+
static class RawQueryDSLPlanImpl extends RawPlanImpl<TextWriteHandle> implements RawQueryDSLPlan {
1648+
RawQueryDSLPlanImpl(TextWriteHandle handle) {
1649+
super(handle);
1650+
}
1651+
RawQueryDSLPlanImpl(
1652+
TextWriteHandle handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params
1653+
) {
1654+
super(handle, params);
15861655
}
1656+
1657+
RawQueryDSLPlanImpl parameterize(
1658+
TextWriteHandle handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params
1659+
) {
1660+
return new RawQueryDSLPlanImpl(handle, params);
1661+
}
1662+
void configHandle(BaseHandle handle) {
1663+
handle.setFormat(Format.TEXT);
1664+
handle.setMimetype("application/vnd.marklogic.querydsl+javascript");
1665+
}
1666+
1667+
public RawQueryDSLPlan withHandle(TextWriteHandle handle) {
1668+
setHandle(handle);
1669+
return this;
1670+
}
1671+
}
1672+
static class RawPlanDefinitionImpl extends RawPlanImpl<JSONWriteHandle> implements RawPlanDefinition {
1673+
RawPlanDefinitionImpl(JSONWriteHandle handle) {
1674+
super(handle);
1675+
}
1676+
private RawPlanDefinitionImpl(
1677+
JSONWriteHandle handle,
1678+
Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params) {
1679+
super(handle, params);
1680+
}
1681+
1682+
RawPlanDefinitionImpl parameterize(
1683+
JSONWriteHandle handle, Map<PlanBuilderBaseImpl.PlanParamBase,BaseTypeImpl.ParamBinder> params
1684+
) {
1685+
return new RawPlanDefinitionImpl(handle, params);
1686+
}
1687+
void configHandle(BaseHandle handle) {
1688+
handle.setFormat(Format.JSON);
1689+
handle.setMimetype("application/json");
1690+
}
1691+
15871692
@Override
15881693
public RawPlanDefinition withHandle(JSONWriteHandle handle) {
15891694
setHandle(handle);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2020 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.marklogic.client.row;
17+
18+
import com.marklogic.client.expression.PlanBuilder;
19+
20+
public interface RawPlan extends PlanBuilder.Plan {
21+
}

marklogic-client-api/src/main/java/com/marklogic/client/row/RawPlanDefinition.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 MarkLogic Corporation
2+
* Copyright (c) 2019-2020 MarkLogic Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,22 +15,21 @@
1515
*/
1616
package com.marklogic.client.row;
1717

18-
import com.marklogic.client.expression.PlanBuilder.Plan;
1918
import com.marklogic.client.io.marker.JSONWriteHandle;
2019

2120
/**
2221
* A Raw Plan Definition provides access to a plan
2322
* in a JSON serialization of the exported
2423
* AST (Abstract Syntax Tree) for the plan.
2524
*/
26-
public interface RawPlanDefinition extends Plan {
25+
public interface RawPlanDefinition extends RawPlan {
2726
/**
28-
* Returns the handle for the JSON representation of the plan.
27+
* Returns the handle for the JSON representation of the AST for the plan.
2928
* @return the JSON handle
3029
*/
3130
JSONWriteHandle getHandle();
3231
/**
33-
* Specifies the handle for the JSON representation of the plan.
32+
* Specifies the handle for the JSON representation of the AST for the plan.
3433
* @param handle the JSON handle
3534
*/
3635
void setHandle(JSONWriteHandle handle);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2020 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.marklogic.client.row;
17+
18+
import com.marklogic.client.io.marker.TextWriteHandle;
19+
20+
public interface RawQueryDSLPlan extends RawPlan {
21+
TextWriteHandle getHandle();
22+
void setHandle(TextWriteHandle handle);
23+
RawQueryDSLPlan withHandle(TextWriteHandle handle);
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2020 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.marklogic.client.row;
17+
18+
import com.marklogic.client.io.marker.TextWriteHandle;
19+
20+
public interface RawSPARQLSelectPlan extends RawPlan {
21+
TextWriteHandle getHandle();
22+
void setHandle(TextWriteHandle handle);
23+
RawSPARQLSelectPlan withHandle(TextWriteHandle handle);
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2020 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.marklogic.client.row;
17+
18+
import com.marklogic.client.io.marker.TextWriteHandle;
19+
20+
public interface RawSQLPlan extends RawPlan {
21+
TextWriteHandle getHandle();
22+
void setHandle(TextWriteHandle handle);
23+
RawSQLPlan withHandle(TextWriteHandle handle);
24+
}

marklogic-client-api/src/main/java/com/marklogic/client/row/RowManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.marklogic.client.expression.PlanBuilder.Plan;
2121
import com.marklogic.client.io.marker.JSONWriteHandle;
2222
import com.marklogic.client.io.marker.StructureReadHandle;
23+
import com.marklogic.client.io.marker.TextWriteHandle;
2324

2425
/**
2526
* A Row Manager provides database operations on rows projected from documents.
@@ -84,6 +85,12 @@ public enum RowStructure{ARRAY, OBJECT}
8485
*/
8586
RawPlanDefinition newRawPlanDefinition(JSONWriteHandle handle);
8687

88+
// TODO: JavaDoc
89+
RawQueryDSLPlan newQueryDSLPlan(TextWriteHandle handle);
90+
RawSQLPlan newRawSQLPlan(TextWriteHandle handle);
91+
RawSPARQLSelectPlan newRawSPARQLSelectPlan(TextWriteHandle handle);
92+
93+
8794
/**
8895
* Constructs and retrieves a set of database rows based on a plan using
8996
* a map interface for the column values in each row.
@@ -177,7 +184,7 @@ public enum RowStructure{ARRAY, OBJECT}
177184
* @return the JSON or XML handle populated with the set of rows
178185
*/
179186
<T extends StructureReadHandle> T resultDoc(Plan plan, T handle, Transaction transaction);
180-
187+
181188
/**
182189
* Constructs and retrieves a set of database rows based on a plan
183190
* in the representation specified by the IO class.

0 commit comments

Comments
 (0)