use of org.datanucleus.samples.schema.ClassWithDefaultCols in project tests by datanucleus.
the class SchemaColumnTest method testColumnDefaultsStoringNullWhenNull.
/**
* Test of default values for columns, storing null when a field is null at persist.
*/
public void testColumnDefaultsStoringNullWhenNull() {
Properties props = new Properties();
props.setProperty(RDBMSPropertyNames.PROPERTY_RDBMS_COLUMN_DEFAULT_WHEN_NULL, "false");
PersistenceManagerFactory myPMF = getConfigurablePMF(1, props);
try {
PersistenceManager pm = myPMF.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
ClassWithDefaultCols c1 = new ClassWithDefaultCols(1);
pm.makePersistent(c1);
tx.commit();
} catch (Exception ex) {
LOG.error("Exception during test : " + ex.getMessage());
fail("Exception thrown during test : " + ex.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
myPMF.getDataStoreCache().evictAll();
// Retrieve and check data
pm = myPMF.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
ClassWithDefaultCols c1 = pm.getObjectById(ClassWithDefaultCols.class, 1);
assertNull(c1.getDefaultedNameNull());
assertNull(c1.getDefaultedName());
assertNull(c1.getDefaultedLong());
tx.commit();
} catch (Exception ex) {
LOG.error("Exception during test : " + ex.getMessage());
fail("Exception thrown during test : " + ex.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
clean(myPMF, ClassWithDefaultCols.class);
myPMF.close();
}
}
use of org.datanucleus.samples.schema.ClassWithDefaultCols in project tests by datanucleus.
the class SchemaColumnTest method testColumnDefaultsStoringDefaultWhenNull.
/**
* Test of default values for columns, storing the default when a field is null at persist.
*/
public void testColumnDefaultsStoringDefaultWhenNull() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
ClassWithDefaultCols c1 = new ClassWithDefaultCols(1);
pm.makePersistent(c1);
tx.commit();
} catch (Exception ex) {
LOG.error("Exception during test : " + ex.getMessage());
fail("Exception thrown during test : " + ex.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pmf.getDataStoreCache().evictAll();
// Retrieve and check data
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
ClassWithDefaultCols c1 = pm.getObjectById(ClassWithDefaultCols.class, 1);
assertNull(c1.getDefaultedNameNull());
assertEquals("Name 1", c1.getDefaultedName());
assertEquals(new Long(3), c1.getDefaultedLong());
tx.commit();
} catch (Exception ex) {
LOG.error("Exception during test : " + ex.getMessage());
fail("Exception thrown during test : " + ex.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
clean(ClassWithDefaultCols.class);
}
}
Aggregations