- remove artifact in index if artifact no longer exists in the file system - added tests git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@590622 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.0-beta-4
@@ -34,7 +34,7 @@ public class LuceneRepositoryContentIndexFactoryStub | |||
{ | |||
public RepositoryContentIndex createBytecodeIndex( ManagedRepositoryConfiguration repository ) | |||
{ | |||
{ | |||
// TODO Auto-generated method stub | |||
return new LuceneRepositoryContentIndexStub(); | |||
} |
@@ -126,5 +126,12 @@ public class LuceneRepositoryContentIndexStub | |||
// TODO Auto-generated method stub | |||
} | |||
public void deleteRecord( LuceneRepositoryContentRecord record ) | |||
throws RepositoryIndexException | |||
{ | |||
// TODO Auto-generated method stub | |||
} | |||
} |
@@ -22,19 +22,27 @@ package org.apache.maven.archiva.consumers.lucene; | |||
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; | |||
import org.apache.maven.archiva.consumers.ConsumerException; | |||
import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer; | |||
import org.apache.maven.archiva.indexer.RepositoryContentIndex; | |||
import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; | |||
import org.apache.maven.archiva.indexer.RepositoryIndexException; | |||
import org.apache.maven.archiva.indexer.bytecode.BytecodeRecord; | |||
import org.apache.maven.archiva.indexer.filecontent.FileContentRecord; | |||
import org.apache.maven.archiva.indexer.hashcodes.HashcodesRecord; | |||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||
import org.apache.maven.archiva.repository.ManagedRepositoryContent; | |||
import org.apache.maven.archiva.repository.RepositoryContentFactory; | |||
import org.apache.maven.archiva.repository.RepositoryException; | |||
import java.io.File; | |||
import java.util.List; | |||
/** | |||
* LuceneCleanupRemoveIndexedConsumer | |||
* | |||
* LuceneCleanupRemoveIndexedConsumer | |||
* | |||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> | |||
* @version $Id$ | |||
* | |||
* @plexus.component role="org.apache.maven.archiva.consumers.DatabaseCleanupConsumer" | |||
* role-hint="not-present-remove-indexed" | |||
* instantiation-strategy="per-lookup" | |||
* role-hint="not-present-remove-indexed" instantiation-strategy="per-lookup" | |||
*/ | |||
public class LuceneCleanupRemoveIndexedConsumer | |||
extends AbstractMonitoredConsumer | |||
@@ -50,6 +58,16 @@ public class LuceneCleanupRemoveIndexedConsumer | |||
*/ | |||
private String description; | |||
/** | |||
* @plexus.requirement role-hint="lucene" | |||
*/ | |||
private RepositoryContentIndexFactory repoIndexFactory; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private RepositoryContentFactory repoFactory; | |||
public void beginScan() | |||
{ | |||
// TODO Auto-generated method stub | |||
@@ -71,8 +89,41 @@ public class LuceneCleanupRemoveIndexedConsumer | |||
public void processArchivaArtifact( ArchivaArtifact artifact ) | |||
throws ConsumerException | |||
{ | |||
// TODO Auto-generated method stub | |||
try | |||
{ | |||
ManagedRepositoryContent repoContent = | |||
repoFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() ); | |||
File file = new File( repoContent.getRepoRoot(), repoContent.toPath( artifact ) ); | |||
if( !file.exists() ) | |||
{ | |||
RepositoryContentIndex bytecodeIndex = repoIndexFactory.createBytecodeIndex( repoContent.getRepository() ); | |||
RepositoryContentIndex hashcodesIndex = repoIndexFactory.createHashcodeIndex( repoContent.getRepository() ); | |||
RepositoryContentIndex fileContentIndex = | |||
repoIndexFactory.createFileContentIndex( repoContent.getRepository() ); | |||
FileContentRecord fileContentRecord = new FileContentRecord(); | |||
fileContentRecord.setFilename( repoContent.toPath( artifact ) ); | |||
fileContentIndex.deleteRecord( fileContentRecord ); | |||
HashcodesRecord hashcodesRecord = new HashcodesRecord(); | |||
hashcodesRecord.setArtifact( artifact ); | |||
hashcodesIndex.deleteRecord( hashcodesRecord ); | |||
BytecodeRecord bytecodeRecord = new BytecodeRecord(); | |||
bytecodeRecord.setArtifact( artifact ); | |||
bytecodeIndex.deleteRecord( bytecodeRecord ); | |||
} | |||
} | |||
catch ( RepositoryException e ) | |||
{ | |||
throw new ConsumerException( "Can't run index cleanup consumer: " + e.getMessage() ); | |||
} | |||
catch ( RepositoryIndexException e ) | |||
{ | |||
throw new ConsumerException( e.getMessage() ); | |||
} | |||
} | |||
public String getDescription() | |||
@@ -90,4 +141,13 @@ public class LuceneCleanupRemoveIndexedConsumer | |||
return false; | |||
} | |||
public void setRepositoryIndexFactory( RepositoryContentIndexFactory repoIndexFactory ) | |||
{ | |||
this.repoIndexFactory = repoIndexFactory; | |||
} | |||
public void setRepositoryContentFactory( RepositoryContentFactory repoFactory ) | |||
{ | |||
this.repoFactory = repoFactory; | |||
} | |||
} |
@@ -0,0 +1,129 @@ | |||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||
<!-- | |||
~ 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. | |||
--> | |||
<configuration> | |||
<version>1</version> | |||
<repositories> | |||
<repository> | |||
<id>test-repo</id> | |||
<name>Test Repository</name> | |||
<url>file://src/test/resources/test-repo</url> | |||
<layout>default</layout> | |||
<releases>true</releases> | |||
<snapshots>true</snapshots> | |||
<indexed>true</indexed> | |||
<refreshCronExpression>0 0 * * ?</refreshCronExpression> | |||
<daysOlder>0</daysOlder> | |||
<retentionCount>2</retentionCount> | |||
</repository> | |||
</repositories> | |||
<proxyConnectors/> | |||
<networkProxies> | |||
<networkProxy> | |||
<id>example</id> | |||
<protocol>http</protocol> | |||
<host>proxy.mycompany.com</host> | |||
<port>8080</port> | |||
<username>myself</username> | |||
<password>mypass</password> | |||
</networkProxy> | |||
</networkProxies> | |||
<repositoryScanning> | |||
<fileTypes> | |||
<fileType> | |||
<id>artifacts</id> | |||
<patterns> | |||
<pattern>**/*.pom</pattern> | |||
<pattern>**/*.jar</pattern> | |||
<pattern>**/*.ear</pattern> | |||
<pattern>**/*.war</pattern> | |||
</patterns> | |||
</fileType> | |||
<fileType> | |||
<id>indexable-content</id> | |||
<patterns> | |||
<pattern>**/*.txt</pattern> | |||
<pattern>**/*.TXT</pattern> | |||
</patterns> | |||
</fileType> | |||
<fileType> | |||
<id>auto-remove</id> | |||
<patterns> | |||
<pattern>**/*.bak</pattern> | |||
<pattern>**/*~</pattern> | |||
<pattern>**/*-</pattern> | |||
</patterns> | |||
</fileType> | |||
<fileType> | |||
<id>ignored</id> | |||
<patterns> | |||
<pattern>**/.htaccess</pattern> | |||
<pattern>**/KEYS</pattern> | |||
<pattern>**/*.rb</pattern> | |||
<pattern>**/*.sh</pattern> | |||
<pattern>**/.svn/**</pattern> | |||
<pattern>**/.DAV/**</pattern> | |||
</patterns> | |||
</fileType> | |||
</fileTypes> | |||
<knownContentConsumers> | |||
<knownContentConsumer>update-db-artifact</knownContentConsumer> | |||
<knownContentConsumer>create-missing-checksums</knownContentConsumer> | |||
<knownContentConsumer>update-db-repository-metadata</knownContentConsumer> | |||
<knownContentConsumer>validate-checksum</knownContentConsumer> | |||
<knownContentConsumer>validate-signature</knownContentConsumer> | |||
<knownContentConsumer>index-content</knownContentConsumer> | |||
<knownContentConsumer>auto-remove</knownContentConsumer> | |||
<knownContentConsumer>auto-rename</knownContentConsumer> | |||
<knownContentConsumer>repository-purge</knownContentConsumer> | |||
</knownContentConsumers> | |||
<invalidContentConsumers> | |||
<invalidContentConsumer>update-db-bad-content</invalidContentConsumer> | |||
</invalidContentConsumers> | |||
</repositoryScanning> | |||
<databaseScanning> | |||
<cronExpression>0 0 * * ?</cronExpression> | |||
<unprocessedConsumers> | |||
<unprocessedConsumer>index-artifact</unprocessedConsumer> | |||
<unprocessedConsumer>update-db-project</unprocessedConsumer> | |||
<unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> | |||
<unprocessedConsumer>index-archive-toc</unprocessedConsumer> | |||
<unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> | |||
<unprocessedConsumer>index-public-methods</unprocessedConsumer> | |||
</unprocessedConsumers> | |||
<cleanupConsumers> | |||
<cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> | |||
<cleanupConsumer>not-present-remove-db-project</cleanupConsumer> | |||
<cleanupConsumer>not-present-remove-indexed</cleanupConsumer> | |||
</cleanupConsumers> | |||
</databaseScanning> | |||
<webapp> | |||
<ui> | |||
<showFindArtifacts>true</showFindArtifacts> | |||
<appletFindEnabled>true</appletFindEnabled> | |||
</ui> | |||
</webapp> | |||
</configuration> |
@@ -0,0 +1,77 @@ | |||
package org.apache.maven.archiva.consumers.lucene; | |||
/* | |||
* 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. | |||
*/ | |||
import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer; | |||
import org.apache.maven.archiva.model.ArchivaArtifact; | |||
import org.apache.maven.archiva.model.ArchivaArtifactModel; | |||
import org.codehaus.plexus.PlexusTestCase; | |||
/** | |||
* LuceneCleanupRemoveIndexedConsumerTest | |||
* | |||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> | |||
* @version | |||
*/ | |||
public class LuceneCleanupRemoveIndexedConsumerTest | |||
extends PlexusTestCase | |||
{ | |||
private DatabaseCleanupConsumer luceneCleanupRemoveIndexConsumer; | |||
public void setUp() | |||
throws Exception | |||
{ | |||
super.setUp(); | |||
luceneCleanupRemoveIndexConsumer = (DatabaseCleanupConsumer) | |||
lookup( DatabaseCleanupConsumer.class, "lucene-cleanup" ); | |||
} | |||
public void testIfArtifactExists() | |||
throws Exception | |||
{ | |||
ArchivaArtifact artifact = createArtifact( | |||
"org.apache.maven.archiva", "archiva-lucene-cleanup", "1.0", "jar" ); | |||
luceneCleanupRemoveIndexConsumer.processArchivaArtifact( artifact ); | |||
} | |||
public void testIfArtifactDoesNotExist() | |||
throws Exception | |||
{ | |||
ArchivaArtifact artifact = createArtifact( | |||
"org.apache.maven.archiva", "deleted-artifact", "1.0", "jar" ); | |||
luceneCleanupRemoveIndexConsumer.processArchivaArtifact( artifact ); | |||
} | |||
private ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String type ) | |||
{ | |||
ArchivaArtifactModel model = new ArchivaArtifactModel(); | |||
model.setGroupId( groupId ); | |||
model.setArtifactId( artifactId ); | |||
model.setVersion( version ); | |||
model.setType( type ); | |||
model.setRepositoryId( "test-repo" ); | |||
return new ArchivaArtifact( model ); | |||
} | |||
} |
@@ -0,0 +1,55 @@ | |||
package org.apache.maven.archiva.consumers.lucene.stubs; | |||
/* | |||
* 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. | |||
*/ | |||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.maven.archiva.indexer.RepositoryContentIndex; | |||
import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; | |||
import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentIndex; | |||
/** | |||
* LuceneRepositoryContenIndexFactoryStub | |||
* | |||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> | |||
* @version | |||
*/ | |||
public class LuceneRepositoryContentIndexFactoryStub | |||
implements RepositoryContentIndexFactory | |||
{ | |||
public RepositoryContentIndex createBytecodeIndex( ManagedRepositoryConfiguration repository ) | |||
{ | |||
// TODO Auto-generated method stub | |||
return new LuceneRepositoryContentIndexStub(); | |||
} | |||
public RepositoryContentIndex createFileContentIndex( ManagedRepositoryConfiguration repository ) | |||
{ | |||
// TODO Auto-generated method stub | |||
return new LuceneRepositoryContentIndexStub(); | |||
} | |||
public RepositoryContentIndex createHashcodeIndex( ManagedRepositoryConfiguration repository ) | |||
{ | |||
// TODO Auto-generated method stub | |||
return new LuceneRepositoryContentIndexStub(); | |||
} | |||
} |
@@ -0,0 +1,145 @@ | |||
package org.apache.maven.archiva.consumers.lucene.stubs; | |||
/* | |||
* 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. | |||
*/ | |||
import java.io.File; | |||
import java.util.Collection; | |||
import junit.framework.Assert; | |||
import org.apache.lucene.analysis.Analyzer; | |||
import org.apache.lucene.queryParser.QueryParser; | |||
import org.apache.lucene.search.Searchable; | |||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.maven.archiva.indexer.RepositoryContentIndex; | |||
import org.apache.maven.archiva.indexer.RepositoryIndexException; | |||
import org.apache.maven.archiva.indexer.RepositoryIndexSearchException; | |||
import org.apache.maven.archiva.indexer.lucene.LuceneEntryConverter; | |||
import org.apache.maven.archiva.indexer.lucene.LuceneRepositoryContentRecord; | |||
/** | |||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> | |||
* @version | |||
*/ | |||
public class LuceneRepositoryContentIndexStub | |||
implements RepositoryContentIndex | |||
{ | |||
public void deleteRecords( Collection records ) | |||
throws RepositoryIndexException | |||
{ | |||
// TODO Auto-generated method stub | |||
Assert.assertEquals( 2, records.size() ); | |||
} | |||
public boolean exists() | |||
throws RepositoryIndexException | |||
{ | |||
// TODO Auto-generated method stub | |||
return false; | |||
} | |||
public Collection getAllRecordKeys() | |||
throws RepositoryIndexException | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public Analyzer getAnalyzer() | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public LuceneEntryConverter getEntryConverter() | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public String getId() | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public File getIndexDirectory() | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public QueryParser getQueryParser() | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public ManagedRepositoryConfiguration getRepository() | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public Searchable getSearchable() | |||
throws RepositoryIndexSearchException | |||
{ | |||
// TODO Auto-generated method stub | |||
return null; | |||
} | |||
public void indexRecords( Collection records ) | |||
throws RepositoryIndexException | |||
{ | |||
// TODO Auto-generated method stub | |||
} | |||
public void modifyRecord( LuceneRepositoryContentRecord record ) | |||
throws RepositoryIndexException | |||
{ | |||
// TODO Auto-generated method stub | |||
} | |||
public void modifyRecords( Collection records ) | |||
throws RepositoryIndexException | |||
{ | |||
// TODO Auto-generated method stub | |||
} | |||
public void deleteRecord( LuceneRepositoryContentRecord record ) | |||
throws RepositoryIndexException | |||
{ | |||
Assert.assertNotNull( record ); | |||
// fail since the record to be deleted should only be the deleted-artifact-1.0.jar | |||
// according to the tests | |||
if( record.getPrimaryKey().equals( | |||
"org/apache/maven/archiva/archiva-lucene-cleanup/1.0/archiva-lucene-cleanup-1.0.jar" ) && | |||
record.getPrimaryKey().equals( "org.apache.maven.archiva:archiva-lucene-cleanup:1.0:jar" ) ) | |||
{ | |||
Assert.fail(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,78 @@ | |||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||
<!-- | |||
~ 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. | |||
--> | |||
<component-set> | |||
<components> | |||
<component> | |||
<role>org.apache.maven.archiva.consumers.DatabaseCleanupConsumer</role> | |||
<role-hint>lucene-cleanup</role-hint> | |||
<implementation>org.apache.maven.archiva.consumers.lucene.LuceneCleanupRemoveIndexedConsumer</implementation> | |||
<requirements> | |||
<requirement> | |||
<role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role> | |||
<role-hint>lucene-cleanup</role-hint> | |||
<field-name>repoIndexFactory</field-name> | |||
</requirement> | |||
<requirement> | |||
<role>org.apache.maven.archiva.repository.RepositoryContentFactory</role> | |||
</requirement> | |||
</requirements> | |||
</component> | |||
<component> | |||
<role>org.apache.maven.archiva.repository.RepositoryContentFactory</role> | |||
<implementation>org.apache.maven.archiva.repository.RepositoryContentFactory</implementation> | |||
<requirements> | |||
<requirement> | |||
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> | |||
<role-hint>lucene-cleanup</role-hint> | |||
</requirement> | |||
</requirements> | |||
</component> | |||
<component> | |||
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> | |||
<role-hint>lucene-cleanup</role-hint> | |||
<implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> | |||
<requirements> | |||
<requirement> | |||
<role>org.codehaus.plexus.registry.Registry</role> | |||
<role-hint>lucene-cleanup</role-hint> | |||
</requirement> | |||
</requirements> | |||
</component> | |||
<component> | |||
<role>org.codehaus.plexus.registry.Registry</role> | |||
<role-hint>lucene-cleanup</role-hint> | |||
<implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation> | |||
<configuration> | |||
<properties> | |||
<xml fileName="${basedir}/src/test/conf/repository-manager.xml" | |||
config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/> | |||
</properties> | |||
</configuration> | |||
</component> | |||
<component> | |||
<role>org.apache.maven.archiva.indexer.RepositoryContentIndexFactory</role> | |||
<implementation>org.apache.maven.archiva.consumers.lucene.stubs.LuceneRepositoryContentIndexFactoryStub</implementation> | |||
<role-hint>lucene-cleanup</role-hint> | |||
</component> | |||
</components> | |||
</component-set> |
@@ -80,6 +80,15 @@ public interface RepositoryContentIndex | |||
*/ | |||
void deleteRecords( Collection records ) | |||
throws RepositoryIndexException; | |||
/** | |||
* Delete a record from the index. Simply ignore the request any did not exist. | |||
* | |||
* @param record the record to be deleted | |||
* @throws RepositoryIndexException if there is a problem removing the record | |||
*/ | |||
void deleteRecord( LuceneRepositoryContentRecord record ) | |||
throws RepositoryIndexException; | |||
/** | |||
* Retrieve all primary keys of records in the index. |
@@ -234,6 +234,38 @@ public class LuceneRepositoryContentIndex | |||
} | |||
} | |||
public void deleteRecord( LuceneRepositoryContentRecord record ) | |||
throws RepositoryIndexException | |||
{ | |||
synchronized( repository ) | |||
{ | |||
if ( exists() ) | |||
{ | |||
IndexReader indexReader = null; | |||
try | |||
{ | |||
indexReader = IndexReader.open( indexLocation ); | |||
if ( record != null ) | |||
{ | |||
Term term = new Term( LuceneDocumentMaker.PRIMARY_KEY, record.getPrimaryKey() ); | |||
indexReader.deleteDocuments( term ); | |||
} | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RepositoryIndexException( "Error deleting document: " + e.getMessage(), e ); | |||
} | |||
finally | |||
{ | |||
closeQuietly( indexReader ); | |||
} | |||
} | |||
} | |||
} | |||
public Collection getAllRecordKeys() | |||
throws RepositoryIndexException | |||
{ |