@Test public void verifyConfig() throws Exception { ClassDescriptor descriptorA = helper.getSession().getClassDescriptorForAlias("SimpleA"); assertNotNull("No descriptor found for alias='SimpleA'", descriptorA); DynamicType simpleTypeA = helper.getType("SimpleA"); assertNotNull("'SimpleA' EntityType not found", simpleTypeA); assertEquals(descriptorA, simpleTypeA.getDescriptor()); DirectToFieldMapping a_id = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("id"); assertEquals(int.class, a_id.getAttributeClassification()); DirectToFieldMapping a_value1 = (DirectToFieldMapping) descriptorA.getMappingForAttributeName("value1"); assertEquals(String.class, a_value1.getAttributeClassification()); ClassDescriptor descriptorB = helper.getSession().getClassDescriptorForAlias("SimpleB"); assertNotNull("No descriptor found for alias='SimpleB'", descriptorB); DynamicType simpleTypeB = helper.getType("SimpleB"); assertNotNull("'SimpleB' EntityType not found", simpleTypeB); assertEquals(descriptorB, simpleTypeB.getDescriptor()); DirectToFieldMapping b_id = (DirectToFieldMapping) descriptorB.getMappingForAttributeName("id"); assertEquals(int.class, b_id.getAttributeClassification()); DirectToFieldMapping b_value1 = (DirectToFieldMapping) descriptorB.getMappingForAttributeName("value1"); assertEquals(String.class, b_value1.getAttributeClassification()); OneToManyMapping a_b = (OneToManyMapping) descriptorA.getMappingForAttributeName("b"); assertEquals(descriptorB, a_b.getReferenceDescriptor()); }
public void setup() { super.setup(); // add a join between BabyMonitor and Baby what will complete a loop when combined with the // superclass' joins ClassDescriptor descriptor = getSession().getClassDescriptor(BabyMonitor.class); oldJoinFetch = ((OneToOneMapping) descriptor.getMappingForAttributeName("baby")).getJoinFetch(); ((OneToOneMapping) descriptor.getMappingForAttributeName("baby")).useInnerJoinFetch(); descriptor.reInitializeJoinedAttributes(); }
protected ClassDescriptor buildTypeConversionConverterDescriptor() { ClassDescriptor descriptor = super.buildTypeConversionConverterDescriptor(); XMLDirectMapping objectClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("objectClass"); objectClassMapping.setGetMethodName("getObjectClassName"); objectClassMapping.setSetMethodName("setObjectClassName"); XMLDirectMapping dataClassNameMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("dataClass"); dataClassNameMapping.setGetMethodName("getDataClassName"); dataClassNameMapping.setSetMethodName("setDataClassName"); return descriptor; }
protected ClassDescriptor buildClassDescriptorDescriptor() { ClassDescriptor descriptor = super.buildClassDescriptorDescriptor(); XMLDirectMapping referenceClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("javaClass"); referenceClassMapping.setGetMethodName("getJavaClassName"); referenceClassMapping.setSetMethodName("setJavaClassName"); XMLDirectMapping amendmentClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("amendmentClass"); amendmentClassMapping.setGetMethodName("getAmendmentClassName"); amendmentClassMapping.setSetMethodName("setAmendmentClassName"); return descriptor; }
protected void setup() { descriptor = ((DatabaseSession) getSession()).getDescriptor(Actor.class); mapping = (VariableOneToOneMapping) descriptor.getMappingForAttributeName("program"); sourceField = new DatabaseField("ACTOR.PROGRAM_ID"); targetQueryKeyName = (String) mapping.getSourceToTargetQueryKeyNames().get(sourceField); mapping.addForeignQueryKeyName("ACTOR.PROGRAM_ID", "name2"); mapping.getForeignKeyFields().removeElement(sourceField); actor = Actor.example4(); databaseRow = new DatabaseRecord(); if (testMode == 0) { // nothing extra needed } else if (testMode == 1) { ObjectChangeSet changeSet = new ObjectChangeSet(new Vector(), descriptor, actor, new UnitOfWorkChangeSet(), true); changeRecord = new ObjectReferenceChangeRecord(changeSet); changeRecord.setNewValue(changeSet); } else if (testMode == 2) { deleteObjectQuery = new DeleteObjectQuery(actor); deleteObjectQuery.setSession((AbstractSession) getSession()); } expectedException = DescriptorException.variableOneToOneMappingIsNotDefinedProperly( mapping, descriptor, targetQueryKeyName); }
protected ClassDescriptor buildInterfacePolicyDescriptor() { ClassDescriptor descriptor = super.buildInterfacePolicyDescriptor(); XMLCompositeDirectCollectionMapping referenceClassMapping = (XMLCompositeDirectCollectionMapping) descriptor.getMappingForAttributeName("parentInterfaces"); referenceClassMapping.setGetMethodName("getParentInterfaceNames"); referenceClassMapping.setSetMethodName("setParentInterfaceNames"); XMLDirectMapping implementorDescriptorMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("implementorDescriptor"); implementorDescriptorMapping.setGetMethodName("getImplementorDescriptorClassName"); implementorDescriptorMapping.setSetMethodName("setImplementorDescriptorClassName"); return descriptor; }
public void setup() throws Exception { DatabaseLogin login; login = (DatabaseLogin) getSession().getLogin().clone(); server = new Server(login); server.serverSession.setLogLevel(getSession().getLogLevel()); server.serverSession.setLog(getSession().getLog()); server.copyDescriptors(getSession()); ClassDescriptor d = (server.serverSession).getClassDescriptor(BigBadObject.class); DatabaseMapping m; Vector v = d.getMappings(); int mappings = v.size(); int i = 0; while (i < mappings) { m = (DatabaseMapping) v.get(i); m.setWeight(new Integer(Integer.MAX_VALUE - 1)); i++; } m = d.getMappingForAttributeName("number02"); m.setWeight(new Integer(Integer.MAX_VALUE)); server.login(); server.serverSession.setLogLevel(getSession().getLogLevel()); server.serverSession.setLog(getSession().getLog()); }
public void testXmlPropertiesOnField() { ClassDescriptor descriptor = project.getClassDescriptor(Foo.class); DatabaseMapping mapping = descriptor.getMappingForAttributeName("bar2"); Map<Object, Object> properties = mapping.getProperties(); assertTrue("Incorrect number of properties", properties.size() == 1); Object property = properties.get(FIELD_PROPERTY_2_NAME); assertNotNull(property); assertTrue("Incorrect value for property", property.equals("bar2Value")); }
protected ClassDescriptor buildInterfaceContainerPolicyDescriptor() { ClassDescriptor descriptor = super.buildInterfaceContainerPolicyDescriptor(); XMLDirectMapping referenceClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("containerClass"); referenceClassMapping.setGetMethodName("getContainerClassName"); referenceClassMapping.setSetMethodName("setContainerClassName"); return descriptor; }
protected ClassDescriptor buildMethodBaseQueryRedirectorDescriptor() { ClassDescriptor descriptor = super.buildMethodBaseQueryRedirectorDescriptor(); XMLDirectMapping referenceClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("methodClass"); referenceClassMapping.setGetMethodName("getMethodClassName"); referenceClassMapping.setSetMethodName("setMethodClassName"); return descriptor; }
protected ClassDescriptor buildInheritancePolicyDescriptor() { ClassDescriptor descriptor = super.buildInheritancePolicyDescriptor(); XMLDirectMapping referenceClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("parentClass"); referenceClassMapping.setGetMethodName("getParentClassName"); referenceClassMapping.setSetMethodName("setParentClassName"); return descriptor; }
protected ClassDescriptor buildForeignReferenceMappingDescriptor() { ClassDescriptor descriptor = super.buildForeignReferenceMappingDescriptor(); XMLDirectMapping referenceClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("referenceClass"); referenceClassMapping.setGetMethodName("getReferenceClassName"); referenceClassMapping.setSetMethodName("setReferenceClassName"); return descriptor; }
protected ClassDescriptor buildTransformerBasedFieldTransformationDescriptor() { ClassDescriptor descriptor = super.buildTransformerBasedFieldTransformationDescriptor(); XMLDirectMapping objectClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("transformerClass"); objectClassMapping.setGetMethodName("getTransformerClassName"); objectClassMapping.setSetMethodName("setTransformerClassName"); return descriptor; }
protected ClassDescriptor buildAbstractDirectMappingDescriptor() { ClassDescriptor descriptor = super.buildAbstractDirectMappingDescriptor(); XMLDirectMapping attributeClassificationNameMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("attributeClassification"); attributeClassificationNameMapping.setGetMethodName("getAttributeClassificationName"); attributeClassificationNameMapping.setSetMethodName("setAttributeClassificationName"); return descriptor; }
protected ClassDescriptor buildTypedAssociationDescriptor() { ClassDescriptor descriptor = super.buildTypedAssociationDescriptor(); XMLDirectMapping keyMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("key"); keyMapping.setAttributeClassification(null); keyMapping.setGetMethodName("getKey"); keyMapping.setSetMethodName("setKey"); return descriptor; }
protected ClassDescriptor buildQueryArgumentDescriptor() { ClassDescriptor descriptor = super.buildQueryArgumentDescriptor(); XMLDirectMapping referenceClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("type"); referenceClassMapping.setGetMethodName("getTypeName"); referenceClassMapping.setSetMethodName("setTypeName"); return descriptor; }
protected ClassDescriptor buildInstantiationPolicyDescriptor() { ClassDescriptor descriptor = super.buildInstantiationPolicyDescriptor(); XMLDirectMapping referenceClassMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("factoryClass"); referenceClassMapping.setGetMethodName("getFactoryClassName"); referenceClassMapping.setSetMethodName("setFactoryClassName"); return descriptor; }
@Override protected ClassDescriptor buildPLSQLrecordDescriptor() { ClassDescriptor descriptor = super.buildPLSQLrecordDescriptor(); XMLDirectMapping javaTypeMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("javaType"); javaTypeMapping.setGetMethodName("getJavaTypeName"); javaTypeMapping.setSetMethodName("setJavaTypeName"); return descriptor; }
@Test public void testExtensionAttribute_eclipselink_data() { ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class); ClassDescriptor referenceDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObjectExtension.class); assertNotNull( "A classDescriptor should have been retrieved from JPA for TestDataObject", classDescriptor); assertNotNull( "A classDescriptor should have been retrieved from JPA for TestDataObjectExtension", referenceDescriptor); DatabaseMapping databaseMapping = classDescriptor.getMappingForAttributeName("extension"); assertNotNull("extension mapping missing from metamodel", databaseMapping); assertTrue("Should be a OneToOne mapping", databaseMapping instanceof OneToOneMapping); OneToOneMapping mapping = (OneToOneMapping) databaseMapping; assertEquals( "Should be mapped by primaryKeyProperty", "primaryKeyProperty", mapping.getMappedBy()); Map<DatabaseField, DatabaseField> databaseFields = mapping.getSourceToTargetKeyFields(); assertEquals(1, databaseFields.size()); for (DatabaseField sourceField : databaseFields.keySet()) { DatabaseField targetField = databaseFields.get(sourceField); assertEquals("PK_PROP", sourceField.getName()); assertEquals("PK_PROP", targetField.getName()); } assertNotNull( "Reference descriptor missing from relationship", mapping.getReferenceDescriptor()); assertEquals( "Reference descriptor should be the one for TestDataObjectExtension", referenceDescriptor, mapping.getReferenceDescriptor()); assertNotNull("selection query relationship missing", mapping.getSelectionQuery()); assertNotNull("selection query missing name", mapping.getSelectionQuery().getName()); assertEquals( "selection query name incorrect", "extension", mapping.getSelectionQuery().getName()); assertNotNull( "selection query reference class", mapping.getSelectionQuery().getReferenceClass()); assertEquals( "selection query reference class incorrect", TestDataObjectExtension.class, mapping.getSelectionQuery().getReferenceClass()); assertNotNull( "selection query reference class name", mapping.getSelectionQuery().getReferenceClassName()); assertNotNull( "selection query source mapping missing", mapping.getSelectionQuery().getSourceMapping()); assertEquals( "selection query source mapping incorrect", mapping, mapping.getSelectionQuery().getSourceMapping()); }
@Override protected ClassDescriptor buildStoredProcedureArgumentDescriptor() { ClassDescriptor descriptor = super.buildStoredProcedureArgumentDescriptor(); XMLDirectMapping argumentTypeMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("argumentType"); argumentTypeMapping.setGetMethodName("getArgumentTypeName"); argumentTypeMapping.setSetMethodName("setArgumentTypeName"); return descriptor; }
public void verify() { // Check that the named query from employee was found. if (m_exception != null) { throw new TestErrorException( "Our named query from Employee was lost in the XML/Annotation merging. " + m_exception); } // Check that the descriptor contains those mappings we expect from // annotations. ClassDescriptor descriptor = ((EntityManagerImpl) getEntityManager()) .getActiveSession() .getClassDescriptor(Employee.class); if (descriptor.getMappingForAttributeName("lastName") == null) { throw new TestErrorException( "The mapping for [lastName] was was lost in the XML/Annotation merging."); } if (descriptor.getMappingForAttributeName("manager") == null) { throw new TestErrorException( "The mapping for [manager] was lost in the XML/Annotation merging."); } }
public Vector getAttributeFromAll(String attributeName, Vector objects) { ClassDescriptor descriptor = getSession().getClassDescriptor(getReferenceClass()); DirectToFieldMapping mapping = (DirectToFieldMapping) descriptor.getMappingForAttributeName(attributeName); Vector attributes = new Vector(); Object currentObject; for (int i = 0; i < objects.size(); i++) { currentObject = objects.elementAt(i); if (currentObject.getClass() == ReportQueryResult.class) { attributes.addElement(((ReportQueryResult) currentObject).get(attributeName)); } else { attributes.addElement(mapping.getAttributeValueFromObject(currentObject)); } } return attributes; }
public ClassDescriptor buildDatabaseLoginConfigDescriptor() { ClassDescriptor descriptor = super.buildDatabaseLoginConfigDescriptor(); XMLDirectMapping bindAllParametersMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("m_bindAllParameters"); bindAllParametersMapping.setNullValue(Boolean.valueOf(BIND_ALL_PARAMETERS_DEFAULT)); XMLDirectMapping validateConnectionHealthOnErrorMapping = new XMLDirectMapping(); validateConnectionHealthOnErrorMapping.setAttributeName("connectionHealthValidatedOnError"); validateConnectionHealthOnErrorMapping.setGetMethodName("isConnectionHealthValidatedOnError"); validateConnectionHealthOnErrorMapping.setSetMethodName("setConnectionHealthValidatedOnError"); validateConnectionHealthOnErrorMapping.setXPath("connection-health-validated-on-error/text()"); validateConnectionHealthOnErrorMapping.setNullPolicy(new NullPolicy(null, false, false, false)); validateConnectionHealthOnErrorMapping.setNullValue(true); descriptor.addMapping(validateConnectionHealthOnErrorMapping); XMLDirectMapping delayBetweenReconnectAttempts = new XMLDirectMapping(); delayBetweenReconnectAttempts.setAttributeName("delayBetweenConnectionAttempts"); delayBetweenReconnectAttempts.setGetMethodName("getDelayBetweenConnectionAttempts"); delayBetweenReconnectAttempts.setSetMethodName("setDelayBetweenConnectionAttempts"); delayBetweenReconnectAttempts.setXPath("delay-between-reconnect-attempts/text()"); delayBetweenReconnectAttempts.setNullPolicy(new NullPolicy(null, false, false, false)); descriptor.addMapping(delayBetweenReconnectAttempts); XMLDirectMapping queryRetryAttemptCount = new XMLDirectMapping(); queryRetryAttemptCount.setAttributeName("queryRetryAttemptCount"); queryRetryAttemptCount.setGetMethodName("getQueryRetryAttemptCount"); queryRetryAttemptCount.setSetMethodName("setQueryRetryAttemptCount"); queryRetryAttemptCount.setXPath("query-retry-attempt-count/text()"); queryRetryAttemptCount.setNullPolicy(new NullPolicy(null, false, false, false)); descriptor.addMapping(queryRetryAttemptCount); XMLDirectMapping pingSQLMapping = new XMLDirectMapping(); pingSQLMapping.setAttributeName("pingSQL"); pingSQLMapping.setGetMethodName("getPingSQL"); pingSQLMapping.setSetMethodName("setPingSQL"); pingSQLMapping.setXPath("ping-sql/text()"); pingSQLMapping.setNullPolicy(new NullPolicy(null, false, false, false)); descriptor.addMapping(pingSQLMapping); return descriptor; }
@Test public void testConvertersEstabished_autoApply() throws Exception { ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class); DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("currencyProperty"); assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass()); Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter(); assertNotNull("converter not assigned", converter); assertEquals( "Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class, converter.getClass()); Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName"); f.setAccessible(true); String attributeConverterClassName = (String) f.get(converter); assertNotNull("attributeConverterClassName missing", attributeConverterClassName); assertEquals( "Converter class incorrect", "org.kuali.rice.krad.data.jpa.converters.KualiDecimalConverter", attributeConverterClassName); }
public void reset() { super.reset(); ClassDescriptor descriptor = getSession().getClassDescriptor(BabyMonitor.class); ((OneToOneMapping) descriptor.getMappingForAttributeName("baby")).setJoinFetch(oldJoinFetch); descriptor.reInitializeJoinedAttributes(); }