use of org.apache.derby.vti.VTIContext in project derby by apache.
the class LuceneQueryVTI method initScan.
// ///////////////////////////////////////////////////////////////////
//
// MINIONS
//
// ///////////////////////////////////////////////////////////////////
/**
* Initialize the metadata and scan
*/
private void initScan() throws SQLException {
try {
// read the execution context for this AwareVTI
VTIContext context = getContext();
_schema = context.vtiSchema();
String[] nameParts = LuceneSupport.decodeFunctionName(context.vtiTable());
_table = nameParts[LuceneSupport.TABLE_PART];
_column = nameParts[LuceneSupport.COLUMN_PART];
// divine the column names
VTITemplate.ColumnDescriptor[] returnColumns = getReturnTableSignature(_connection);
String[] columnNames = new String[returnColumns.length];
for (int i = 0; i < returnColumns.length; i++) {
columnNames[i] = returnColumns[i].columnName;
}
setColumnNames(columnNames);
_scoreColumnID = getColumnCount();
_docIDColumnID = _scoreColumnID - 1;
_maxKeyID = _docIDColumnID - 1;
_minKeyID = 1;
// make sure the user has SELECT privilege on all relevant columns of the underlying table
vetPrivileges();
String delimitedColumnName = LuceneSupport.delimitID(_column);
DerbyLuceneDir derbyLuceneDir = LuceneSupport.getDerbyLuceneDir(_connection, _schema, _table, delimitedColumnName);
StorageFile propertiesFile = LuceneSupport.getIndexPropertiesFile(derbyLuceneDir);
Properties indexProperties = readIndexProperties(propertiesFile);
String indexDescriptorMaker = indexProperties.getProperty(LuceneSupport.INDEX_DESCRIPTOR_MAKER);
LuceneIndexDescriptor indexDescriptor = getIndexDescriptor(indexDescriptorMaker);
Analyzer analyzer = indexDescriptor.getAnalyzer();
QueryParser qp = indexDescriptor.getQueryParser();
vetLuceneVersion(indexProperties.getProperty(LuceneSupport.LUCENE_VERSION));
_indexReader = getIndexReader(derbyLuceneDir);
_searcher = new IndexSearcher(_indexReader);
Query luceneQuery = qp.parse(_queryText);
TopScoreDocCollector tsdc = TopScoreDocCollector.create(_windowSize, true);
if (_scoreCeiling != null) {
tsdc = TopScoreDocCollector.create(_windowSize, new ScoreDoc(0, _scoreCeiling), true);
}
searchAndScore(luceneQuery, tsdc);
} catch (IOException ioe) {
throw ToolUtilities.wrap(ioe);
} catch (ParseException pe) {
throw ToolUtilities.wrap(pe);
} catch (PrivilegedActionException pae) {
throw ToolUtilities.wrap(pae);
}
}
use of org.apache.derby.vti.VTIContext in project derby by apache.
the class VTIResultSet method openCore.
//
// ResultSet interface (leftover from NoPutResultSet)
//
/**
* Sets state to 'open'.
*
* @exception StandardException thrown if activation closed.
*/
public void openCore() throws StandardException {
beginTime = getCurrentTimeMillis();
if (SanityManager.DEBUG)
SanityManager.ASSERT(!isOpen, "VTIResultSet already open");
isOpen = true;
numOpens++;
/* We need to Instantiate the user's ResultSet on the each open since
* there is no way to close and then reopen a java.sql.ResultSet.
* For Version 2 VTIs, we may be able to skip instantiated their
* PreparedStatement here.
*/
try {
if (version2) {
userPS = (PreparedStatement) constructor.invoke(activation);
if (userPS instanceof org.apache.derby.vti.Pushable) {
org.apache.derby.vti.Pushable p = (org.apache.derby.vti.Pushable) userPS;
if (referencedColumns != null) {
pushedProjection = p.pushProjection(this, getProjectedColList());
}
}
if (userPS instanceof org.apache.derby.vti.IQualifyable) {
org.apache.derby.vti.IQualifyable q = (org.apache.derby.vti.IQualifyable) userPS;
q.setQualifiers(this, pushedQualifiers);
}
fastPath = userPS instanceof IFastPath ? (IFastPath) userPS : null;
if (isTarget && userPS instanceof DeferModification && activation.getConstantAction() instanceof UpdatableVTIConstantAction) {
UpdatableVTIConstantAction constants = (UpdatableVTIConstantAction) activation.getConstantAction();
((DeferModification) userPS).modificationNotify(constants.statementType, constants.deferred);
}
if ((fastPath != null) && fastPath.executeAsFastPath())
;
else
userVTI = userPS.executeQuery();
/* Save off the target VTI */
if (isTarget) {
activation.setTargetVTI(userVTI);
}
} else {
userVTI = (ResultSet) constructor.invoke(activation);
if (userVTI instanceof RestrictedVTI) {
RestrictedVTI restrictedVTI = (RestrictedVTI) userVTI;
restrictedVTI.initScan(vtiProjection, cloneRestriction(activation));
}
if (userVTI instanceof AwareVTI) {
AwareVTI awareVTI = (AwareVTI) userVTI;
awareVTI.setContext(new VTIContext(vtiSchema, vtiName, activation.getLanguageConnectionContext().getStatementContext().getStatementText()));
}
}
// Set up the nullablity of the runtime columns, may be delayed
setNullableColumnList();
} catch (Throwable t) {
throw StandardException.unexpectedUserException(t);
}
openTime += getElapsedMillis(beginTime);
}
Aggregations