Search in sources :

Example 6 with JpqlEntityModel

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.

the class HintProviderTest method requestHint_fieldNameHint_where_in_topLevelVariablesUse.

@Test
public void requestHint_fieldNameHint_where_in_topLevelVariablesUse() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name", "owner");
    builder.startNewEntity("Player");
    builder.addStringAttribute("name");
    builder.addStringAttribute("nickname");
    builder.addReferenceAttribute("team", "Team");
    JpqlEntityModel playerEntity = builder.produce();
    DomainModel model = new DomainModel();
    model.add(teamEntity);
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select p.name from Player p " + "where p.nickname in " + "(select t.name " + "from Team t " + "where t.onwer = p.~)");
    List<String> options = response.getOptions();
    assertEquals(3, options.size());
    assertEquals("name", options.get(0));
    assertEquals("nickname", options.get(1));
    assertEquals("team", options.get(2));
    response = hintProvider.requestHint("select t.~ from Player p " + "where p.nickname in " + "(select t.name " + "from Team t " + "where t.onwer = p.name)");
    options = response.getOptions();
    assertEquals(0, options.size());
    assertEquals("Query error", response.getErrorMessage());
    assertEquals(1, response.getCauseErrorMessages().size());
    assertEquals("Cannot parse [t.]", response.getCauseErrorMessages().get(0));
    hintProvider = createTestHintProvider(model);
    response = hintProvider.requestHint("select p from Player p where p.team.name in (select a.~ from Team a where a.name = 'KS')");
    options = response.getOptions();
    assertEquals(2, options.size());
    assertEquals("name", options.get(0));
    assertEquals("owner", options.get(1));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 7 with JpqlEntityModel

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.

the class HintProviderTest method requestHint_betweenMacro.

@Test
public void requestHint_betweenMacro() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    builder.startNewEntity("Player");
    builder.addStringAttribute("nickname");
    builder.addStringAttribute("name");
    builder.addSingleValueAttribute(Date.class, "joinDate");
    JpqlEntityModel playerEntity = builder.produce();
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select p.~ from Player p where @between(p.joinDate, now, now+1, day)");
    List<String> options = response.getOptions();
    assertEquals(3, options.size());
    assertEquals("joinDate", options.get(0));
    assertEquals("name", options.get(1));
    assertEquals("nickname", options.get(2));
    hintProvider = createTestHintProvider(model);
    response = hintProvider.requestHint("select p.name from Player p where @between(p.~, now, now+1, day)");
    options = response.getOptions();
    assertEquals(1, options.size());
    assertEquals("joinDate", options.get(0));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 8 with JpqlEntityModel

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.

the class HintProviderTest method requestHint_fieldNameHint_returnedFieldOrder.

@Test
public void requestHint_fieldNameHint_returnedFieldOrder() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel playerEntity = builder.produceImmediately("Player", "nickname", "name");
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select p.~ from Player p");
    List<String> options = response.getOptions();
    assertEquals(2, options.size());
    assertEquals("name", options.get(0));
    assertEquals("nickname", options.get(1));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 9 with JpqlEntityModel

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.

the class HintProviderTest method requestHint_fieldNameHint_keywordCaseInsensitivity.

@Test
public void requestHint_fieldNameHint_keywordCaseInsensitivity() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel playerEntity = builder.produceImmediately("Player", "name", "nickname");
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select p.~ from Player p");
    List<String> options = response.getOptions();
    assertEquals(2, options.size());
    assertEquals("name", options.get(0));
    assertEquals("nickname", options.get(1));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 10 with JpqlEntityModel

use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.

the class QueryAnalyzerTest method prepareDomainModel.

private DomainModel prepareDomainModel() {
    EntityBuilder builder = new EntityBuilder();
    builder.startNewEntity("Driver");
    builder.addStringAttribute("name");
    builder.addStringAttribute("signal");
    builder.addReferenceAttribute("car", "Driver");
    JpqlEntityModel driver = builder.produce();
    builder.startNewEntity("Car");
    builder.addStringAttribute("model");
    builder.addStringAttribute("regNumber");
    builder.addCollectionReferenceAttribute("drivers", "Driver");
    JpqlEntityModel car = builder.produce();
    return new DomainModel(car, driver);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)

Aggregations

JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)57 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)46 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)45 Test (org.junit.Test)40 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)17 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)16 QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)9 ArrayList (java.util.ArrayList)5 Attribute (com.haulmont.cuba.core.sys.jpql.model.Attribute)4 PathNode (com.haulmont.cuba.core.sys.jpql.tree.PathNode)4 IdentificationVariableNode (com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 UnknownEntityNameException (com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException)2 NoJpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.NoJpqlEntityModel)2 Pointer (com.haulmont.cuba.core.sys.jpql.pointer.Pointer)2 List (java.util.List)2 CommonTree (org.antlr.runtime.tree.CommonTree)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 JPA2RecognitionException (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2RecognitionException)1 VirtualJpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.VirtualJpqlEntityModel)1