Search in sources :

Example 6 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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 7 with EntityBuilder

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

the class HintProviderTest method requestHint_erroneous.

@Test
public void requestHint_erroneous() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModelImpl playerEntity = builder.produceImmediately("Player");
    DomainModel model = new DomainModel();
    model.add(playerEntity);
    HintProvider hintProvider = createTestHintProvider(model);
    HintResponse response = hintProvider.requestHint("select t FROM p...~");
    List<String> options = response.getOptions();
    assertEquals(0, options.size());
    assertEquals("Query error", response.getErrorMessage());
    assertArrayEquals(new String[] { "Cannot parse [p...]", "Error near: \"p\"" }, response.getCauseErrorMessages().toArray());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) JpqlEntityModelImpl(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) Test(org.junit.Test)

Example 8 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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 EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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 EntityBuilder

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

the class HintProviderTest method requestHint_entityNameHint_simple.

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

Aggregations

EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)50 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)49 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)46 Test (org.junit.Test)44 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)20 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)19 QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)9 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)4 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 QueryTreeTransformer (com.haulmont.cuba.core.sys.jpql.transform.QueryTreeTransformer)1 VariableEntityReference (com.haulmont.cuba.core.sys.jpql.transform.VariableEntityReference)1 CommonTree (org.antlr.runtime.tree.CommonTree)1