Search in sources :

Example 41 with DatabaseSessionImpl

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);
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) Date(java.sql.Date) EntityManager(jakarta.persistence.EntityManager) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 42 with DatabaseSessionImpl

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());
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 43 with DatabaseSessionImpl

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);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 44 with DatabaseSessionImpl

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);
}
Also used : DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) Vector(java.util.Vector)

Example 45 with DatabaseSessionImpl

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);
    }
}
Also used : TimeToLiveCacheInvalidationPolicy(org.eclipse.persistence.descriptors.invalidation.TimeToLiveCacheInvalidationPolicy) CacheInvalidationPolicy(org.eclipse.persistence.descriptors.invalidation.CacheInvalidationPolicy) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) TimeToLiveCacheInvalidationPolicy(org.eclipse.persistence.descriptors.invalidation.TimeToLiveCacheInvalidationPolicy)

Aggregations

DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)64 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)18 EntityManager (jakarta.persistence.EntityManager)15 HashMap (java.util.HashMap)14 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)14 Map (java.util.Map)13 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)13 Project (org.eclipse.persistence.sessions.Project)12 StringReader (java.io.StringReader)9 StreamSource (javax.xml.transform.stream.StreamSource)9 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)9 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)9 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)9 XMLContext (org.eclipse.persistence.oxm.XMLContext)9 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)9 JAXBContext (jakarta.xml.bind.JAXBContext)8 JAXBException (jakarta.xml.bind.JAXBException)8 Unmarshaller (jakarta.xml.bind.Unmarshaller)8 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)8 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)8