use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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);
}
use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder in project cuba by cuba-platform.
the class QueryAnalyzerTest method mixinJoinIntoTree_with_in_collections.
@Test
public void mixinJoinIntoTree_with_in_collections() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
builder.startNewEntity("HomeBase");
builder.addStringAttribute("name");
JpqlEntityModel homeBase = builder.produce();
builder.startNewEntity("Driver");
builder.addStringAttribute("name");
builder.addStringAttribute("signal");
JpqlEntityModel driver = 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);
JoinVariableNode join = Parser.parseJoinClause("join c.station h").get(0);
QueryTreeTransformer qa = new QueryTreeTransformer();
qa.prepare(model, "select d.name from Car c, in(c.drivers) d");
CommonTree tree = qa.getTree();
CommonTree sources = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SOURCES);
assertEquals(2, sources.getChildCount());
assertTrue(sources.getChild(0) instanceof SelectionSourceNode);
CommonTree source0 = (CommonTree) sources.getChild(0);
assertEquals(1, source0.getChildCount());
assertTrue(source0.getChild(0) instanceof IdentificationVariableNode);
assertTrue(sources.getChild(1) instanceof SelectionSourceNode);
CommonTree source1 = (CommonTree) sources.getChild(1);
assertTrue(source1.getChild(0) instanceof CollectionMemberNode);
qa.mixinJoinIntoTree(join, new VariableEntityReference("Car", "c"), true);
tree = qa.getTree();
sources = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SOURCES);
assertEquals(2, sources.getChildCount());
assertTrue(sources.getChild(0) instanceof SelectionSourceNode);
source0 = (CommonTree) sources.getChild(0);
assertEquals(2, source0.getChildCount());
assertTrue(source0.getChild(0) instanceof IdentificationVariableNode);
assertTrue(source0.getChild(1) instanceof JoinVariableNode);
assertTrue(sources.getChild(1) instanceof SelectionSourceNode);
source1 = (CommonTree) sources.getChild(1);
assertTrue(source1.getChild(0) instanceof CollectionMemberNode);
}
use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method prepareDomainModel.
private DomainModel prepareDomainModel() {
EntityBuilder builder = new EntityBuilder();
builder.startNewEntity("sec$GroupHierarchy");
builder.addStringAttribute("group");
builder.addStringAttribute("createdBy");
builder.addReferenceAttribute("parent", "sec$GroupHierarchy");
builder.addReferenceAttribute("other", "sec$GroupHierarchy");
builder.addReferenceAttribute("token", "fake$EmbeddedToken", "token", true);
builder.addCollectionReferenceAttribute("constraints", "sec$Constraint");
JpqlEntityModel groupHierarchy = builder.produce();
builder = new EntityBuilder();
builder.startNewEntity("sec$Constraint");
builder.addReferenceAttribute("group", "sec$GroupHierarchy");
JpqlEntityModel constraintEntity = builder.produce();
JpqlEntityModel userEntity = builder.produceImmediately("sec$User", "login");
builder = new EntityBuilder();
builder.startNewEntity("fake$EmbeddedToken");
builder.addStringAttribute("name");
builder.addStringAttribute("code");
builder.addReferenceAttribute("manager", "sec$User");
builder.addReferenceAttribute("parentToken", "fake$EmbeddedToken", "parentToken", true);
JpqlEntityModel token = builder.produce();
return new DomainModel(groupHierarchy, constraintEntity, userEntity, token);
}
use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_withParameters.
@Test
public void getResult_noChangesMade_withParameters() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel playerEntity = builder.produceImmediately("Player", "name", "nickname");
DomainModel model = new DomainModel(playerEntity);
assertTransformsToSame(model, "select p.nickname from Player p where p.name = :name");
assertTransformsToSame(model, "select p.nickname from Player p where p.name = :name or p.name = :name2");
assertTransformsToSame(model, "select p.nickname from Player p where p.name = ?1 or p.name = ?2");
assertTransformsToSame(model, "select p.nickname from Player p where p.name like :component$playersFilter.name52981");
}
use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_with_in_collections.
@Test
public void getResult_noChangesMade_with_in_collections() 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);
assertTransformsToSame(model, "select d.name from Car c, in(c.drivers) d where d.name = ?1");
assertTransformsToSame(model, "select d.name from Car c join c.station s, in(c.drivers) d where d.name = ?1 and s.city = :par2");
}
Aggregations