use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testProperty.
/**
* Tests Property and Properties annotations
*/
public void testProperty() {
EntityManager em = createEntityManager();
DatabaseSessionImpl session = getDatabaseSession();
ClassDescriptor descriptor = session.getDescriptorForAlias("XMLEmployee");
ClassDescriptor aggregateDescriptor = session.getDescriptor(EmploymentPeriod.class);
em.close();
String errorMsg = "";
if (descriptor == null) {
errorMsg += " Descriptor for XMLEmployee alias was not found;";
}
if (aggregateDescriptor == null) {
errorMsg += " Descriptor for EmploymentPeriod.class was not found;";
}
if (errorMsg.length() > 0) {
fail(errorMsg);
}
// verify properties set on Employee instance
errorMsg += verifyPropertyValue(descriptor, "entityName", String.class, "XMLEmployee");
errorMsg += verifyPropertyValue(descriptor, "entityIntegerProperty", Integer.class, 1);
errorMsg += verifyPropertyValue(descriptor, "ToBeOverriddenByXml", Boolean.class, Boolean.TRUE);
errorMsg += verifyPropertyValue(descriptor, "ToBeProcessed", Boolean.class, Boolean.TRUE);
// each attribute of Employee was assigned a property attributeName with the value attribute name.
for (DatabaseMapping mapping : descriptor.getMappings()) {
errorMsg += verifyPropertyValue(mapping, "attributeName", String.class, mapping.getAttributeName());
}
// attribute m_lastName has many properties of different types
DatabaseMapping mapping = descriptor.getMappingForAttributeName("lastName");
errorMsg += verifyPropertyValue(mapping, "BooleanProperty", Boolean.class, Boolean.TRUE);
errorMsg += verifyPropertyValue(mapping, "ByteProperty", Byte.class, (byte) 1);
errorMsg += verifyPropertyValue(mapping, "CharacterProperty", Character.class, 'A');
errorMsg += verifyPropertyValue(mapping, "DoubleProperty", Double.class, 1.0);
errorMsg += verifyPropertyValue(mapping, "FloatProperty", Float.class, 1F);
errorMsg += verifyPropertyValue(mapping, "IntegerProperty", Integer.class, 1);
errorMsg += verifyPropertyValue(mapping, "LongProperty", Long.class, 1L);
errorMsg += verifyPropertyValue(mapping, "ShortProperty", Short.class, (short) 1);
errorMsg += verifyPropertyValue(mapping, "BigDecimalProperty", java.math.BigDecimal.class, java.math.BigDecimal.ONE);
errorMsg += verifyPropertyValue(mapping, "BigIntegerProperty", java.math.BigInteger.class, java.math.BigInteger.ONE);
errorMsg += verifyPropertyValue(mapping, "TimeProperty", java.sql.Time.class, Helper.timeFromString("13:59:59"));
errorMsg += verifyPropertyValue(mapping, "TimeStampProperty", java.sql.Timestamp.class, Helper.timestampFromString("2008-04-10 13:59:59"));
errorMsg += verifyPropertyValue(mapping, "DateProperty", java.sql.Date.class, Helper.dateFromString("2008-04-10"));
errorMsg += verifyPropertyValue(mapping, "ToBeIgnored", null, null);
// verify property set on EmploymentPeriod embeddable
errorMsg += verifyPropertyValue(aggregateDescriptor, "embeddableClassName", String.class, "EmploymentPeriod");
errorMsg += verifyPropertyValue(aggregateDescriptor, "ToBeOverriddenByXml", Boolean.class, Boolean.TRUE);
errorMsg += verifyPropertyValue(aggregateDescriptor, "ToBeProcessed", Boolean.class, Boolean.TRUE);
if (errorMsg.length() > 0) {
fail(errorMsg);
}
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testPhoneNumberChangeTrackingPolicy.
/**
* Verifies that the change tracking metadata is correctly processed.
*/
public void testPhoneNumberChangeTrackingPolicy() {
if (!isWeavingEnabled()) {
return;
}
DatabaseSessionImpl session = getDatabaseSession();
ClassDescriptor descriptor = session.getDescriptor(PhoneNumber.class);
assertFalse("PhoneNumber descriptor was not found in the PU [" + m_persistenceUnit + "]", descriptor == null);
assertTrue("PhoneNumber descriptor has incorrect object change policy", descriptor.getObjectChangePolicy().isAttributeChangeTrackingPolicy());
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testIfMultipleBasicCollectionMappingsExistForEmployeeResponsibilites.
/**
* Verifies that a basic collection is not added to the employee descriptor
* twice.
*/
public void testIfMultipleBasicCollectionMappingsExistForEmployeeResponsibilites() {
DatabaseSessionImpl session = getDatabaseSession();
ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
int foundCount = 0;
for (DatabaseMapping mapping : employeeDescriptor.getMappings()) {
if (mapping.isDirectCollectionMapping()) {
if (mapping.getAttributeName().equals("responsibilities")) {
foundCount++;
}
}
}
assertFalse("We found multiple mappings for Employee responsibilities", foundCount == 2);
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method getVersion.
protected int getVersion(EntityManager em, Dealer dealer) {
Vector pk = new Vector(1);
pk.add(dealer.getId());
DatabaseSessionImpl session = getDatabaseSession();
return session.getDescriptor(Dealer.class).getOptimisticLockingPolicy().getWriteLockValue(dealer, pk, session);
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testEmployeeCacheSettings.
/**
* Verifies that settings from the Employee cache annotation have been set.
* Also verifies that that employee customizer sets the disable cache hits
* back to false. It is true in XML.
*/
public void testEmployeeCacheSettings() {
DatabaseSessionImpl session = getDatabaseSession();
ClassDescriptor descriptor = session.getDescriptor(Employee.class);
if (descriptor == null) {
fail("A descriptor for the Employee alias was not found in the PU [" + m_persistenceUnit + "]");
} else {
assertTrue("Incorrect cache type() setting.", descriptor.getIdentityMapClass().equals(ClassConstants.SoftCacheWeakIdentityMap_Class));
assertTrue("Incorrect cache size() setting.", descriptor.getIdentityMapSize() == 730);
assertFalse("Incorrect cache isolated() setting.", descriptor.isIsolated());
assertFalse("Incorrect cache alwaysRefresh() setting.", descriptor.shouldAlwaysRefreshCache());
assertFalse("Incorrect disable hits setting.", descriptor.shouldDisableCacheHits());
CacheInvalidationPolicy policy = descriptor.getCacheInvalidationPolicy();
assertTrue("Incorrect cache expiry() policy setting.", policy instanceof TimeToLiveCacheInvalidationPolicy);
assertTrue("Incorrect cache expiry() setting.", ((TimeToLiveCacheInvalidationPolicy) policy).getTimeToLive() == 1000);
assertTrue("Incorrect cache coordinationType() settting.", descriptor.getCacheSynchronizationType() == ClassDescriptor.INVALIDATE_CHANGED_OBJECTS);
}
}
Aggregations