assertEquals(
expectedValues[expectedArrayIndex+1][i][0], properties[i]);
println(" " + properties[i]);
}
Referenceable refDS = (Referenceable) ds;
Reference dsAsReference = refDS.getReference();
String factoryClassName = dsAsReference.getFactoryClassName();
ObjectFactory factory =
(ObjectFactory) Class.forName(factoryClassName).newInstance();
Object recreatedDS =
factory.getObjectInstance(dsAsReference, null, null, null);
// DERBY-2559 - with jdk16, this recreatedDS will be null.
// bailing out
if (JDBC.vmSupportsJDBC4())
return;
println(" empty DataSource recreated using Reference as " +
recreatedDS.getClass().getName());
// empty DataSource recreated using Reference should not be
// the same as the original
assertNotSame(recreatedDS, ds);
compareDS(expectedArrayIndex, properties, ds, recreatedDS);
// now serialize and recreate
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ds);
oos.flush();
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
recreatedDS = ois.readObject();
println(" empty DataSource recreated using serialization");
compareDS(expectedArrayIndex, properties, ds, recreatedDS);
// now populate the data source
for (int i = 0; i < properties.length; i++)
{
String property = properties[i];
Method getMethod = getGet(property, ds);
Method setMethod = getSet(getMethod, ds);
Class pt = getMethod.getReturnType();
// generate a somewhat unique value for a property
int val = 0;
for (int j = 0; j < property.length(); j++)
val += property.charAt(j);
if (pt.equals(Integer.TYPE))
{
setMethod.invoke(ds, new Object[] {new Integer(val)});
continue;
}
if (pt.equals(String.class))
{
String value;
if (property.equals("createDatabase"))
value = "create";
else if (property.equals("shutdownDatabase"))
value = "shutdown";
else if (property.equals("ssl"))
value = "basic";
else
value = "XX_" + property + "_" + val;
setMethod.invoke(ds, new Object[] {value});
continue;
}
if (pt.equals(Boolean.TYPE))
{
// set the opposite value
Object gbv = getMethod.invoke(ds, null);
Boolean sbv =
Boolean.FALSE.equals(gbv) ? Boolean.TRUE : Boolean.FALSE;
setMethod.invoke(ds, new Object[] {sbv});
continue;
}
if (pt.equals(Short.TYPE))
{
setMethod.invoke(ds, new Object[] {new Short((short)val)});
continue;
}
if (pt.equals(Long.TYPE))
{
setMethod.invoke(ds, new Object[] {new Long(val)});
continue;
}
fail ( property + " not settable - update test!!");
}
dsAsReference = refDS.getReference();
recreatedDS =
factory.getObjectInstance(dsAsReference, null, null, null);
println(" populated DataSource recreated using Reference as "
+ recreatedDS.getClass().getName());
// again, recreated should not be same instance