boolean validIndex = false;
localBuf.append("create index " + indexName + " on " + entity.externalName() + "(");
for (Enumeration<String> attributes = NSArray.componentsSeparatedByString(attributeNames, ",").objectEnumerator(); attributes.hasMoreElements();) {
String attributeName = attributes.nextElement();
attributeName = attributeName.trim();
EOAttribute attribute = entity.attributeNamed(attributeName);
if (attribute == null) {
attribute = ERXEOAccessUtilities.attributeWithColumnNameFromEntity(attributeName, entity);
}
if (attribute != null && externalTypesToIgnore.indexOfObject(attribute.externalType()) != NSArray.NotFound) {
continue;
}
validIndex = true;
String columnName = attribute == null ? attributeName : attribute.columnName();
columnBuf.append(columnName);
if (attributes.hasMoreElements()) {
columnBuf.append(", ");
}
}
if (validIndex) {
String l = columnBuf.toString();
if (l.endsWith(", ")) {
l = l.substring(0, l.length() - 2);
}
if (usedColumns.indexOfObject(l) == NSArray.NotFound) {
buf.append(localBuf).append(l);
usedColumns.addObject(l);
buf.append(')').append(commandSeparator).append(lineSeparator);
}
}
}
}
else if (key.equals("additionalIndexes")) {
// this is a space separated list of column or attribute
// names
String value = (String) d.objectForKey(key);
for (Enumeration indexes = NSArray.componentsSeparatedByString(value, " ").objectEnumerator(); indexes.hasMoreElements();) {
String indexValues = (String) indexes.nextElement();
if (ERXStringUtilities.stringIsNullOrEmpty(indexValues)) {
continue;
}
// this might be a comma separate list
String indexName = "c" + System.currentTimeMillis() + new NSTimestamp().getNanos();
String newIndexName = i == 0 ? indexName : indexName + "_" + i;
if (oldIndexName == null) {
oldIndexName = indexName;
}
else if (oldIndexName.equals(newIndexName)) {
indexName += "_" + ++i;
}
else {
i = 0;
}
oldIndexName = indexName;
StringBuffer localBuf = new StringBuffer();
StringBuffer columnBuf = new StringBuffer();
boolean validIndex = false;
localBuf.append("create index " + indexName + " on " + entity.externalName() + "(");
for (Enumeration e = NSArray.componentsSeparatedByString(indexValues, ",").objectEnumerator(); e.hasMoreElements();) {
String attributeName = (String) e.nextElement();
attributeName = attributeName.trim();
EOAttribute attribute = entity.attributeNamed(attributeName);
if (attribute == null) {
attribute = ERXEOAccessUtilities.attributeWithColumnNameFromEntity(attributeName, entity);
}
if (attribute != null && externalTypesToIgnore.indexOfObject(attribute.externalType()) != NSArray.NotFound) {
continue;
}
validIndex = true;
String columnName = attribute == null ? attributeName : attribute.columnName();
columnBuf.append(columnName);
if (e.hasMoreElements()) {
columnBuf.append(", ");
}
}