Search in sources :

Example 1 with Index

use of org.teiid.internal.core.index.Index in project teiid by teiid.

the class IndexMetadataRepository method loadAll.

// there are multiple threads trying to load this, since the initial index lading is not
// optimized for multi-thread loading this locking to sync will work
private synchronized void loadAll(Collection<Datatype> systemDatatypes, Map<String, ? extends VDBResource> resources) throws IOException {
    if (this.loaded) {
        return;
    }
    ArrayList<Index> tmp = new ArrayList<Index>();
    for (VDBResource f : resources.values()) {
        if (f.getName().endsWith(VDBResources.INDEX_EXT)) {
            Index index = new Index(f);
            index.setDoCache(true);
            tmp.add(index);
        }
    }
    for (Index index : tmp) {
        try {
            IEntryResult[] results = SimpleIndexUtil.queryIndex(new Index[] { index }, new char[0], true, true, false);
            recordFactory.getMetadataRecord(results);
        } catch (TeiidException e) {
            throw new TeiidRuntimeException(RuntimeMetadataPlugin.Event.TEIID80000, e);
        }
    }
    // force close, since we cached the index files
    for (Index index : tmp) {
        index.close();
    }
    Map<String, AbstractMetadataRecord> uuidToRecord = getByType(MetadataConstants.RECORD_TYPE.DATATYPE);
    if (systemDatatypes != null) {
        for (Datatype datatype : systemDatatypes) {
            uuidToRecord.put(datatype.getUUID(), datatype);
        }
    }
    this.loaded = true;
    // associate the annotation/extension metadata
    for (Map<String, AbstractMetadataRecord> map : allRecords.values()) {
        for (AbstractMetadataRecord metadataRecord : map.values()) {
            String uuid = metadataRecord.getUUID();
            metadataRecord.setAnnotation(this.annotationCache.get(uuid));
            metadataRecord.setProperties(this.extensionCache.get(uuid));
        }
    }
}
Also used : IEntryResult(org.teiid.core.index.IEntryResult) ArrayList(java.util.ArrayList) Index(org.teiid.internal.core.index.Index) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Aggregations

ArrayList (java.util.ArrayList)1 TeiidException (org.teiid.core.TeiidException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 IEntryResult (org.teiid.core.index.IEntryResult)1 Index (org.teiid.internal.core.index.Index)1