private static final String SEPARATOR_STRING = "+";
@SuppressWarnings("rawtypes")
public static Object buildId(PersistenceContext app, String entityName, String idString) {
DatabaseSession session = app.getJpaSession();
ClassDescriptor descriptor = app.getDescriptor(entityName);
List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings();
List<SortableKey> pkIndices = new ArrayList<SortableKey>();
int index = 0;
int multitenantPKMappings = 0;
for (DatabaseMapping mapping: pkMappings){
if (mapping.isMultitenantPrimaryKeyMapping()){
multitenantPKMappings++;
} else {
pkIndices.add(new SortableKey(mapping, index));
index++;
}
}
Collections.sort(pkIndices);
// Handle composite key in map
Object[] keyElements = new Object[pkMappings.size() - multitenantPKMappings];
StringTokenizer tokenizer = new StringTokenizer(idString, SEPARATOR_STRING);
int tokens = tokenizer.countTokens();
if (tokens + multitenantPKMappings != pkMappings.size()){
throw new RuntimeException("Failed, incorrect number of keys values");
}
index = 0;
Iterator<SortableKey> iterator = pkIndices.iterator();
while (tokenizer.hasMoreTokens()){
SortableKey key = iterator.next();
String token = tokenizer.nextToken();
DatabaseMapping mapping = key.getMapping();
Class attributeClasification = mapping.getAttributeClassification();
if (attributeClasification == null) {
if ((mapping.getFields() != null) && (!mapping.getFields().isEmpty())) {
attributeClasification = mapping.getFields().get(0).getType();
}
}
Object idValue = session.getPlatform().getConversionManager().convertObject(token, attributeClasification);
keyElements[key.getIndex()] = idValue;
index++;
}
if (descriptor.hasCMPPolicy()) {