use of org.eclipse.persistence.internal.queries.AttributeItem in project eclipselink by eclipse-ee4j.
the class EntityGraphImpl method buildAttributeNodes.
protected void buildAttributeNodes() {
// this instance was built from a pre-existing attribute group so we need to rebuild
// and entity graph
this.attributeNodes = new HashMap<String, AttributeNodeImpl>();
for (AttributeItem item : this.attributeGroup.getItems().values()) {
AttributeNodeImpl node = new AttributeNodeImpl(item.getAttributeName());
ClassDescriptor localDescriptor = null;
if (this.descriptor != null) {
localDescriptor = this.descriptor.getMappingForAttributeName(item.getAttributeName()).getReferenceDescriptor();
}
if (item.getGroups() != null && !item.getGroups().isEmpty()) {
for (AttributeGroup subGroup : item.getGroups().values()) {
Class<?> type = subGroup.getType();
if (type == null) {
type = CoreClassConstants.OBJECT;
}
if (localDescriptor != null) {
if (!type.equals(CoreClassConstants.OBJECT) && localDescriptor.hasInheritance()) {
localDescriptor = localDescriptor.getInheritancePolicy().getDescriptor(type);
}
node.addSubgraph(new EntityGraphImpl(subGroup, localDescriptor));
} else {
node.addSubgraph(new EntityGraphImpl(subGroup));
}
}
}
if (item.getKeyGroups() != null && !item.getKeyGroups().isEmpty()) {
for (AttributeGroup subGroup : item.getKeyGroups().values()) {
Class<?> type = subGroup.getType();
if (type == null) {
type = CoreClassConstants.OBJECT;
}
if (localDescriptor != null) {
if (!type.equals(CoreClassConstants.OBJECT) && localDescriptor.hasInheritance()) {
localDescriptor = localDescriptor.getInheritancePolicy().getDescriptor(type);
}
node.addKeySubgraph(new EntityGraphImpl(subGroup, localDescriptor));
} else {
node.addKeySubgraph(new EntityGraphImpl(subGroup));
}
}
}
this.attributeNodes.put(item.getAttributeName(), node);
}
}
use of org.eclipse.persistence.internal.queries.AttributeItem in project eclipselink by eclipse-ee4j.
the class DescriptorIterator method iteratePrimitiveForMapping.
/**
* Iterate on the primitive value for its mapping.
*/
public void iteratePrimitiveForMapping(Object primitiveValue, DatabaseMapping mapping) {
if (primitiveValue == null) {
return;
}
setCurrentMapping(mapping);
setCurrentDescriptor(null);
if (shouldIterateOnPrimitives()) {
// false by default
AttributeGroup currentGroupOriginal = null;
AttributeItem currentItemOriginal = null;
if (this.usesGroup) {
currentGroupOriginal = this.currentGroup;
currentItemOriginal = this.currentItem;
this.currentGroup = this.currentItem.getGroup();
}
internalIteratePrimitive(primitiveValue);
if (this.usesGroup) {
this.currentGroup = currentGroupOriginal;
this.currentItem = currentItemOriginal;
}
}
}
use of org.eclipse.persistence.internal.queries.AttributeItem in project eclipselink by eclipse-ee4j.
the class FetchGroupManager method prepareAndVerifyInternal.
/**
* INTERNAL:
* Add primary key and version attributes to the passed fetch group
* and all the fetch group it contains.
* Also verifies that all the attributes have corresponding mappings.
*/
protected void prepareAndVerifyInternal(FetchGroup fetchGroup, String attributePrefix) {
addMinimalFetchGroup(fetchGroup);
ObjectBuilder builder = this.descriptor.getObjectBuilder();
if (fetchGroup.isValidated()) {
return;
}
Iterator<Map.Entry<String, AttributeItem>> it = fetchGroup.getAllItems().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, AttributeItem> entry = it.next();
String name = entry.getKey();
DatabaseMapping mapping = builder.getMappingForAttributeName(name);
if (mapping != null) {
FetchGroup nestedFetchGroup = (FetchGroup) entry.getValue().getGroup();
if (nestedFetchGroup != null) {
if (mapping.isForeignReferenceMapping()) {
ClassDescriptor referenceDescriptor = mapping.getReferenceDescriptor();
if (referenceDescriptor != null) {
FetchGroupManager nestedFetchGroupManager = referenceDescriptor.getFetchGroupManager();
if (nestedFetchGroupManager != null) {
nestedFetchGroupManager.prepareAndVerifyInternal(nestedFetchGroup, attributePrefix + name + '.');
} else {
// target descriptor does not support fetch groups
throw ValidationException.fetchGroupHasWrongReferenceClass(fetchGroup, name);
}
} else {
// no reference descriptor found
throw ValidationException.fetchGroupHasWrongReferenceAttribute(fetchGroup, name);
}
} else if (mapping.isAggregateObjectMapping()) {
ClassDescriptor referenceDescriptor = mapping.getReferenceDescriptor();
if (referenceDescriptor != null) {
FetchGroupManager nestedFetchGroupManager = referenceDescriptor.getFetchGroupManager();
if (nestedFetchGroupManager != null) {
nestedFetchGroupManager.prepareAndVerifyInternal(nestedFetchGroup, attributePrefix + name + '.');
} else {
// target descriptor does not support fetch groups
throw ValidationException.fetchGroupHasWrongReferenceClass(fetchGroup, name);
}
} else {
// no reference descriptor found
throw ValidationException.fetchGroupHasWrongReferenceAttribute(fetchGroup, name);
}
} else {
// no reference mapping found
throw ValidationException.fetchGroupHasWrongReferenceAttribute(fetchGroup, name);
}
}
} else {
// no mapping found
throw ValidationException.fetchGroupHasUnmappedAttribute(fetchGroup, name);
}
}
}
use of org.eclipse.persistence.internal.queries.AttributeItem in project eclipselink by eclipse-ee4j.
the class SimpleSerializeFetchGroupTests method verifyWriteReplaceOnFetchGroup.
@Test
public void verifyWriteReplaceOnFetchGroup() throws Exception {
EntityFetchGroup fg = new EntityFetchGroup(new String[] { "basic", "a" });
// fg.addAttribute("basic");
// fg.addAttribute("a.b");
// assertTrue(fg.getClass() == FetchGroup.class);
FetchGroup serFG = serialize(fg);
assertNotNull(serFG);
assertTrue(serFG.getClass() == EntityFetchGroup.class);
assertTrue(serFG.hasItems());
AttributeItem basicFI = serFG.getItem("basic");
assertNotNull(basicFI);
// assertTrue(basicFI instanceof DetachedFetchItem);
AttributeItem aFI = serFG.getItem("a");
assertNotNull(aFI);
// assertTrue(aFI instanceof DetachedFetchItem);
// serialized EntityFetchGroup is always flat - doesn't have nested groups.
assertNull(aFI.getGroup());
/*assertNotNull(aFI.getGroup());
assertTrue(aFI.getGroup() instanceof EntityFetchGroup);
EntityFetchGroup aEFG = (EntityFetchGroup) aFI.getGroup();
assertNull(aEFG.getParent());
assertTrue(aEFG.hasItems());
AttributeItem bFI = aEFG.getItem("b");
assertNotNull(bFI);
//assertTrue(bFI instanceof DetachedFetchItem);
assertNull(bFI.getGroup());*/
}
use of org.eclipse.persistence.internal.queries.AttributeItem in project eclipselink by eclipse-ee4j.
the class NestedNamedFetchGroupTests method dynamicHierarchicalFetchGroup.
@Test
public void dynamicHierarchicalFetchGroup() throws Exception {
EntityManager em = createEntityManager();
Query query = em.createQuery("SELECT e FROM Employee e WHERE e.gender = :GENDER");
query.setParameter("GENDER", Gender.Male);
// Define the fields to be fetched on Employee
FetchGroup fg = new FetchGroup();
fg.addAttribute("firstName");
fg.addAttribute("lastName");
fg.addAttribute("salary");
fg.addAttribute("gender");
fg.addAttribute("manager.firstName");
fg.addAttribute("manager.lastName");
fg.addAttribute("manager.salary");
fg.addAttribute("manager.gender");
fg.addAttribute("manager.manager.firstName");
fg.addAttribute("manager.manager.lastName");
fg.addAttribute("manager.manager.salary");
fg.addAttribute("manager.manager.gender");
AttributeItem mgrItem = fg.getItem("manager");
assertNotNull(mgrItem);
assertNotNull(mgrItem.getGroup());
AttributeItem mgrMgrItem = fg.getItem("manager.manager");
assertNotNull(mgrMgrItem);
assertNotNull(mgrMgrItem.getGroup());
query.setHint(QueryHints.FETCH_GROUP, fg);
List<Employee> emps = query.getResultList();
int numSelect = getQuerySQLTracker(em).getTotalSQLSELECTCalls();
List<Employee> loadedEmps = new ArrayList<Employee>();
loadedEmps.addAll(emps);
for (Employee emp : emps) {
if (!loadedEmps.contains(emp)) {
assertFetched(emp, fg);
}
assertNotFetchedAttribute(emp, "startDate");
loadedEmps.add(emp);
}
// TODO assertEquals(1 + loadedEmps.size() - emps.size(), numSelect);
}
Aggregations