Project

General

Profile

« Previous | Next » 

Revision 6395

added HazelCast MapStore and MapLoader implementation for SystemMetadata

View differences:

src/edu/ucsb/nceas/metacat/dataone/hazelcast/SystemMetadataMap.java
1
package edu.ucsb.nceas.metacat.dataone.hazelcast;
2

  
3
import java.sql.SQLException;
4
import java.util.Collection;
5
import java.util.Map;
6
import java.util.Set;
7
import java.util.TreeMap;
8
import java.util.TreeSet;
9

  
10
import org.dataone.service.types.v1.Identifier;
11
import org.dataone.service.types.v1.ObjectInfo;
12
import org.dataone.service.types.v1.ObjectList;
13
import org.dataone.service.types.v1.SystemMetadata;
14

  
15
import com.hazelcast.core.MapLoader;
16
import com.hazelcast.core.MapStore;
17

  
18
import edu.ucsb.nceas.metacat.IdentifierManager;
19
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
20
import edu.ucsb.nceas.metacat.shared.ServiceException;
21
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
22

  
23
/**
24
 * Storage implementation for Hazelcast System Metadata
25
 * @author leinfelder
26
 *
27
 */
28
public class SystemMetadataMap implements MapStore<Identifier, SystemMetadata>, MapLoader<Identifier, SystemMetadata> {
29

  
30
	@Override
31
	public void delete(Identifier arg0) {
32
		// we do not delete system metadata
33
	}
34

  
35
	@Override
36
	public void deleteAll(Collection<Identifier> arg0) {
37
		// we do not delete system metadata	
38
	}
39

  
40
	@Override
41
	public void store(Identifier pid, SystemMetadata sm) {
42
		try {
43
			if (!IdentifierManager.getInstance().identifierExists(pid.getValue())) {
44
				IdentifierManager.getInstance().createSystemMetadata(sm);
45
			} else {
46
				IdentifierManager.getInstance().updateSystemMetadata(sm);
47
			}
48
		} catch (McdbDocNotFoundException e) {
49
			// TODO Auto-generated catch block
50
			e.printStackTrace();
51
		}
52
	}
53

  
54
	@Override
55
	public void storeAll(Map<Identifier, SystemMetadata> map) {
56
		for (Identifier key: map.keySet()) {
57
			store(key, map.get(key));
58
		}
59
	}
60

  
61
	@Override
62
	public SystemMetadata load(Identifier pid) {
63
		SystemMetadata sm = null;
64
		try {
65
			sm = IdentifierManager.getInstance().getSystemMetadata(pid.getValue());
66
		} catch (McdbDocNotFoundException e) {
67
			// TODO Auto-generated catch block
68
			e.printStackTrace();
69
		}
70
		return sm;
71
	}
72

  
73
	@Override
74
	public Map<Identifier, SystemMetadata> loadAll(Collection<Identifier> keys) {
75
		Map<Identifier, SystemMetadata> map = new TreeMap<Identifier, SystemMetadata>();
76
		for (Identifier key: keys) {
77
			SystemMetadata value = load(key);
78
			map.put(key, value);
79
		}
80
		return map;
81
	}
82

  
83
	@Override
84
	public Set<Identifier> loadAllKeys() {
85
		Set<Identifier> pids = new TreeSet<Identifier>();
86
		try {
87
			ObjectList ol = IdentifierManager.getInstance().querySystemMetadata(
88
					null, //startTime, 
89
					null, //endTime, 
90
					null, //objectFormatId, 
91
					false, //replicaStatus, 
92
					0, //start, 
93
					-1 //count
94
					);
95
			for (ObjectInfo o: ol.getObjectInfoList()) {
96
				Identifier pid = o.getIdentifier();
97
				pids.add(pid);
98
			}
99
		} catch (PropertyNotFoundException e) {
100
			// TODO Auto-generated catch block
101
			e.printStackTrace();
102
		} catch (ServiceException e) {
103
			// TODO Auto-generated catch block
104
			e.printStackTrace();
105
		} catch (SQLException e) {
106
			// TODO Auto-generated catch block
107
			e.printStackTrace();
108
		}
109
		
110
		return pids;
111
	}
112

  
113
}
0 114

  

Also available in: Unified diff