db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1583216 [1/2] - in /db/derby/code/trunk: ./ java/engine/ java/engine/org/apache/derby/catalog/ java/engine/org/apache/derby/impl/ java/engine/org/apache/derby/impl/optional/lucene/ java/engine/org/apache/derby/impl/sql/compile/ java/engine...
Date Sun, 30 Mar 2014 22:23:29 GMT
Author: rhillegas
Date: Sun Mar 30 22:23:28 2014
New Revision: 1583216

URL: http://svn.apache.org/r1583216
Log:
DERBY-590: Move Lucene code to a new directory tree intended for optional code; commit derby-590-11-aa-moveCode.diff.

Added:
    db/derby/code/trunk/java/optional/
    db/derby/code/trunk/java/optional/build.xml   (with props)
    db/derby/code/trunk/java/optional/org/
    db/derby/code/trunk/java/optional/org/apache/
    db/derby/code/trunk/java/optional/org/apache/derby/
    db/derby/code/trunk/java/optional/org/apache/derby/optional/
    db/derby/code/trunk/java/optional/org/apache/derby/optional/api/
    db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java   (with
props)
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
  (with props)
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
  (with props)
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
  (with props)
Removed:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/optional/lucene/
    db/derby/code/trunk/java/engine/org/apache/derby/optional/
Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/engine/build.xml
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
    db/derby/code/trunk/tools/ant/properties/dirs.properties
    db/derby/code/trunk/tools/jar/extraDBMSclasses.properties

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1583216&r1=1583215&r2=1583216&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Sun Mar 30 22:23:28 2014
@@ -48,7 +48,7 @@
 
   <target
       name="buildsource"
-      depends="checkCompilerLevel,init,prebuild,setCompilerProperties,jdbc4stubs,felixStubs,engine,storeless,tools,drda,client,build,versioninfo,localeinfo,binscripts"
+      depends="checkCompilerLevel,init,prebuild,setCompilerProperties,jdbc4stubs,felixStubs,engine,storeless,tools,drda,client,optional,build,versioninfo,localeinfo,binscripts"
       description="Compile the product source (does not build the tests)."
   />
   <target
@@ -621,6 +621,10 @@
     <ant dir="${derby.tools.src.dir}"/>
   </target>
 	
+  <target name="optional" depends="engine">
+    <ant dir="${derby.optional.src.dir}"/>
+  </target>
+	
   <target name="storeless" depends="engine">
   	<ant dir="${derby.storeless.src.dir}"/>
   </target>

Modified: db/derby/code/trunk/java/engine/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/build.xml?rev=1583216&r1=1583215&r2=1583216&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/build.xml (original)
+++ db/derby/code/trunk/java/engine/build.xml Sun Mar 30 22:23:28 2014
@@ -66,7 +66,6 @@
     <ant dir="${derby.engine.dir}/jdbc"/>
     <ant dir="${derby.engine.dir}/osgi"/>
     <ant dir="${derby.engine.dir}/catalog"/>   
-    <ant dir="${derby.engine.dir}/optional"/>
     <ant dir="${derby.engine.dir}/diag"/>
       	<copy todir="${out.dir}/${derby.dir}">
           <fileset dir="${derby.engine.dir}">

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java?rev=1583216&r1=1583215&r2=1583216&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java Sun
Mar 30 22:23:28 2014
@@ -64,7 +64,7 @@ public  class   Java5SystemProcedures
     {
         { "databaseMetaData", "org.apache.derby.impl.tools.optional.DBMDWrapper" },
         { "foreignViews", "org.apache.derby.impl.tools.optional.ForeignDBViews" },
-        { "luceneSupport", "org.apache.derby.impl.optional.lucene.LuceneSupport" },
+        { "luceneSupport", "org.apache.derby.optional.lucene.LuceneSupport" },
         { "optimizerTracing", "org.apache.derby.impl.sql.compile.OptimizerTracer" },
         { "optimizerTracingViews", "org.apache.derby.impl.sql.compile.OptTraceViewer" },
     };

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml?rev=1583216&r1=1583215&r2=1583216&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/build.xml Sun Mar 30 22:23:28 2014
@@ -41,6 +41,5 @@
     <ant dir="${derby.engine.dir}/impl/db"/>
     <ant dir="${derby.engine.dir}/impl/load"/>
     <ant dir="${derby.engine.dir}/impl/jdbc"/>
-    <ant dir="${derby.engine.dir}/impl/optional/lucene"/>
   </target>
 </project>

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java?rev=1583216&r1=1583215&r2=1583216&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
Sun Mar 30 22:23:28 2014
@@ -368,7 +368,7 @@ class StaticMethodCallNode extends Metho
             if (
                 javaClassName.startsWith( "org.apache.derby." ) &&
                 !javaClassName.startsWith( "org.apache.derby.impl.tools.optional." ) &&
-                !javaClassName.startsWith( "org.apache.derby.impl.optional.lucene." ) &&
+                !javaClassName.startsWith( "org.apache.derby.optional.lucene." ) &&
                 !javaClassName.startsWith( "org.apache.derby.vti." )
                 )
             {

Added: db/derby/code/trunk/java/optional/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/build.xml?rev=1583216&view=auto
==============================================================================
--- db/derby/code/trunk/java/optional/build.xml (added)
+++ db/derby/code/trunk/java/optional/build.xml Sun Mar 30 22:23:28 2014
@@ -0,0 +1,87 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to you under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- ==================================================================== -->
+<!--                       Apache Derby build file                        -->
+<!-- ==================================================================== -->
+
+<project default="optional" basedir="../..">
+
+<!-- ==================================================================== -->
+<!--                           Set properties                             -->
+<!-- ==================================================================== -->
+
+  <property name="properties.dir" value="tools/ant/properties"/>
+
+  <!-- User settings -->
+  <property file="${user.home}/ant.properties"/>
+
+  <!-- Significant dirs -->
+  <property file="${properties.dir}/dirs.properties"/>
+
+  <!-- Compiler settings -->
+  <property file="${properties.dir}/defaultcompiler.properties"/>
+  <property file="${properties.dir}/${build.compiler}.properties"/>
+
+  <!-- Parser properties -->
+  <property file="${properties.dir}/parser.properties"/>
+
+  <!-- Compile-time classpath properties files -->
+  <property file="${properties.dir}/extrapath.properties"/>
+  <property file="${properties.dir}/compilepath.properties"/>
+  <property name="cur.dir" value="optional"/>
+
+  <!-- Release and Version info -->
+  <property file="${properties.dir}/release.properties"/>
+
+<!--             ============ Begin Targets ==============                -->
+ 
+  <target name="optional"
+          description="Build Derby optional tools">
+
+    <javac
+      source="1.6"
+      target="1.6"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.optional.src.dir}:${generated.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${java16compile.classpath}"/>
+        <pathelement path="${lucene_core}"/>
+        <pathelement path="${lucene_a_co}"/>
+        <pathelement path="${lucene_qp}"/>
+      </classpath>
+      <include name="${derby.dir}/${cur.dir}/**"/>
+      <compilerarg value="-Xlint:unchecked"/>
+    </javac>
+
+  </target>
+
+<!--             ============= End Targets ==============                -->
+
+<!--             ============= End Project ==============                -->
+
+</project>
+

Propchange: db/derby/code/trunk/java/optional/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java?rev=1583216&view=auto
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java (added)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java Sun Mar
30 22:23:28 2014
@@ -0,0 +1,191 @@
+/*
+
+   Derby - Class org.apache.derby.optional.api.LuceneUtils
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.optional.api;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Locale;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.util.Version;
+
+import org.apache.derby.iapi.sql.conn.ConnectionUtil;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+
+/**
+ * <p>
+ * Utility methods for the Lucene optional tool.
+ * </p>
+ */
+public abstract class LuceneUtils
+{
+    /////////////////////////////////////////////////////////////////
+    //
+    //  CONSTANTS
+    //
+    /////////////////////////////////////////////////////////////////
+
+    /////////////////////////////////////////////////////////////////
+    //
+    //  STATE
+    //
+    /////////////////////////////////////////////////////////////////
+
+    /** Map of Analyzers keyed by language code */
+    private static  HashMap<String,Class<? extends Analyzer>>   _analyzerClasses;
+    static
+    {
+        _analyzerClasses = new HashMap<String,Class<? extends Analyzer>>();
+
+        storeAnalyzerClass( org.apache.lucene.analysis.ar.ArabicAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.hy.ArmenianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.eu.BasqueAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.br.BrazilianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.bg.BulgarianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.ca.CatalanAnalyzer.class );
+        // deprecated, use StandardAnalyzer instead: storeAnalyzerClass( org.apache.lucene.analysis.cn.ChineseAnalyzer.class
);
+        storeAnalyzerClass( org.apache.lucene.analysis.cz.CzechAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.da.DanishAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.nl.DutchAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.en.EnglishAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.fi.FinnishAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.fr.FrenchAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.gl.GalicianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.de.GermanAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.el.GreekAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.hi.HindiAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.hu.HungarianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.id.IndonesianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.ga.IrishAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.it.ItalianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.lv.LatvianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.no.NorwegianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.fa.PersianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.pt.PortugueseAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.ro.RomanianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.ru.RussianAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.es.SpanishAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.sv.SwedishAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.th.ThaiAnalyzer.class );
+        storeAnalyzerClass( org.apache.lucene.analysis.tr.TurkishAnalyzer.class );
+    }
+
+    /////////////////////////////////////////////////////////////////
+    //
+    //  PUBLIC BEHAVIOR
+    //
+    /////////////////////////////////////////////////////////////////
+
+    /** Get the version of the Lucene library on the classpath. */
+    @SuppressWarnings("deprecation")
+    public  static  Version currentVersion()
+    {
+        Version retval = null;
+
+        // the current version is the highest one
+        for ( Version current : Version.values() )
+        {
+            if ( current == Version.LUCENE_CURRENT ) { continue; }
+            
+            if ( retval == null ) { retval = current; }
+            else
+            {
+                if ( current.onOrAfter( retval ) ) { retval = current; }
+            }
+        }
+        
+        return retval;
+    }
+
+    /**
+     * <p>
+     * Get the default Analyzer associated with the database Locale.
+     * </p>
+     */
+    public  static  Analyzer    defaultAnalyzer()
+        throws IllegalAccessException, InstantiationException, InvocationTargetException,
NoSuchMethodException, SQLException
+    {
+        return getAnalyzerForLocale( ConnectionUtil.getCurrentLCC().getDatabase().getLocale()
);
+    }
+    
+    /**
+     * <p>
+     * Get the Analyzer associated with the given Locale.
+     * </p>
+     */
+    public  static  Analyzer    getAnalyzerForLocale( Locale locale )
+        throws IllegalAccessException, InstantiationException, InvocationTargetException,
NoSuchMethodException
+    {
+        String          language = locale.getLanguage();
+
+        Class<? extends Analyzer>   analyzerClass = _analyzerClasses.get( language
);
+        
+        if ( analyzerClass == null )    { return standardAnalyzer(); }
+        else
+        {
+            Constructor<? extends Analyzer> constructor = analyzerClass.getConstructor(
Version.class );
+
+            return constructor.newInstance( currentVersion() );
+        }
+    }
+
+    /**
+     * <p>
+     * Get the StandardAnalyzer for parsing text.
+     * </p>
+     */
+    public  static  Analyzer    standardAnalyzer()
+    {
+        return new StandardAnalyzer( currentVersion() );
+    }
+    
+    /////////////////////////////////////////////////////////////////
+    //
+    //  MINIONS
+    //
+    /////////////////////////////////////////////////////////////////
+
+    /** Store an Analyzer class in the HashMap of Analyzers, keyed by language code */
+    private static  void    storeAnalyzerClass( Class<? extends Analyzer> analyzerClass
)
+    {
+        _analyzerClasses.put( getLanguageCode( analyzerClass ), analyzerClass );
+    }
+
+    /**
+     * <p>
+     * Get the language code for a Lucene Analyzer. Each of the Analyzers
+     * lives in a package whose last leg is the language code.
+     * </p>
+     */
+    private static  String  getLanguageCode( Class<? extends Analyzer> analyzerClass
)
+    {
+        String  className = analyzerClass.getName();
+        String  packageName = className.substring( 0, className.lastIndexOf( "." ) );
+        String  languageCode = packageName.substring( packageName.lastIndexOf( "." ) + 1,
packageName.length() );
+
+        return languageCode;
+    }
+
+}

Propchange: db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java?rev=1583216&view=auto
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
(added)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
Sun Mar 30 22:23:28 2014
@@ -0,0 +1,230 @@
+/*
+
+   Class org.apache.derby.optional.lucene.LuceneListIndexesVTI
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+package org.apache.derby.optional.lucene;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.security.PrivilegedActionException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.apache.derby.shared.common.reference.SQLState;
+import org.apache.derby.vti.StringColumnVTI;
+
+/**
+ * Provides a table interface to the Lucene indexes in this database.
+ * See org.apache.derby.optional.lucene.LuceneSupport.listIndexes.
+ * 
+ */
+public class LuceneListIndexesVTI extends StringColumnVTI
+{
+    private Connection  connection;
+	private File[] indexes;
+	private int row = -1;
+
+    private String      schema;
+    private String      table;
+    private String      column;
+    private Properties  rowProperties;
+
+	/**
+	 * Return a new LuceneListIndexesVTI.
+	 * 
+	 * @throws IOException
+	 */
+	public LuceneListIndexesVTI()
+        throws IOException, PrivilegedActionException, SQLException
+    {
+		super
+            ( new String[]
+                {
+                    "SCHEMANAME",
+                    "TABLENAME",
+                    "COLUMNNAME",
+                    "LASTUPDATED",
+                    "LUCENEVERSION",
+                    "ANALYZER",
+                    "ANALYZERMAKER",
+                }
+              );
+		
+        connection = LuceneSupport.getDefaultConnection();
+		String dir = LuceneSupport.getIndexLocation( connection, null, null, null );
+		
+		File luceneDir = new File(dir);
+        DirFilter   dirFilter = new DirFilter();
+        ArrayList<File> allIndexes = new ArrayList<File>();
+
+        File[]  schemas = LuceneSupport.listFiles( luceneDir, dirFilter );
+        if ( schemas != null )
+        {
+            for ( File schema : schemas )
+            {
+                File[]  tables = LuceneSupport.listFiles( schema, dirFilter );
+                for ( File table : tables )
+                {
+                    File[]  indexes = LuceneSupport.listFiles( table, dirFilter );
+                    for ( File index : indexes )
+                    {
+                        allIndexes.add( index );
+                    }
+                }
+            }
+        }
+
+        indexes = new File[ allIndexes.size() ];
+        allIndexes.toArray( indexes );
+	}
+
+	public void close() throws SQLException
+    {
+		connection = null;
+        indexes = null;
+        schema = null;
+        table = null;
+        column = null;
+        rowProperties = null;
+	}
+
+	public boolean next() throws SQLException
+    {
+        schema = null;
+        table = null;
+        column = null;
+        rowProperties = null;
+        
+		row++;
+		if (row < indexes.length) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * columns:
+	 * 1 == id
+	 * 2 == schema
+	 * 3 == table
+	 * 4 == column name
+	 * 5 == last modified
+	 */
+	protected String getRawColumn( int col ) throws SQLException
+    {
+        readSchemaTableColumn();
+        
+        switch( col )
+        {
+        case 1: return schema;
+        case 2: return table;
+        case 3: return column;
+        case 5: return getProperty( LuceneSupport.LUCENE_VERSION );
+        case 6: return getProperty( LuceneSupport.ANALYZER );
+        case 7: return getProperty( LuceneSupport.ANALYZER_MAKER );
+        default:
+            throw LuceneSupport.newSQLException
+                (
+                 SQLState.LANG_INVALID_COLUMN_POSITION,
+                 new Integer( col ),
+                 new Integer( getColumnCount() )
+                 );
+        }
+            /*
+            try {
+                DateFormat df = DateFormat.getDateTimeInstance();
+                return df.format( LuceneSupport.getLastModified( columnDir ) );
+            }
+            catch (Exception e) { throw LuceneSupport.wrap( e ); }
+            */
+	}
+
+    /** Get the timestamp value of the 1-based column id */
+    public  Timestamp   getTimestamp( int col ) throws SQLException
+    {
+        if ( col != 4 )
+        {
+            throw LuceneSupport.newSQLException
+                (
+                 SQLState.LANG_INVALID_COLUMN_POSITION,
+                 new Integer( col ),
+                 new Integer( getColumnCount() )
+                 );
+        }
+
+        try {
+            long    timestampMillis = Long.parseLong( getProperty( LuceneSupport.UPDATE_TIMESTAMP
) );
+
+            return new Timestamp( timestampMillis );
+        }
+        catch (NumberFormatException nfe) { throw LuceneSupport.wrap( nfe ); }
+    }
+    
+	
+    public  static  class   DirFilter   implements  FileFilter
+    {
+        public  boolean accept( File file ) { return file.isDirectory(); }
+    }
+
+    /** Fill in the schema, table, and column names */
+    private void    readSchemaTableColumn()
+        throws SQLException
+    {
+        if ( column != null ) { return; }
+        
+        File    columnDir = indexes[ row ];
+        column = columnDir.getName();
+        File    tableDir = columnDir.getParentFile();
+        table = tableDir.getName();
+        File    schemaDir = tableDir.getParentFile();
+        schema = schemaDir.getName();
+    }
+
+    /** get the string value of a property from the row properties */
+    private String  getProperty( String key )
+        throws SQLException
+    {
+        return getRowProperties().getProperty( key );
+    }
+    
+    /** get the properties of the current row */
+    private Properties  getRowProperties()
+        throws SQLException
+    {
+        if ( rowProperties == null )
+        {
+            try {
+                readSchemaTableColumn();
+                File    indexPropertiesFile = LuceneSupport.getIndexPropertiesFile( connection,
schema, table, column );
+                rowProperties = LuceneSupport.readIndexProperties( indexPropertiesFile );
+            }
+            catch (IOException ioe) { throw LuceneSupport.wrap( ioe ); }
+            catch (PrivilegedActionException pae) { throw LuceneSupport.wrap( pae ); }
+        }
+
+        return rowProperties;
+    }
+
+}
\ No newline at end of file

Propchange: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java?rev=1583216&view=auto
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
(added)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
Sun Mar 30 22:23:28 2014
@@ -0,0 +1,480 @@
+/*
+
+   Class org.apache.derby.optional.lucene.LuceneQueryVTI
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+package org.apache.derby.optional.lucene;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedActionException;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Properties;
+
+import org.apache.derby.shared.common.reference.SQLState;
+import org.apache.derby.optional.api.LuceneUtils;
+import org.apache.derby.vti.RestrictedVTI;
+import org.apache.derby.vti.Restriction;
+import org.apache.derby.vti.Restriction.ColumnQualifier;
+import org.apache.derby.vti.StringColumnVTI;
+import org.apache.derby.vti.VTIContext;
+import org.apache.derby.vti.VTITemplate;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.apache.lucene.queryparser.classic.QueryParser;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.TopScoreDocCollector;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.Version;
+
+/**
+ * A VTI that provides the results of Lucene queries and
+ * associated Lucene assigned document ids. 
+ * 
+ * This is intended for use through the provided query function
+ * LuceneSupport.luceneQuery.
+ * 
+ */
+public class LuceneQueryVTI extends StringColumnVTI
+{
+    /////////////////////////////////////////////////////////////////////
+    //
+    //  CONSTANTS
+    //
+    /////////////////////////////////////////////////////////////////////
+
+    public  static  final   String  TEXT_FIELD_NAME = "luceneTextField";
+
+    /////////////////////////////////////////////////////////////////////
+    //
+    //  STATE
+    //
+    /////////////////////////////////////////////////////////////////////
+
+    // constructor args
+    private Connection  _connection;
+    private String  _queryText;
+    private double  _rankCutoff;
+
+    private String      _schema;
+    private String      _table;
+    private String      _column;
+    
+	private ScoreDoc[] _hits;
+	private IndexReader _indexReader;
+	private IndexSearcher _searcher;
+	private int _hitIndex = -1;
+
+    // ids (1-based positions) of the columns
+    private int _minKeyID;
+    private int _maxKeyID;
+    private int _docIDColumnID;
+    private int _rankColumnID;
+	
+    /////////////////////////////////////////////////////////////////////
+    //
+    //  CONSTRUCTOR
+    //
+    /////////////////////////////////////////////////////////////////////
+
+	/**
+	 * Return a LuceneQueryVTI based on the given Lucene query text.
+	 */
+	LuceneQueryVTI
+        (
+         String queryText,
+         double rankCutoff
+         )
+        throws SQLException
+    {
+        super( null );
+        
+        _connection = LuceneSupport.getDefaultConnection();
+        _queryText = queryText;
+        _rankCutoff = rankCutoff;
+	}
+
+    /////////////////////////////////////////////////////////////////////
+    //
+    //  StringColumnVTI BEHAVIOR
+    //
+    /////////////////////////////////////////////////////////////////////
+
+	/**
+	 * columns:
+	 * 1 ... $_maxKeyID == key columns
+	 * $_maxKeyID + 1 == lucene docId
+	 * $_maxKeyID + 2 == lucene rank
+	 */
+	public String getRawColumn( int columnid ) throws SQLException
+    {
+		try {
+            ScoreDoc    scoreDoc = getScoreDoc();
+            int     docID = scoreDoc.doc;
+            
+			if ( isKeyID( columnid ) ) { return _searcher.doc( docID ).get( getColumnName( columnid
) ); }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+	}
+
+    /** Handle float columns */
+    public  float   getFloat( int columnid )    throws SQLException
+    {
+		try {
+            if ( columnid == _rankColumnID ) { return getScoreDoc().score; }
+			else if ( isKeyID( columnid ) )
+            {
+                Number  number = getNumberValue( columnid );
+
+                if ( number == null ) { return 0; }
+                else { return number.floatValue(); }
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+
+    /** Handle double columns */
+    public  double   getDouble( int columnid )    throws SQLException
+    {
+		try {
+			if ( isKeyID( columnid ) )
+            {
+                Number  number = getNumberValue( columnid );
+
+                if ( number == null ) { return 0; }
+                else { return number.doubleValue(); }
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+
+    /** Handle bytecolumns */
+    public  byte    getByte( int columnid )  throws SQLException
+    {
+        return (byte) getInt( columnid );
+    }
+
+    /** Handle short columns */
+    public  short getShort( int columnid )  throws SQLException
+    {
+        return (short) getInt( columnid );
+    }
+
+    /** Handle long columns */
+    public  long    getLong( int columnid )  throws SQLException
+    {
+		try {
+            ScoreDoc    scoreDoc = getScoreDoc();
+            int     docID = scoreDoc.doc;
+			if ( isKeyID( columnid ) )
+            {
+                Number  number = getNumberValue( columnid );
+
+                if ( number == null ) { return 0; }
+                else { return number.longValue(); }
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+    
+    /** Handle Date columns */
+    public  Date    getDate( int columnid )  throws SQLException
+    {
+		try {
+            ScoreDoc    scoreDoc = getScoreDoc();
+            int     docID = scoreDoc.doc;
+			if ( isKeyID( columnid ) )
+            {
+                Number  number = getNumberValue( columnid );
+
+                if ( number == null ) { return null; }
+                else { return new Date( number.longValue() ); }
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+    
+    /** Handle Time columns */
+    public  Time    getTime( int columnid )  throws SQLException
+    {
+		try {
+            ScoreDoc    scoreDoc = getScoreDoc();
+            int     docID = scoreDoc.doc;
+			if ( isKeyID( columnid ) )
+            {
+                Number  number = getNumberValue( columnid );
+
+                if ( number == null ) { return null; }
+                else { return new Time( number.longValue() ); }
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+    
+    /** Handle Timestamp columns */
+    public  Timestamp    getTimestamp( int columnid )  throws SQLException
+    {
+		try {
+            ScoreDoc    scoreDoc = getScoreDoc();
+            int     docID = scoreDoc.doc;
+			if ( isKeyID( columnid ) )
+            {
+                Number  number = getNumberValue( columnid );
+
+                if ( number == null ) { return null; }
+                else { return new Timestamp( number.longValue() ); }
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+    
+    /** Handle integer columns */
+    public  int getInt( int columnid )  throws SQLException
+    {
+		try {
+            ScoreDoc    scoreDoc = getScoreDoc();
+            int     docID = scoreDoc.doc;
+			if ( columnid == _docIDColumnID ) { return docID; }
+			else if ( isKeyID( columnid ) )
+            {
+                Number  number = getNumberValue( columnid );
+
+                if ( number == null ) { return 0; }
+                else { return number.intValue(); }
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+    private Number getNumberValue( int columnid ) throws IOException
+    {
+        IndexableField  field = _searcher.doc( getScoreDoc().doc ).getField( getColumnName(
columnid ) );
+
+        if ( field == null ) { return null; }
+        else
+        {
+            Number  number = field.numericValue();
+
+            return number;
+        }
+    }
+
+    /** Handle byte columns */
+    public  byte[]  getBytes( int columnid ) throws SQLException
+    {
+		try {
+            ScoreDoc    scoreDoc = getScoreDoc();
+            int     docID = scoreDoc.doc;
+            
+			if ( isKeyID( columnid ) )
+            {
+                Document    doc = _searcher.doc( docID );
+                String          columnName = getColumnName( columnid );
+
+                if ( columnName != null )
+                {
+                    BytesRef        ref = doc.getBinaryValue( columnName );
+
+                    if ( ref != null )  { return ref.bytes; }
+                }
+
+                return null;
+            }
+			else { throw invalidColumnPosition( columnid ); }
+		}
+        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+    }
+
+    private SQLException    invalidColumnPosition( int columnid )
+    {
+        return LuceneSupport.newSQLException
+            (
+             SQLState.LANG_INVALID_COLUMN_POSITION,
+             new Integer( columnid ),
+             new Integer( getColumnCount() )
+             );
+    }
+
+    private ScoreDoc    getScoreDoc()   throws IOException
+    {
+        return _hits[ _hitIndex ];
+    }
+	
+	public boolean next()
+        throws SQLException
+    {
+        if ( _schema == null ) { initScan(); }
+        
+		_hitIndex++;
+		if (_hitIndex < _hits.length) {
+			return true;
+		}
+
+        closeReader();
+		return false;
+	}
+	
+	public void close()
+        throws SQLException
+    {
+		_hits = null;
+		_hitIndex = 0;
+
+        closeReader();
+	}
+	
+	/**
+	 * Be sure to close the Lucene IndexReader
+	 */
+	protected void finalize()
+    {
+		try {
+			if ( _indexReader != null ) { _indexReader.close(); }
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	private void closeReader()
+        throws SQLException
+    {
+		if ( _indexReader == null ) { return; }
+        
+		try {
+			_indexReader.close();
+		}
+        catch (IOException e) { throw LuceneSupport.wrap( e ); }
+        finally
+        {
+            _indexReader = null;
+        }
+	}
+	
+    /////////////////////////////////////////////////////////////////////
+    //
+    //  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 );
+
+            _rankColumnID = getColumnCount();
+            _docIDColumnID = _rankColumnID - 1;
+            _maxKeyID = _docIDColumnID - 1;
+            _minKeyID = 1;
+            
+            // make sure the user has SELECT privilege on all relevant columns of the underlying
table
+            vetPrivileges();
+        
+            String          indexhome = LuceneSupport.getIndexLocation( _connection, _schema,
_table, _column);
+            File            propertiesFile = LuceneSupport.getIndexPropertiesFile( _connection,
_schema, _table, _column );
+            Properties  indexProperties = LuceneSupport.readIndexProperties( propertiesFile
);
+            String          analyzerMaker = indexProperties.getProperty( LuceneSupport.ANALYZER_MAKER
);
+            Analyzer    analyzer = LuceneSupport.getAnalyzer( analyzerMaker );
+				
+            _indexReader = LuceneSupport.getIndexReader( new File( indexhome.toString() )
);
+            _searcher = new IndexSearcher(_indexReader);
+
+            QueryParser qp = new QueryParser( LuceneUtils.currentVersion(), TEXT_FIELD_NAME,
analyzer );
+            Query luceneQuery = qp.parse( _queryText );
+            TopScoreDocCollector tsdc = TopScoreDocCollector.create(1000, true);
+            if ( _rankCutoff != 0 ) {
+                tsdc = TopScoreDocCollector.create(1000, new ScoreDoc(0, (float) _rankCutoff
), true);
+            }
+            _searcher.search(luceneQuery, tsdc);
+            TopDocs topdocs = tsdc.topDocs();
+            _hits = topdocs.scoreDocs;
+        }
+        catch (IOException ioe) { throw LuceneSupport.wrap( ioe ); }
+        catch (ParseException pe) { throw LuceneSupport.wrap( pe ); }
+        catch (PrivilegedActionException pae) { throw LuceneSupport.wrap( pae ); }
+        catch (ClassNotFoundException cnfe) { throw LuceneSupport.wrap( cnfe ); }
+        catch (IllegalAccessException iae) { throw LuceneSupport.wrap( iae ); }
+        catch (InvocationTargetException ite) { throw LuceneSupport.wrap( ite ); }
+        catch (NoSuchMethodException nsme) { throw LuceneSupport.wrap( nsme ); }
+    }
+
+    /**
+     * <p>
+     * Make sure that the user has SELECT privilege on the text column and on all
+     * the key columns of the underlying table.
+     */
+    private void    vetPrivileges() throws SQLException
+    {
+        StringBuilder   buffer = new StringBuilder();
+        int _maxKeyID = getColumnCount() - 2;
+
+        buffer.append( "select " );
+        for ( int i = 0; i < _maxKeyID; i++ )
+        {
+            if ( i > 0 ) { buffer.append( ", " ); }
+            buffer.append( getColumnName( i + 1 ) );
+        }
+        buffer.append( ", " + _column );
+        buffer.append( " from " + LuceneSupport.makeTableName( _schema, _table ) );
+        buffer.append( " where 1=2" );
+
+        _connection.prepareStatement( buffer.toString() ).executeQuery().close();
+    }
+
+    /** Return true if the 1-based column ID is the ID of a key column */
+    private boolean isKeyID( int columnid )
+    {
+        return ( (columnid > 0) && (columnid <= _maxKeyID) );
+    }
+    
+}

Propchange: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message