use of org.glassfish.ejb.deployment.descriptor.RelationRoleDescriptor in project Payara by payara.
the class EjbConversionHelper method getRealRelationRoleDescriptor.
private RelationRoleDescriptor getRealRelationRoleDescriptor(String ejbName, String cmrFieldName, boolean self) {
ArrayList rels = (ArrayList) ejbRelMap.get(ejbName);
for (int i = 0; i < rels.size(); i++) {
RelationshipDescriptor rel = (RelationshipDescriptor) rels.get(i);
RelationRoleDescriptor source = rel.getSource();
RelationRoleDescriptor sink = rel.getSink();
if (ejbName.equals(source.getOwner().getName()) && cmrFieldName.equals(source.getCMRField())) {
return (self) ? source : sink;
} else if (ejbName.equals(sink.getOwner().getName()) && cmrFieldName.equals(sink.getCMRField())) {
return (self) ? sink : source;
}
}
throw new IllegalArgumentException();
}
use of org.glassfish.ejb.deployment.descriptor.RelationRoleDescriptor in project Payara by payara.
the class EjbConversionHelper method getInverseFieldName.
/**
* This method return the fieldName of relation role on the other end.
*/
public String getInverseFieldName(String ejbName, String fieldName) {
RelationRoleDescriptor oppRole = getRelationRoleDescriptor(ejbName, fieldName, false);
String inverseName = oppRole.getCMRField();
// if we are generating relationships, check for a generated inverse
if ((generateFields) && (inverseName == null))
inverseName = nameMapper.getGeneratedFieldForEjbField(ejbName, fieldName)[1];
return inverseName;
}
use of org.glassfish.ejb.deployment.descriptor.RelationRoleDescriptor in project Payara by payara.
the class CmrFieldTest method check.
/**
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbCMPEntityDescriptor descriptor) {
Result result = getInitializedResult();
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
boolean oneFailed = false;
boolean found = false;
Class c = loadEjbClass(descriptor, result);
if (c != null) {
Set cmrFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getRelationships();
Iterator cmrIterator = cmrFields.iterator();
if (cmrIterator.hasNext()) {
while (cmrIterator.hasNext()) {
RelationshipDescriptor cmfDescriptor = (RelationshipDescriptor) cmrIterator.next();
{
// test if this bean is the source in this relationship
RelationRoleDescriptor role = cmfDescriptor.getSource();
if (role.getOwner().equals(descriptor) && role.getCMRField() != null) {
found = true;
if (!runIndividualCmrTest(descriptor, role, c, result)) {
oneFailed = true;
}
}
}
// we need to test for both source and sink because of self references
{
// test if this bean is the sink in this relationship
RelationRoleDescriptor role = cmfDescriptor.getSink();
if (role.getOwner().equals(descriptor) && role.getCMRField() != null) {
found = true;
if (!runIndividualCmrTest(descriptor, role, c, result)) {
oneFailed = true;
}
}
}
}
if (oneFailed)
result.setStatus(Result.FAILED);
else if (found == false) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldTest.notApplicable", "Not Applicable : The EJB has no CMR fields declared", new Object[] {}));
} else
result.setStatus(Result.PASSED);
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldTest.notApplicable", "Not Applicable : The EJB has no CMR fields declared", new Object[] {}));
}
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.RelationRoleDescriptor in project Payara by payara.
the class EJBBundleInfoHelper method getRelationshipsForEjb.
/**
* @see EJBInfoHelper#getRelationshipsForEjb
*/
public Collection getRelationshipsForEjb(String ejbName) {
Iterator iterator = getBundleDescriptor().getRelationships().iterator();
ArrayList returnList = new ArrayList();
// getFieldsForEjb)
while (iterator.hasNext()) {
RelationshipDescriptor relD = (RelationshipDescriptor) iterator.next();
RelationRoleDescriptor testRole = relD.getSource();
String cmrField = null;
if (ejbName.equals(testRole.getOwner().getName())) {
cmrField = testRole.getCMRField();
if (cmrField != null)
returnList.add(cmrField);
}
testRole = relD.getSink();
if (ejbName.equals(testRole.getOwner().getName())) {
cmrField = testRole.getCMRField();
if (cmrField != null)
returnList.add(cmrField);
}
}
return returnList;
}
use of org.glassfish.ejb.deployment.descriptor.RelationRoleDescriptor in project Payara by payara.
the class NameMapper method initGeneratedRelationshipMaps.
private void initGeneratedRelationshipMaps() {
EjbBundleDescriptorImpl bundleDescriptor = getBundleDescriptor();
Set relationships = bundleDescriptor.getRelationships();
_generatedRelToInverseRelMap = new HashMap();
_relToInverseGeneratedRelMap = new HashMap();
// null check
if (relationships != null) {
Iterator iterator = relationships.iterator();
List generatedRels = new ArrayList();
int counter = 0;
// gather list of generated cmr fields by examining source and sink
while (iterator.hasNext()) {
RelationshipDescriptor relationship = (RelationshipDescriptor) iterator.next();
if (relationship.getSource().getCMRField() == null)
generatedRels.add(relationship);
if (relationship.getSink().getCMRField() == null)
generatedRels.add(relationship);
}
// now update the maps to contain this info
iterator = generatedRels.iterator();
while (iterator.hasNext()) {
RelationshipDescriptor relationship = (RelationshipDescriptor) iterator.next();
RelationRoleDescriptor source = relationship.getSource();
String sourceEjbName = source.getOwner().getName();
String sourceCMRField = source.getCMRField();
boolean sourceIsNull = (sourceCMRField == null);
RelationRoleDescriptor sink = relationship.getSink();
String sinkEjbName = sink.getOwner().getName();
String ejbName = (sourceIsNull ? sourceEjbName : sinkEjbName);
String otherEjbName = (sourceIsNull ? sinkEjbName : sourceEjbName);
List ejbField = Arrays.asList(new String[] { otherEjbName, (sourceIsNull ? sink.getCMRField() : sourceCMRField) });
PersistenceDescriptor pDescriptor = ((EjbCMPEntityDescriptor) bundleDescriptor.getEjbByName(ejbName)).getPersistenceDescriptor();
List generatedField = null;
String uniqueName = null;
// with this name
do {
counter++;
uniqueName = GENERATED_CMR_FIELD_PREFIX + counter;
} while (hasField(pDescriptor, uniqueName));
generatedField = Arrays.asList(new String[] { ejbName, uniqueName });
_generatedRelToInverseRelMap.put(generatedField, ejbField);
_relToInverseGeneratedRelMap.put(ejbField, generatedField);
}
}
}
Aggregations