Search in sources :

Example 1 with ParamLocationRecognizer

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());
}
Also used : ParamLocationRecognizer(org.hibernate.engine.query.spi.ParamLocationRecognizer) Test(org.junit.Test)

Example 2 with ParamLocationRecognizer

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());
}
Also used : ParamLocationRecognizer(org.hibernate.engine.query.spi.ParamLocationRecognizer) Test(org.junit.Test)

Example 3 with ParamLocationRecognizer

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);
}
Also used : ParamLocationRecognizer(org.hibernate.engine.query.spi.ParamLocationRecognizer) HashMap(java.util.HashMap) OrdinalParameterDescriptor(org.hibernate.engine.query.spi.OrdinalParameterDescriptor) NamedParameterDescriptor(org.hibernate.engine.query.spi.NamedParameterDescriptor) ParameterMetadataImpl(org.hibernate.query.internal.ParameterMetadataImpl)

Example 4 with ParamLocationRecognizer

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"));
}
Also used : ParamLocationRecognizer(org.hibernate.engine.query.spi.ParamLocationRecognizer) Test(org.junit.Test)

Example 5 with ParamLocationRecognizer

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());
}
Also used : ParamLocationRecognizer(org.hibernate.engine.query.spi.ParamLocationRecognizer) Test(org.junit.Test)

Aggregations

ParamLocationRecognizer (org.hibernate.engine.query.spi.ParamLocationRecognizer)8 Test (org.junit.Test)7 HashMap (java.util.HashMap)1 NamedParameterDescriptor (org.hibernate.engine.query.spi.NamedParameterDescriptor)1 OrdinalParameterDescriptor (org.hibernate.engine.query.spi.OrdinalParameterDescriptor)1 ParameterMetadataImpl (org.hibernate.query.internal.ParameterMetadataImpl)1