You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2014/04/09 21:59:27 UTC
svn commit: r1586114 - in /db/derby/code/trunk: ./
java/optional/org/apache/derby/optional/lucene/
Author: rhillegas
Date: Wed Apr 9 19:59:26 2014
New Revision: 1586114
URL: http://svn.apache.org/r1586114
Log:
DERBY-590: Hide doPrivileged() blocks inside private methods, seal derbyoptionaltools.jar, and create more relevant SQLExceptions; commit derby-590-22-aa-cleanupPrivacy.diff.
Modified:
db/derby/code/trunk/build.xml
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1586114&r1=1586113&r2=1586114&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Wed Apr 9 19:59:26 2014
@@ -1608,9 +1608,17 @@
<!-- copy boilerplate common to derby jar files -->
<antcall target="meta-inf-common"/>
+ <manifest file="${derby.jar.dir}/lists/smfoptionaltools.mf">
+ <attribute name="Bundle-Vendor" value="Apache Software Foundation"/>
+ <attribute name="Bundle-Name" value="Apache Derby ${major}.${minor}"/>
+ <attribute name="Bundle-Version" value="${major}.${minor}.${maint}.${changenumber}"/>
+ <attribute name="Bundle-ManifestVersion" value="2"/>
+ <attribute name="Sealed" value="true"/>
+ </manifest>
+
<antcall target="make-locale-classpath-manifest">
<param name="manifest.file" value="${derby.jar.dir}/lists/smfoptionaltools.mf"/>
- <param name="manifest.mode" value="replace"/>
+ <param name="manifest.mode" value="update"/>
</antcall>
<delete file="${derby.jar.dir}/derbyoptionaltools.jar"/>
Modified: 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=1586114&r1=1586113&r2=1586114&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java Wed Apr 9 19:59:26 2014
@@ -24,7 +24,9 @@ package org.apache.derby.optional.lucene
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
+import java.security.AccessController;
import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Timestamp;
@@ -79,15 +81,15 @@ public class LuceneListIndexesVTI extend
DirFilter dirFilter = new DirFilter();
ArrayList<File> allIndexes = new ArrayList<File>();
- File[] schemas = LuceneSupport.listFiles( luceneDir, dirFilter );
+ File[] schemas = listFiles( luceneDir, dirFilter );
if ( schemas != null )
{
for ( File schema : schemas )
{
- File[] tables = LuceneSupport.listFiles( schema, dirFilter );
+ File[] tables = listFiles( schema, dirFilter );
for ( File table : tables )
{
- File[] indexes = LuceneSupport.listFiles( table, dirFilter );
+ File[] indexes = listFiles( table, dirFilter );
for ( File index : indexes )
{
allIndexes.add( index );
@@ -152,13 +154,6 @@ public class LuceneListIndexesVTI extend
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 */
@@ -218,7 +213,7 @@ public class LuceneListIndexesVTI extend
try {
readSchemaTableColumn();
File indexPropertiesFile = LuceneSupport.getIndexPropertiesFile( connection, schema, table, column );
- rowProperties = LuceneSupport.readIndexProperties( indexPropertiesFile );
+ rowProperties = readIndexProperties( indexPropertiesFile );
}
catch (IOException ioe) { throw LuceneSupport.wrap( ioe ); }
catch (PrivilegedActionException pae) { throw LuceneSupport.wrap( pae ); }
@@ -227,4 +222,37 @@ public class LuceneListIndexesVTI extend
return rowProperties;
}
+ /** List files */
+ private static File[] listFiles( final File file, final FileFilter fileFilter )
+ throws IOException, PrivilegedActionException
+ {
+ return AccessController.doPrivileged
+ (
+ new PrivilegedExceptionAction<File[]>()
+ {
+ public File[] run() throws IOException
+ {
+ if ( fileFilter == null ) { return file.listFiles(); }
+ else { return file.listFiles( fileFilter ); }
+ }
+ }
+ );
+ }
+
+ /** Read the index properties file */
+ private static Properties readIndexProperties( final File file )
+ throws IOException, PrivilegedActionException
+ {
+ return AccessController.doPrivileged
+ (
+ new PrivilegedExceptionAction<Properties>()
+ {
+ public Properties run() throws IOException
+ {
+ return LuceneSupport.readIndexPropertiesNoPrivs( file );
+ }
+ }
+ );
+ }
+
}
\ No newline at end of file
Modified: 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=1586114&r1=1586113&r2=1586114&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java Wed Apr 9 19:59:26 2014
@@ -24,7 +24,10 @@ package org.apache.derby.optional.lucene
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
@@ -428,16 +431,16 @@ public class LuceneQueryVTI extends Stri
String indexhome = LuceneSupport.getIndexLocation( _connection, _schema, _table, _column);
File propertiesFile = LuceneSupport.getIndexPropertiesFile( _connection, _schema, _table, _column );
- Properties indexProperties = LuceneSupport.readIndexProperties( propertiesFile );
+ Properties indexProperties = readIndexProperties( propertiesFile );
String analyzerMaker = indexProperties.getProperty( LuceneSupport.ANALYZER_MAKER );
- Analyzer analyzer = LuceneSupport.getAnalyzer( analyzerMaker );
+ Analyzer analyzer = getAnalyzer( analyzerMaker );
vetLuceneVersion( indexProperties.getProperty( LuceneSupport.LUCENE_VERSION ) );
- _indexReader = LuceneSupport.getIndexReader( new File( indexhome.toString() ) );
+ _indexReader = getIndexReader( new File( indexhome.toString() ) );
_searcher = new IndexSearcher(_indexReader);
- QueryParser qp = LuceneSupport.getQueryParser
+ QueryParser qp = getQueryParser
(
_queryParserMaker == null ?
LuceneUtils.class.getName() + ".defaultQueryParser" : _queryParserMaker,
@@ -519,4 +522,97 @@ public class LuceneQueryVTI extends Stri
return ( (columnid > 0) && (columnid <= _maxKeyID) );
}
+ /**
+ * Invoke a static method (possibly supplied by the user) to instantiate a QueryParser.
+ *
+ * @param queryParserMaker Full name of public, static method whicn instantiates a QueryParser given the following arguments.
+ * @param version Lucene version.
+ * @param fieldName Name of field holding the indexed text.
+ * @param analyzer Analyzer used to index the text.
+ */
+ private static QueryParser getQueryParser
+ (
+ final String queryParserMaker,
+ final Version version,
+ final String fieldName,
+ final Analyzer analyzer
+ )
+ throws ClassNotFoundException, IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException, PrivilegedActionException
+ {
+ return AccessController.doPrivileged
+ (
+ new PrivilegedExceptionAction<QueryParser>()
+ {
+ public QueryParser run()
+ throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
+ {
+ int lastDotIdx = queryParserMaker.lastIndexOf( "." );
+ Class<? extends Object> klass = Class.forName( queryParserMaker.substring( 0, lastDotIdx ) );
+ String methodName = queryParserMaker.substring( lastDotIdx + 1, queryParserMaker.length() );
+ Method method = klass.getDeclaredMethod( methodName, Version.class, String.class, Analyzer.class );
+
+ return (QueryParser) method.invoke( null, version, fieldName, analyzer );
+ }
+ }
+ );
+ }
+
+ /**
+ * Returns a Lucene IndexReader, which reads from the indicated Lucene index.
+ *
+ * @param indexHome The directory holding the Lucene index.
+ */
+ private static IndexReader getIndexReader( final File indexHome )
+ throws IOException, PrivilegedActionException
+ {
+ return AccessController.doPrivileged
+ (
+ new PrivilegedExceptionAction<IndexReader>()
+ {
+ public IndexReader run() throws SQLException, IOException
+ {
+ return DirectoryReader.open( FSDirectory.open( indexHome ) );
+ }
+ }
+ );
+ }
+
+ /** Read the index properties file */
+ private static Properties readIndexProperties( final File file )
+ throws IOException, PrivilegedActionException
+ {
+ return AccessController.doPrivileged
+ (
+ new PrivilegedExceptionAction<Properties>()
+ {
+ public Properties run() throws IOException
+ {
+ return LuceneSupport.readIndexPropertiesNoPrivs( file );
+ }
+ }
+ );
+ }
+
+ /**
+ * Invoke a static method (possibly supplied by the user) to instantiate an Analyzer.
+ * The method has no arguments.
+ */
+ private static Analyzer getAnalyzer( final String analyzerMaker )
+ throws ClassNotFoundException, IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException, PrivilegedActionException
+ {
+ return AccessController.doPrivileged
+ (
+ new PrivilegedExceptionAction<Analyzer>()
+ {
+ public Analyzer run()
+ throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
+ {
+ return LuceneSupport.getAnalyzerNoPrivs( analyzerMaker );
+ }
+ }
+ );
+ }
+
}
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java?rev=1586114&r1=1586113&r2=1586114&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java Wed Apr 9 19:59:26 2014
@@ -50,6 +50,7 @@ import java.util.Properties;
import org.apache.derby.iapi.sql.conn.ConnectionUtil;
import org.apache.derby.iapi.sql.dictionary.DataDictionary;
import org.apache.derby.iapi.sql.dictionary.OptionalTool;
+import org.apache.derby.iapi.error.PublicAPI;
import org.apache.derby.iapi.error.StandardException;
import org.apache.derby.iapi.util.IdUtil;
import org.apache.derby.impl.jdbc.EmbedConnection;
@@ -634,7 +635,7 @@ public class LuceneSupport implements Op
/** Turn a StandardException into a SQLException */
public static SQLException sqlException( StandardException se )
{
- return new SQLException( se.getMessage(), se.getSQLState() );
+ return PublicAPI.wrapStandardException( se );
}
/** Wrap an external exception */
@@ -1115,7 +1116,7 @@ public class LuceneSupport implements Op
}
/** Read the index properties file */
- static Properties readIndexProperties( final File file )
+ private static Properties readIndexProperties( final File file )
throws IOException, PrivilegedActionException
{
return AccessController.doPrivileged
@@ -1124,22 +1125,27 @@ public class LuceneSupport implements Op
{
public Properties run() throws IOException
{
- if ( file == null ) { return null; }
- else
- {
- Properties properties = new Properties();
- FileInputStream fis = new FileInputStream( file );
-
- properties.load( fis );
- fis.close();
-
- return properties;
- }
+ return readIndexPropertiesNoPrivs( file );
}
}
);
}
+ /** Read the index properties file */
+ static Properties readIndexPropertiesNoPrivs( File file )
+ throws IOException
+ {
+ if ( file == null ) { return null; }
+
+ Properties properties = new Properties();
+ FileInputStream fis = new FileInputStream( file );
+
+ properties.load( fis );
+ fis.close();
+
+ return properties;
+ }
+
/** Write the index properties file */
private static void writeIndexProperties( final File file, final Properties properties )
throws IOException, PrivilegedActionException
@@ -1550,7 +1556,7 @@ public class LuceneSupport implements Op
* Delete a file. If it's a directory, recursively delete all directories
* and files underneath it first.
*/
- static boolean deleteFile( File file )
+ private static boolean deleteFile( File file )
throws IOException, SQLException, PrivilegedActionException
{
boolean retval = true;
@@ -1566,7 +1572,7 @@ public class LuceneSupport implements Op
}
/** Return true if the file is a directory */
- static boolean isDirectory( final File file )
+ private static boolean isDirectory( final File file )
throws IOException, PrivilegedActionException
{
return AccessController.doPrivileged
@@ -1605,24 +1611,8 @@ public class LuceneSupport implements Op
).booleanValue();
}
- /** Get the timestamp when the file was last modified */
- public static long getLastModified( final File file )
- throws PrivilegedActionException
- {
- return AccessController.doPrivileged
- (
- new PrivilegedExceptionAction<Long>()
- {
- public Long run()
- {
- return file.lastModified();
- }
- }
- ).longValue();
- }
-
/** List files */
- static File[] listFiles( final File file, final FileFilter fileFilter )
+ private static File[] listFiles( final File file, final FileFilter fileFilter )
throws IOException, PrivilegedActionException
{
return AccessController.doPrivileged
@@ -1639,7 +1629,7 @@ public class LuceneSupport implements Op
}
/** Return true if the file exists */
- static boolean fileExists( final File file )
+ private static boolean fileExists( final File file )
throws IOException, PrivilegedActionException
{
return AccessController.doPrivileged
@@ -1809,30 +1799,10 @@ public class LuceneSupport implements Op
}
/**
- * Returns a Lucene IndexReader, which reads from the indicated Lucene index.
- *
- * @param indexHome The directory holding the Lucene index.
- */
- static IndexReader getIndexReader( final File indexHome )
- throws IOException, PrivilegedActionException
- {
- return AccessController.doPrivileged
- (
- new PrivilegedExceptionAction<IndexReader>()
- {
- public IndexReader run() throws SQLException, IOException
- {
- return DirectoryReader.open( FSDirectory.open( indexHome ) );
- }
- }
- );
- }
-
- /**
* Invoke a static method (possibly supplied by the user) to instantiate an Analyzer.
* The method has no arguments.
*/
- static Analyzer getAnalyzer( final String analyzerMaker )
+ private static Analyzer getAnalyzer( final String analyzerMaker )
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException, PrivilegedActionException
{
@@ -1843,51 +1813,26 @@ public class LuceneSupport implements Op
public Analyzer run()
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
{
- int lastDotIdx = analyzerMaker.lastIndexOf( "." );
- Class<? extends Object> klass = Class.forName( analyzerMaker.substring( 0, lastDotIdx ) );
- String methodName = analyzerMaker.substring( lastDotIdx + 1, analyzerMaker.length() );
- Method method = klass.getDeclaredMethod( methodName );
-
- return (Analyzer) method.invoke( null );
+ return getAnalyzerNoPrivs( analyzerMaker );
}
}
);
}
/**
- * Invoke a static method (possibly supplied by the user) to instantiate a QueryParser.
- *
- * @param queryParserMaker Full name of public, static method whicn instantiates a QueryParser given the following arguments.
- * @param version Lucene version.
- * @param fieldName Name of field holding the indexed text.
- * @param analyzer Analyzer used to index the text.
+ * Invoke a static method (possibly supplied by the user) to instantiate an Analyzer.
+ * The method has no arguments.
*/
- static QueryParser getQueryParser
- (
- final String queryParserMaker,
- final Version version,
- final String fieldName,
- final Analyzer analyzer
- )
+ static Analyzer getAnalyzerNoPrivs( String analyzerMaker )
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException,
- NoSuchMethodException, PrivilegedActionException
+ NoSuchMethodException
{
- return AccessController.doPrivileged
- (
- new PrivilegedExceptionAction<QueryParser>()
- {
- public QueryParser run()
- throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
- {
- int lastDotIdx = queryParserMaker.lastIndexOf( "." );
- Class<? extends Object> klass = Class.forName( queryParserMaker.substring( 0, lastDotIdx ) );
- String methodName = queryParserMaker.substring( lastDotIdx + 1, queryParserMaker.length() );
- Method method = klass.getDeclaredMethod( methodName, Version.class, String.class, Analyzer.class );
+ int lastDotIdx = analyzerMaker.lastIndexOf( "." );
+ Class<? extends Object> klass = Class.forName( analyzerMaker.substring( 0, lastDotIdx ) );
+ String methodName = analyzerMaker.substring( lastDotIdx + 1, analyzerMaker.length() );
+ Method method = klass.getDeclaredMethod( methodName );
- return (QueryParser) method.invoke( null, version, fieldName, analyzer );
- }
- }
- );
+ return (Analyzer) method.invoke( null );
}
}