private SecondaryConfig getSecondaryConfig(String secName,
EntityMetadata entityMeta,
String keyClassName,
SecondaryKeyMetadata
secKeyMeta) {
SecondaryConfig config = secConfigMap.get(secName);
if (config == null) {
/* Set common properties to match the primary DB. */
DatabaseConfig priConfig = getPrimaryConfig(entityMeta);
config = new SecondaryConfig();
config.setTransactional(priConfig.getTransactional());
config.setAllowCreate(!priConfig.getReadOnly());
config.setReadOnly(priConfig.getReadOnly());
DbCompat.setTypeBtree(config);
/* <!-- begin JE only --> */
DbInternal.setReplicated(config,
DbInternal.getReplicated(priConfig));
config.setTemporary(priConfig.getTemporary());
config.setDeferredWrite(priConfig.getDeferredWrite());
config.setOverrideBtreeComparator(true);
config.setOverrideDuplicateComparator(true);
/* <!-- end JE only --> */
/* Set secondary properties based on metadata. */
config.setAllowPopulate(true);
Relationship rel = secKeyMeta.getRelationship();
config.setSortedDuplicates(rel == Relationship.MANY_TO_ONE ||
rel == Relationship.MANY_TO_MANY);
setBtreeComparator(config, keyClassName);
config.setDuplicateComparator(priConfig.getBtreeComparator());
PersistKeyCreator keyCreator = new PersistKeyCreator
(catalog, entityMeta, keyClassName, secKeyMeta, rawAccess);
if (rel == Relationship.ONE_TO_MANY ||
rel == Relationship.MANY_TO_MANY) {
config.setMultiKeyCreator(keyCreator);
} else {
config.setKeyCreator(keyCreator);
}
DeleteAction deleteAction = secKeyMeta.getDeleteAction();
if (deleteAction != null) {
ForeignKeyDeleteAction baseDeleteAction;
switch (deleteAction) {
case ABORT:
baseDeleteAction = ForeignKeyDeleteAction.ABORT;
break;
case CASCADE:
baseDeleteAction = ForeignKeyDeleteAction.CASCADE;
break;
case NULLIFY:
baseDeleteAction = ForeignKeyDeleteAction.NULLIFY;
break;
default:
throw DbCompat.unexpectedState(deleteAction.toString());
}
config.setForeignKeyDeleteAction(baseDeleteAction);
if (deleteAction == DeleteAction.NULLIFY) {
config.setForeignMultiKeyNullifier(keyCreator);
}
}
secConfigMap.put(secName, config);
}
return config;