001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.search; 029 030import org.opencms.db.CmsPublishedResource; 031 032import java.util.ArrayList; 033import java.util.List; 034 035/** 036 * A collection of resources for the incremental update of a search index.<p> 037 * 038 * @since 6.0.1 039 */ 040public class CmsSearchIndexUpdateData { 041 042 /** The indexer of this update collection. */ 043 private I_CmsIndexer m_indexer; 044 045 /** List of <code>{@link org.opencms.db.CmsPublishedResource}</code> instances that must be deleted. */ 046 private List<CmsPublishedResource> m_resourcesToDelete; 047 048 /** List of <code>{@link org.opencms.db.CmsPublishedResource}</code> instances that must be updated. */ 049 private List<CmsPublishedResource> m_resourcesToUpdate; 050 051 /** The search index source of this update collection. */ 052 private CmsSearchIndexSource m_source; 053 054 /** 055 * Creates a new instance of an update collection.<p> 056 * 057 * @param source the search index source of this update collection 058 * @param indexer the indexer of this update collection 059 */ 060 public CmsSearchIndexUpdateData(CmsSearchIndexSource source, I_CmsIndexer indexer) { 061 062 m_source = source; 063 m_indexer = indexer; 064 m_resourcesToDelete = new ArrayList<CmsPublishedResource>(); 065 m_resourcesToUpdate = new ArrayList<CmsPublishedResource>(); 066 } 067 068 /** 069 * Adds the given resource to the resources that must be deleted from the search index.<p> 070 * 071 * @param resource the resource to add 072 */ 073 public void addResourceToDelete(CmsPublishedResource resource) { 074 075 m_resourcesToDelete.add(resource); 076 } 077 078 /** 079 * Adds the given resource to the resources that must be updated in the search index.<p> 080 * 081 * @param resource the resource to add 082 */ 083 public void addResourceToUpdate(CmsPublishedResource resource) { 084 085 m_resourcesToUpdate.add(resource); 086 } 087 088 /** 089 * Returns the indexer of this update collection.<p> 090 * 091 * @return the indexer of this update collection 092 */ 093 public I_CmsIndexer getIndexer() { 094 095 return m_indexer; 096 } 097 098 /** 099 * Returns the list of <code>{@link org.opencms.db.CmsPublishedResource}</code> instances that must be deleted.<p> 100 * 101 * @return the list of <code>{@link org.opencms.db.CmsPublishedResource}</code> instances that must be deleted 102 */ 103 public List<CmsPublishedResource> getResourcesToDelete() { 104 105 return m_resourcesToDelete; 106 } 107 108 /** 109 * Returns the list of <code>{@link org.opencms.db.CmsPublishedResource}</code> instances that must be updated.<p> 110 * 111 * @return the list of <code>{@link org.opencms.db.CmsPublishedResource}</code> instances that must be updated 112 */ 113 public List<CmsPublishedResource> getResourcesToUpdate() { 114 115 return m_resourcesToUpdate; 116 } 117 118 /** 119 * Returns the search index source of this update collection.<p> 120 * 121 * @return the search index source of this update collection 122 */ 123 public CmsSearchIndexSource getSource() { 124 125 return m_source; 126 } 127 128 /** 129 * Returns <code>true</code> if this collections contains resources to delete.<p> 130 * 131 * @return <code>true</code> if this collections contains resources to delete 132 */ 133 public boolean hasResourcesToDelete() { 134 135 return !m_resourcesToDelete.isEmpty(); 136 } 137 138 /** 139 * Returns <code>true</code> if this collections contains resources to update.<p> 140 * 141 * @return <code>true</code> if this collections contains resources to update 142 */ 143 public boolean hasResourceToUpdate() { 144 145 return !m_resourcesToUpdate.isEmpty(); 146 } 147 148 /** 149 * Returns <code>true</code> if this collections contains no resources to update or delete.<p> 150 * 151 * @return <code>true</code> if this collections contains no resources to update or delete 152 */ 153 public boolean isEmpty() { 154 155 return m_resourcesToDelete.isEmpty() && m_resourcesToUpdate.isEmpty(); 156 } 157}