use of org.hibernate.engine.query.spi.ParamLocationRecognizer in project hibernate-orm by hibernate.
the class ParameterParserTest method testParseJPAPositionalParameter.
@Test
public void testParseJPAPositionalParameter() {
ParamLocationRecognizer recognizer = new ParamLocationRecognizer(0);
ParameterParser.parse("from Stock s where s.stockCode = ?1 and s.xyz = ?1", recognizer);
assertEquals(1, recognizer.getOrdinalParameterDescriptionMap().size());
ParameterParser.parse("from Stock s where s.stockCode = ?1 and s.xyz = ?2", recognizer);
assertEquals(2, recognizer.getOrdinalParameterDescriptionMap().size());
}
use of org.hibernate.engine.query.spi.ParamLocationRecognizer in project hibernate-orm by hibernate.
the class ParameterParserTest method testDoubleDashInCharLiteral.
@Test
public void testDoubleDashInCharLiteral() {
ParamLocationRecognizer recognizer = new ParamLocationRecognizer(0);
ParameterParser.parse("select coalesce(i.name, '--NONE--') as itname from Item i where i.intVal=? ", recognizer);
assertEquals(1, recognizer.getOrdinalParameterDescriptionMap().size());
}
use of org.hibernate.engine.query.spi.ParamLocationRecognizer in project hibernate-orm by hibernate.
the class NativeQueryInterpreterStandardImpl method getParameterMetadata.
@Override
public ParameterMetadataImpl getParameterMetadata(String nativeQuery) {
final ParamLocationRecognizer recognizer = ParamLocationRecognizer.parseLocations(nativeQuery);
final int size = recognizer.getOrdinalParameterLocationList().size();
final OrdinalParameterDescriptor[] ordinalDescriptors = new OrdinalParameterDescriptor[size];
for (int i = 0; i < size; i++) {
final Integer position = recognizer.getOrdinalParameterLocationList().get(i);
ordinalDescriptors[i] = new OrdinalParameterDescriptor(i, null, position);
}
final Map<String, NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String, NamedParameterDescriptor>();
final Map<String, ParamLocationRecognizer.NamedParameterDescription> map = recognizer.getNamedParameterDescriptionMap();
for (final String name : map.keySet()) {
final ParamLocationRecognizer.NamedParameterDescription description = map.get(name);
namedParamDescriptorMap.put(name, new NamedParameterDescriptor(name, null, description.buildPositionsArray(), description.isJpaStyle()));
}
return new ParameterMetadataImpl(ordinalDescriptors, namedParamDescriptorMap);
}
use of org.hibernate.engine.query.spi.ParamLocationRecognizer in project hibernate-orm by hibernate.
the class ParameterParserTest method testQuotedTextInComment.
@Test
public void testQuotedTextInComment() {
ParamLocationRecognizer recognizer = new ParamLocationRecognizer(0);
ParameterParser.parse("-- 'This' should not fail the test.\n" + "SELECT column FROM Table WHERE column <> :param", recognizer);
assertTrue(recognizer.getNamedParameterDescriptionMap().containsKey("param"));
}
use of org.hibernate.engine.query.spi.ParamLocationRecognizer in project hibernate-orm by hibernate.
the class ParameterParserTest method testParseNamedParameter.
@Test
public void testParseNamedParameter() {
ParamLocationRecognizer recognizer = new ParamLocationRecognizer(0);
ParameterParser.parse("from Stock s where s.stockCode = :stockCode and s.xyz = :pxyz", recognizer);
assertTrue(recognizer.getNamedParameterDescriptionMap().containsKey("stockCode"));
assertTrue(recognizer.getNamedParameterDescriptionMap().containsKey("pxyz"));
assertEquals(2, recognizer.getNamedParameterDescriptionMap().size());
}
Aggregations