Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OGM-953 Passing typed values with grid types to executeBackendQuery()
- Loading branch information
1 parent
ef10bf5
commit 52d9bac
Showing
11 changed files
with
142 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
core/src/main/java/org/hibernate/ogm/dialect/query/spi/QueryParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Hibernate OGM, Domain model persistence for NoSQL datastores | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.ogm.dialect.query.spi; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import org.hibernate.engine.spi.TypedValue; | ||
import org.hibernate.ogm.type.spi.TypeTranslator; | ||
|
||
/** | ||
* Represents the parameters passed to a query. Modelled after {@code QueryParameters} in Hibernate ORM, providing only | ||
* those values needed for OGM's purposes at this point. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class QueryParameters { | ||
|
||
private final RowSelection rowSelection; | ||
private final Map<String, TypedGridValue> namedParameters; | ||
|
||
public QueryParameters(RowSelection rowSelection, Map<String, TypedGridValue> namedParameters) { | ||
this.rowSelection = rowSelection; | ||
this.namedParameters = namedParameters; | ||
} | ||
|
||
public static QueryParameters fromOrmQueryParameters(org.hibernate.engine.spi.QueryParameters parameters, TypeTranslator typeTranslator) { | ||
RowSelection selection = RowSelection.fromOrmRowSelection( parameters.getRowSelection() ); | ||
Map<String, TypedGridValue> namedParameters = new HashMap<>(); | ||
|
||
for ( Entry<String, TypedValue> parameter : parameters.getNamedParameters().entrySet() ) { | ||
namedParameters.put( parameter.getKey(), TypedGridValue.fromOrmTypedValue( parameter.getValue(), typeTranslator ) ); | ||
} | ||
|
||
return new QueryParameters( selection, namedParameters ); | ||
} | ||
|
||
public RowSelection getRowSelection() { | ||
return rowSelection; | ||
} | ||
|
||
public Map<String, TypedGridValue> getNamedParameters() { | ||
return namedParameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/java/org/hibernate/ogm/dialect/query/spi/RowSelection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Hibernate OGM, Domain model persistence for NoSQL datastores | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.ogm.dialect.query.spi; | ||
|
||
/** | ||
* Represents the selection criteria of a query. Modelled after {@code RowSelection} in Hibernate ORM, providing only | ||
* those values needed for OGM's purposes at this point. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class RowSelection { | ||
|
||
private final Integer firstRow; | ||
private final Integer maxRows; | ||
|
||
public RowSelection(Integer firstRow, Integer maxRows) { | ||
this.firstRow = firstRow; | ||
this.maxRows = maxRows; | ||
} | ||
|
||
public static RowSelection fromOrmRowSelection(org.hibernate.engine.spi.RowSelection rowSelection) { | ||
return new RowSelection( rowSelection.getFirstRow(), rowSelection.getMaxRows() ); | ||
} | ||
|
||
public Integer getFirstRow() { | ||
return firstRow; | ||
} | ||
|
||
public Integer getMaxRows() { | ||
return maxRows; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
core/src/main/java/org/hibernate/ogm/dialect/query/spi/TypedGridValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Hibernate OGM, Domain model persistence for NoSQL datastores | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.ogm.dialect.query.spi; | ||
|
||
import org.hibernate.engine.spi.TypedValue; | ||
import org.hibernate.ogm.type.spi.GridType; | ||
import org.hibernate.ogm.type.spi.TypeTranslator; | ||
|
||
/** | ||
* Represents a value and its grid type.the selection criteria of a query. Modelled after {@code TypedValue} in | ||
* Hibernate ORM. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class TypedGridValue { | ||
|
||
private final GridType type; | ||
private final Object value; | ||
|
||
public TypedGridValue(GridType type, Object value) { | ||
this.type = type; | ||
this.value = value; | ||
} | ||
|
||
public static TypedGridValue fromOrmTypedValue(TypedValue typedValue, TypeTranslator typeTranslator) { | ||
GridType gridType = typeTranslator.getType( typedValue.getType() ); | ||
return new TypedGridValue( gridType, typedValue.getValue() ); | ||
} | ||
|
||
public GridType getType() { | ||
return type; | ||
} | ||
|
||
public Object getValue() { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters