use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class HintProviderTest method requestHint_fieldNameHint_join_throughSeveralFields.
@Test
public void requestHint_fieldNameHint_join_throughSeveralFields() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel personEntity = builder.produceImmediately("Person", "personName");
builder.startNewEntity("Team");
builder.addStringAttribute("name");
builder.addStringAttribute("owner");
builder.addReferenceAttribute("manager", "Person");
JpqlEntityModel teamEntity = builder.produce();
builder.startNewEntity("Player");
builder.addStringAttribute("name");
builder.addStringAttribute("nickname");
builder.addReferenceAttribute("team", "Team");
builder.addReferenceAttribute("agent", "Person");
JpqlEntityModel playerEntity = builder.produce();
builder.startNewEntity("League");
builder.addStringAttribute("name");
builder.addCollectionReferenceAttribute("teams", "Team");
JpqlEntityModel leagueEntity = builder.produce();
builder.startNewEntity("Country");
builder.addStringAttribute("flag");
builder.addReferenceAttribute("league", "League");
JpqlEntityModel countryEntity = builder.produce();
DomainModel model = new DomainModel(teamEntity, playerEntity, leagueEntity, personEntity, countryEntity);
HintProvider hintProvider = createTestHintProvider(model);
HintResponse response = hintProvider.requestHint("select m.~ from Player p " + "left join p.team.manager as m");
List<String> options = response.getOptions();
assertEquals(1, options.size());
assertEquals("personName", options.get(0));
hintProvider = createTestHintProvider(model);
response = hintProvider.requestHint("select c.flag from Country c " + "join c.league.teams as t " + "join t.~");
options = response.getOptions();
assertEquals(1, options.size());
assertEquals("manager", options.get(0));
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class HintProviderTest method requestHint_fieldNameHint_simple.
@Test
public void requestHint_fieldNameHint_simple() 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));
response = hintProvider.requestHint("SELECT p.ni~ FROM Player p");
options = response.getOptions();
assertEquals(1, options.size());
assertEquals("nickname", options.get(0));
response = hintProvider.requestHint("SELECT p.p~ FROM Player p");
options = response.getOptions();
assertEquals(0, options.size());
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class HintProviderTest method requestHint_fieldNameHint_join_and_collection.
@Test
public void requestHint_fieldNameHint_join_and_collection() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel driver = builder.produceImmediately("Driver", "name", "signal");
builder.startNewEntity("HomeBase");
builder.addStringAttribute("city");
JpqlEntityModel homeBase = builder.produce();
builder.startNewEntity("Car");
builder.addStringAttribute("model");
builder.addCollectionReferenceAttribute("drivers", "Driver");
builder.addReferenceAttribute("station", "HomeBase");
JpqlEntityModel car = builder.produce();
DomainModel model = new DomainModel(car, driver, homeBase);
HintProvider hp = new HintProvider(model);
HintResponse response = hp.requestHint("select d.name from Car c join c.station s, in(c.drivers) d where d.name = ?1 and s.~");
List<String> options = response.getOptions();
assertEquals(1, options.size());
assertEquals("city", options.get(0));
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class HintProviderTest method requestHint_with_in_collections.
@Test
public void requestHint_with_in_collections() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel driver = builder.produceImmediately("Driver", "name", "signal");
builder.startNewEntity("Car");
builder.addStringAttribute("model");
builder.addCollectionReferenceAttribute("drivers", "Driver");
JpqlEntityModel car = builder.produce();
DomainModel model = new DomainModel(car, driver);
HintProvider hintProvider = createTestHintProvider(model);
HintResponse response = hintProvider.requestHint("select d.~ from Car c, in(c.drivers) d");
List<String> options = response.getOptions();
assertEquals(2, options.size());
assertEquals("name", options.get(0));
assertEquals("signal", options.get(1));
response = hintProvider.requestHint("select d.name from Car c, in(c.~");
options = response.getOptions();
assertEquals(1, options.size());
assertEquals("drivers", options.get(0));
response = hintProvider.requestHint("select d.name from Car c, in(c.drivers) d where d.~");
options = response.getOptions();
assertEquals(2, options.size());
assertEquals("name", options.get(0));
assertEquals("signal", options.get(1));
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class HintProviderTest method requestHint_fieldNameHint_where_exists.
@Test
public void requestHint_fieldNameHint_where_exists() 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 exists " + "(select 1 " + "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 exists " + "(select 1 " + "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));
response = hintProvider.requestHint("select p.name from Player p " + "where exists " + "(select 1 " + "from Team t " + "where t.~ = p.name)");
options = response.getOptions();
assertEquals(2, options.size());
assertEquals("name", options.get(0));
assertEquals("owner", options.get(1));
}
Aggregations