}
// Object classes and user atributes.
Iterator<NdbResultSet> ocRsIterator = ocRsList.iterator();
NdbResultSet ocRs = ocRsIterator.next();
AttributeBuilder attrBuilder = new AttributeBuilder();
for (ObjectClass oc : objectClasses.keySet()) {
if (oc.getObjectClassType() == ObjectClassType.ABSTRACT) {
continue;
}
while (ocRs.next()) {
int mid = ocRs.getInt(BackendImpl.MID);
for (AttributeType reqAttr : oc.getRequiredAttributes()) {
String attrName = reqAttr.getNameOrOID();
byte[] attrValBytes = null;
NdbBlob blob = null;
if (BackendImpl.blobAttributes.contains(attrName)) {
Map<String, NdbBlob> attr2Blob =
blobMap.get(objectClasses.get(oc));
blob = attr2Blob.get(attrName);
} else {
attrValBytes = ocRs.getStringBytes(attrName);
if (ocRs.wasNull()) {
continue;
}
}
AttributeType attributeType =
DirectoryServer.getAttributeType(
BackendImpl.attrName2LC.get(attrName), true);
List<Attribute> attrList = userAttributes.get(attributeType);
if (attrList == null) {
attrList = new ArrayList<Attribute>();
}
Attribute attr = null;
LinkedHashSet<String> options = null;
Map<Integer, LinkedHashSet<String>> mid2tagMap =
attr2tagMap.get(attrName);
if (mid2tagMap != null) {
options = mid2tagMap.get(mid);
}
if ((options == null) && !attrList.isEmpty()) {
attr = attrList.get(attrList.size() - 1);
}
if (attr == null) {
attrBuilder.setAttributeType(attributeType, attrName);
} else {
attrBuilder = new AttributeBuilder(attr);
}
if (blob != null) {
if (blob.getNull()) {
continue;
}
int len = blob.getLength().intValue();
byte[] buf = new byte[len];
blob.readData(buf, len);
attrBuilder.add(AttributeValues.create(attributeType,
ByteString.wrap(buf)));
} else {
attrBuilder.add(AttributeValues.create(attributeType,
ByteString.wrap(attrValBytes)));
}
// Create or update an attribute.
if (options != null) {
attrBuilder.setOptions(options);
}
attr = attrBuilder.toAttribute();
if (attrList.isEmpty()) {
attrList.add(attr);
} else {
attrList.set(attrList.size() - 1, attr);
}
userAttributes.put(attributeType, attrList);
}
for (AttributeType optAttr : oc.getOptionalAttributes()) {
String attrName = optAttr.getNameOrOID();
byte[] attrValBytes = null;
NdbBlob blob = null;
if (BackendImpl.blobAttributes.contains(attrName)) {
Map<String, NdbBlob> attr2Blob =
blobMap.get(objectClasses.get(oc));
blob = attr2Blob.get(attrName);
} else {
attrValBytes = ocRs.getStringBytes(attrName);
if (ocRs.wasNull()) {
continue;
}
}
AttributeType attributeType =
DirectoryServer.getAttributeType(
BackendImpl.attrName2LC.get(attrName), true);
List<Attribute> attrList = userAttributes.get(attributeType);
if (attrList == null) {
attrList = new ArrayList<Attribute>();
}
Attribute attr = null;
LinkedHashSet<String> options = null;
Map<Integer, LinkedHashSet<String>> mid2tagMap =
attr2tagMap.get(attrName);
if (mid2tagMap != null) {
options = mid2tagMap.get(mid);
}
if ((options == null) && !attrList.isEmpty()) {
attr = attrList.get(attrList.size() - 1);
}
if (attr == null) {
attrBuilder.setAttributeType(attributeType, attrName);
} else {
attrBuilder = new AttributeBuilder(attr);
}
if (blob != null) {
if (blob.getNull()) {
continue;
}
int len = blob.getLength().intValue();
byte[] buf = new byte[len];
blob.readData(buf, len);
attrBuilder.add(AttributeValues.create(attributeType,
ByteString.wrap(buf)));
} else {
attrBuilder.add(AttributeValues.create(attributeType,
ByteString.wrap(attrValBytes)));
}
// Create or update an attribute.
if (options != null) {
attrBuilder.setOptions(options);
}
attr = attrBuilder.toAttribute();
if (attrList.isEmpty()) {
attrList.add(attr);
} else {
attrList.set(attrList.size() - 1, attr);
}
userAttributes.put(attributeType, attrList);
}
}
if (ocRsIterator.hasNext()) {
ocRs = ocRsIterator.next();
}
}
// Operational attributes.
if (ocRs.next()) {
for (String attrName : BackendImpl.operationalAttributes) {
byte[] attrValBytes = ocRs.getStringBytes(attrName);
if (ocRs.wasNull()) {
continue;
}
AttributeType attributeType =
DirectoryServer.getAttributeType(
BackendImpl.attrName2LC.get(attrName), true);
attrBuilder.setAttributeType(attributeType, attrName);
attrBuilder.add(AttributeValues.create(attributeType,
ByteString.wrap(attrValBytes)));
Attribute attr = attrBuilder.toAttribute();
List<Attribute> attrList = opAttributes.get(attributeType);
if (attrList == null) {
attrList = new ArrayList<Attribute>();
attrList.add(attr);
opAttributes.put(attributeType, attrList);