use of org.teiid.core.index.IEntryResult in project teiid by teiid.
the class SimpleIndexUtil method addContinuationRecords.
private static IEntryResult[] addContinuationRecords(final Index index, final IEntryResult[] partialResults) throws IOException {
final int blockSize = RecordFactory.INDEX_RECORD_BLOCK_SIZE;
IEntryResult[] results = partialResults;
for (int i = 0; i < results.length; i++) {
IEntryResult partialResult = results[i];
char[] word = partialResult.getWord();
// If this IEntryResult is not continued on another record then skip to the next result
if (word.length < blockSize || word[blockSize - 1] != MetadataConstants.RECORD_TYPE.RECORD_CONTINUATION) {
continue;
}
// Extract the UUID from the IEntryResult to use when creating the prefix string
String objectID = RecordFactory.extractUUIDString(partialResult);
String patternStr = // $NON-NLS-1$
"" + MetadataConstants.RECORD_TYPE.RECORD_CONTINUATION + word[0] + IndexConstants.RECORD_STRING.RECORD_DELIMITER + objectID + IndexConstants.RECORD_STRING.RECORD_DELIMITER;
// Query the index file for any continuation records
IEntryResult[] continuationResults = index.queryEntries(patternStr.toCharArray(), true);
// If found the continued records then join to the original result and stop searching
if (continuationResults != null && continuationResults.length > 0) {
results[i] = RecordFactory.joinEntryResults(partialResult, continuationResults, blockSize);
}
}
return results;
}
use of org.teiid.core.index.IEntryResult 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));
}
}
}
use of org.teiid.core.index.IEntryResult in project teiid by teiid.
the class BlocksIndexInput method queryEntriesPrefixedBy.
public IEntryResult[] queryEntriesPrefixedBy(char[] prefix) throws IOException {
open();
int blockLoc = summary.getFirstBlockLocationForPrefix(prefix);
if (blockLoc < 0)
return null;
IEntryResult[] entries = new IEntryResult[5];
int count = 0;
while (blockLoc >= 0) {
IndexBlock block = getIndexBlock(summary.getBlockNum(blockLoc));
block.reset();
boolean found = false;
WordEntry entry = new WordEntry();
while (block.nextEntry(entry)) {
if (CharOperation.prefixEquals(prefix, entry.getWord(), true)) {
if (count == entries.length) {
System.arraycopy(entries, 0, entries = new IEntryResult[count * 2], 0, count);
}
entries[count++] = new EntryResult(entry.getWord(), entry.getRefs());
found = true;
} else {
if (found)
break;
}
}
/* consider next block ? */
blockLoc = summary.getNextBlockLocationForPrefix(prefix, blockLoc);
}
if (count == 0)
return null;
if (count != entries.length) {
System.arraycopy(entries, 0, entries = new IEntryResult[count], 0, count);
}
return entries;
}
use of org.teiid.core.index.IEntryResult in project teiid by teiid.
the class BlocksIndexInput method queryEntriesPrefixedBy.
/**
* Overloaded the method in BlocksIndexInput to allow a user to specify if the
* query should be case sensitive.
*/
public IEntryResult[] queryEntriesPrefixedBy(char[] prefix, boolean isCaseSensitive) throws IOException {
open();
int blockLoc = summary.getFirstBlockLocationForPrefix(prefix);
if (blockLoc < 0)
return null;
IEntryResult[] entries = new IEntryResult[5];
int count = 0;
while (blockLoc >= 0) {
IndexBlock block = getIndexBlock(summary.getBlockNum(blockLoc));
block.reset();
boolean found = false;
WordEntry entry = new WordEntry();
while (block.nextEntry(entry)) {
if (CharOperation.prefixEquals(prefix, entry.getWord(), isCaseSensitive)) {
if (count == entries.length) {
System.arraycopy(entries, 0, entries = new IEntryResult[count * 2], 0, count);
}
entries[count++] = new EntryResult(entry.getWord(), entry.getRefs());
found = true;
} else {
if (found)
break;
}
}
/* consider next block ? */
blockLoc = summary.getNextBlockLocationForPrefix(prefix, blockLoc);
}
if (count == 0)
return null;
if (count != entries.length) {
System.arraycopy(entries, 0, entries = new IEntryResult[count], 0, count);
}
return entries;
}
use of org.teiid.core.index.IEntryResult in project teiid by teiid.
the class BlocksIndexInput method queryEntriesMatching.
/**
* Overloaded the method in BlocksIndexInput to allow a user to specify if the
* query should be case sensitive.
* @param pattern
* @param isCaseSensitive
* @return
* @throws IOException
*/
public IEntryResult[] queryEntriesMatching(char[] pattern, boolean isCaseSensitive) throws IOException {
open();
if (pattern == null || pattern.length == 0)
return null;
int[] blockNums = null;
int firstStar = indexOf('*', pattern);
switch(firstStar) {
case -1:
WordEntry entry = getEntry(pattern);
if (entry == null)
return null;
return new IEntryResult[] { new EntryResult(entry.getWord(), entry.getRefs()) };
case 0:
blockNums = summary.getAllBlockNums();
break;
default:
char[] prefix = new char[firstStar];
System.arraycopy(pattern, 0, prefix, 0, firstStar);
blockNums = summary.getBlockNumsForPrefix(prefix);
}
if (blockNums == null || blockNums.length == 0)
return null;
IEntryResult[] entries = new IEntryResult[5];
int count = 0;
for (int i = 0, max = blockNums.length; i < max; i++) {
IndexBlock block = getIndexBlock(blockNums[i]);
block.reset();
WordEntry entry = new WordEntry();
while (block.nextEntry(entry)) {
// Switch argument order to fix bug in BlocksIndexInput
if (CharOperation.match(pattern, entry.getWord(), isCaseSensitive)) {
if (count == entries.length) {
System.arraycopy(entries, 0, entries = new IEntryResult[count * 2], 0, count);
}
entries[count++] = new EntryResult(entry.getWord(), entry.getRefs());
}
}
}
if (count != entries.length) {
System.arraycopy(entries, 0, entries = new IEntryResult[count], 0, count);
}
return entries;
}
Aggregations