try
{
ClassEntry entry=(ClassEntry)classMap.get( indexedClass);
if ( entry==null)
// Very rare circumstance; other thread snatched class from us
throw new ObjectStoreException( "Class "+indexedClass.getName()
+" was removed.");
if ( indexMap.get( indexName)!=null)
throw new IndexExistsException( indexName);
listModified=true;
if ( entry.indexStreams==null)
{
entry.indexStreams=new StreamPair(
manager.createDiskAllocator(entry.fileName + "i", DirectoryAllocator.FAVORED_CHUNK_SIZE, 0),
factory.getCustomizer( indexedClass));
}
IndexEntry indexEntry=Index.createIndexEntry( indexName,
keyGen, descending, unique, entriesPerPage, manager, entry.indexStreams);
entry.indices.add( indexEntry);
indexMap.put( indexName, indexEntry.index);
// Add existing objects to index
for ( Iterator i=entry.objectStreams.allocator.iterator();
i.hasNext(); )
{
Object nextObject=entry.objectStreams.readObjectWithPrefix(
((Integer)i.next()).intValue());
indexEntry.index.insertKey( new DAKey(
entry.objectStreams.first, entry.objectStreams.second),
nextObject);
}
}
catch ( ClassNotFoundException cnfe)
{
throw new ObjectStoreException(
"Class not found while creating index", cnfe);
}
catch ( DiskAllocatorException dae)
{
throw new ObjectStoreException( "Error adding index: ", dae);
}
catch ( IOException ioe)
{
throw new ObjectStoreException( "I/O Error adding index: ", ioe);
}
finally
{
classChangeLock.leaveCritical();
}