Search in sources :

Example 1 with VTIContext

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);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) VTIContext(org.apache.derby.vti.VTIContext) Query(org.apache.lucene.search.Query) TopScoreDocCollector(org.apache.lucene.search.TopScoreDocCollector) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) Properties(java.util.Properties) Analyzer(org.apache.lucene.analysis.Analyzer) ScoreDoc(org.apache.lucene.search.ScoreDoc) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) LuceneIndexDescriptor(org.apache.derby.optional.api.LuceneIndexDescriptor) StorageFile(org.apache.derby.io.StorageFile) ParseException(org.apache.lucene.queryparser.classic.ParseException)

Example 2 with VTIContext

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);
}
Also used : DeferModification(org.apache.derby.vti.DeferModification) AwareVTI(org.apache.derby.vti.AwareVTI) VTIContext(org.apache.derby.vti.VTIContext) RestrictedVTI(org.apache.derby.vti.RestrictedVTI) IFastPath(org.apache.derby.vti.IFastPath)

Aggregations

VTIContext (org.apache.derby.vti.VTIContext)2 IOException (java.io.IOException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Properties (java.util.Properties)1 StorageFile (org.apache.derby.io.StorageFile)1 LuceneIndexDescriptor (org.apache.derby.optional.api.LuceneIndexDescriptor)1 AwareVTI (org.apache.derby.vti.AwareVTI)1 DeferModification (org.apache.derby.vti.DeferModification)1 IFastPath (org.apache.derby.vti.IFastPath)1 RestrictedVTI (org.apache.derby.vti.RestrictedVTI)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Query (org.apache.lucene.search.Query)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1 TopScoreDocCollector (org.apache.lucene.search.TopScoreDocCollector)1