if (log.isDebugEnabled())
{
log.debug("Populating default data for '" + persistentName + "'");
}
Persistent p = null;
try
{
p = create(persistentName);
Persistent checkExisting = create(persistentName);
boolean nokeys = true;
Configuration[] children = config.getChildren();
// BUEROBYTE: Sort records by attribute 'id' (if present)
Arrays.sort(children, new Comparator()
{
public int compare(Object o1, Object o2)
{
Configuration c1 = (Configuration) o1;
Configuration c2 = (Configuration) o2;
int id1 = 0;
int id2 = 0;
try
{
id1 = c1.getAttributeAsInteger("id");
}
catch (ConfigurationException x)
{
}
try
{
id2 = c2.getAttributeAsInteger("id");
}
catch (ConfigurationException x)
{
}
return id1 - id2;
}
});
// BUEROBYTE
Configuration oneChild = null;
for (int j = 0; j < children.length; j++)
{
oneChild = children[j];
if (! oneChild.getName().equals("record"))
{
throw new ConfigurationException("default-data element must contain only record elements");
}
p.clear();
checkExisting.clear();
String oneFieldName = null;
for (Iterator names = pmd.getFieldNames().iterator(); names.hasNext();)
{
oneFieldName = (String) names.next();
// BUEROBYTE: Sort records by attribute 'id' (if present)
if (! pmd.getKeyFieldNames().contains(oneFieldName) && "id".equals(oneFieldName))
{
continue;
}
// BUEROBYTE
String attribValue = null;
if (pmd.getKeyFieldNames().contains(oneFieldName))
{
if (pmd.isAutoIncremented(oneFieldName))
{
attribValue = oneChild.getAttribute(oneFieldName, null);
}
else
{
attribValue = oneChild.getAttribute(oneFieldName);
}
if (attribValue != null)
{
checkExisting.setField(oneFieldName, processedAttribValue(attribValue));
nokeys = false;
}
}
else
{
attribValue = oneChild.getAttribute(oneFieldName, null);
}
p.setField(oneFieldName, processedAttribValue(attribValue));
}
if (nokeys)
{
if (! p.find())
{
if (log.isDebugEnabled())
{
log.debug("No existing record for " + p.toString() + ", adding");
}
p.add();
}
else
{
if (log.isDebugEnabled())
{
log.debug("Existing record for " + p.toString());
}
}
}
else if (! checkExisting.find())
{
if (log.isDebugEnabled())
{
log.debug("No existing record with key " + checkExisting.toString() + "', adding");
}
p.add();
}
else
{
if (log.isDebugEnabled())
{
log.debug("Existing record with key " + checkExisting.toString());
}
}
}
}
catch (PersistenceException pe)