Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: Implements a service for managing a Hazelcast cluster member
4
 *  Copyright: 2013 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Leinfelder
7
 * 
8
 *   '$Author: leinfelder $'
9
 *     '$Date: 2013-07-03 00:28:54 -0700 (Wed, 03 Jul 2013) $'
10
 * '$Revision: 7842 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26
package edu.ucsb.nceas.metacat.index;
27

    
28
import java.sql.SQLException;
29
import java.util.Collection;
30
import java.util.Map;
31
import java.util.Set;
32
import java.util.TreeMap;
33

    
34
import org.apache.log4j.Logger;
35
import org.dataone.service.types.v1.Identifier;
36

    
37
import com.hazelcast.core.MapLoader;
38
import com.hazelcast.core.MapStore;
39

    
40
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
41

    
42
public class IndexEventMapStore implements MapStore<Identifier, IndexEvent>, MapLoader<Identifier, IndexEvent> {
43

    
44
	private Logger logMetacat = Logger.getLogger(IndexEventMapStore.class);
45

    
46
	/**
47
	 * The map store/loader methods
48
	 */
49
	
50
	@Override
51
	public IndexEvent load(Identifier identifier) {
52
		try {
53
			return IndexEventDAO.getInstance().get(identifier);
54
		} catch (SQLException e) {
55
			logMetacat.error(e.getMessage(), e);
56
		}
57
		return null;
58
	}
59

    
60
	@Override
61
	public Map<Identifier, IndexEvent> loadAll(Collection<Identifier> identifiers) {
62
		Map<Identifier, IndexEvent> eventMap = new TreeMap<Identifier, IndexEvent>();
63
		for (Identifier identifier: identifiers) {
64
			IndexEvent event = null;
65
			try {
66
				event = IndexEventDAO.getInstance().get(identifier);
67
				eventMap.put(identifier, event);
68
			} catch (SQLException e) {
69
				logMetacat.error(e.getMessage(), e);
70
			}
71
		}
72
		return eventMap;
73
	}
74

    
75
	@Override
76
	public Set<Identifier> loadAllKeys() {
77
		try {
78
			return IndexEventDAO.getInstance().getAllIdentifiers();
79
		} catch (SQLException e) {
80
			logMetacat.error(e.getMessage(), e);
81
		}
82
		return null;
83
	}
84

    
85
	@Override
86
	public void delete(Identifier identifier) {
87
		try {
88
			IndexEventDAO.getInstance().remove(identifier);
89
		} catch (SQLException e) {
90
			logMetacat.error(e.getMessage(), e);
91
		}		
92
	}
93

    
94
	@Override
95
	public void deleteAll(Collection<Identifier> identifiers) {
96
		for (Identifier identifier: identifiers) {
97
			try {
98
				IndexEventDAO.getInstance().remove(identifier);
99
			} catch (SQLException e) {
100
				logMetacat.error(e.getMessage(), e);
101
			}
102
		}
103
	}
104

    
105
	@Override
106
	public void store(Identifier identifier, IndexEvent event) {
107
		try {
108
			IndexEventDAO.getInstance().add(event);
109
		} catch (SQLException e) {
110
			logMetacat.error(e.getMessage(), e);
111
		}		
112
	}
113

    
114
	@Override
115
	public void storeAll(Map<Identifier, IndexEvent> indexEventMap) {
116
		for (IndexEvent event: indexEventMap.values()) {
117
			try {
118
				IndexEventDAO.getInstance().add(event);
119
			} catch (SQLException e) {
120
				logMetacat.error(e.getMessage(), e);
121
			}
122
		}
123
	}
124
	
125
}
(2-2/4)