Revision 6415
Added by rnahf about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/hazelcast/ObjectPathMapLoader.java | ||
---|---|---|
1 | 1 |
package edu.ucsb.nceas.metacat.dataone.hazelcast; |
2 | 2 |
|
3 |
import java.sql.SQLException; |
|
3 | 4 |
import java.util.Collection; |
4 | 5 |
import java.util.Collections; |
5 | 6 |
import java.util.HashSet; |
... | ... | |
12 | 13 |
|
13 | 14 |
import com.hazelcast.core.MapLoader; |
14 | 15 |
|
16 |
import edu.ucsb.nceas.metacat.DBUtil; |
|
15 | 17 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
16 | 18 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
17 | 19 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
... | ... | |
28 | 30 |
*/ |
29 | 31 |
public class ObjectPathMapLoader implements MapLoader<Identifier, String> { |
30 | 32 |
private static IdentifierManager im; |
33 |
private static DBUtil dbUtil; |
|
31 | 34 |
private static String dataPath; |
32 | 35 |
private static String metadataPath; |
33 | 36 |
|
... | ... | |
45 | 48 |
e.printStackTrace(); |
46 | 49 |
} |
47 | 50 |
im = IdentifierManager.getInstance(); |
51 |
dbUtil = new DBUtil(); |
|
48 | 52 |
} |
49 | 53 |
|
50 | 54 |
|
... | ... | |
53 | 57 |
* the data. The doctype value for metadata can vary, but for data |
54 | 58 |
* is always 'BIN', so using a simple if-then-else to separate |
55 | 59 |
*/ |
56 |
private String pathToDocid(String docid, String doctype) {
|
|
60 |
private String pathToDocid(String docid) throws SQLException {
|
|
57 | 61 |
|
58 |
if (doctype.equals("BIN")) { |
|
59 |
return dataPath + FileUtil.getFS() + docid; |
|
62 |
String revType = dbUtil.getCurrentRevisionAndDocTypeForGivenDocument(docid); |
|
63 |
String[] rt = revType.split(";"); |
|
64 |
String docType = rt[1]; |
|
65 |
String revision = rt[0]; |
|
66 |
if (docType.equals("BIN")) { |
|
67 |
return dataPath + FileUtil.getFS() + docid + "." + revision; |
|
60 | 68 |
} else { |
61 |
return metadataPath + FileUtil.getFS() + docid; |
|
69 |
return metadataPath + FileUtil.getFS() + docid + "." + revision;
|
|
62 | 70 |
} |
63 | 71 |
} |
64 | 72 |
|
65 | 73 |
|
66 | 74 |
/** |
67 | 75 |
* Implementation of hazelcast MapLoader interface method. |
76 |
* for the provided Identifier (as key), looks up the localID |
|
77 |
* and revision |
|
68 | 78 |
*/ |
69 |
|
|
70 |
public String load(Identifier key) {
|
|
71 |
|
|
79 |
@Override |
|
80 |
public String load(Identifier key) |
|
81 |
{ |
|
72 | 82 |
String docid = null; |
73 |
Hashtable<String,Object> docinfo = null;
|
|
83 |
String path = null;
|
|
74 | 84 |
try { |
75 | 85 |
docid = im.getLocalId(key.getValue()); |
76 |
docinfo = im.getDocumentInfo(docid); |
|
77 |
|
|
86 |
path = pathToDocid(docid); |
|
78 | 87 |
} catch (McdbDocNotFoundException e) { |
79 | 88 |
// TODO Auto-generated catch block |
80 | 89 |
e.printStackTrace(); |
81 | 90 |
return null; |
91 |
} catch (SQLException e) { |
|
92 |
// TODO Auto-generated catch block |
|
93 |
e.printStackTrace(); |
|
82 | 94 |
} |
83 |
return pathToDocid(docid,(String)docinfo.get("doctype"));
|
|
95 |
return path; |
|
84 | 96 |
} |
85 | 97 |
|
86 | 98 |
|
87 |
|
|
88 |
|
|
89 |
|
|
90 | 99 |
/** |
91 | 100 |
* Implementation of hazelcast MapLoader interface method. |
92 | 101 |
*/ |
... | ... | |
97 | 106 |
for (Identifier id : identifiers) { |
98 | 107 |
try { |
99 | 108 |
String docid = im.getLocalId(id.getValue()); |
100 |
Hashtable<String,Object> docinfo = im.getDocumentInfo(docid); |
|
101 |
map.put(id, pathToDocid(docid, (String)docinfo.get("doctype"))); |
|
109 |
map.put(id, pathToDocid(docid)); |
|
102 | 110 |
|
103 | 111 |
} catch (McdbDocNotFoundException e) { |
104 | 112 |
// TODO Auto-generated catch block |
105 | 113 |
e.printStackTrace(); |
114 |
} catch (SQLException e) { |
|
115 |
// TODO Auto-generated catch block |
|
116 |
e.printStackTrace(); |
|
106 | 117 |
} |
107 | 118 |
} |
108 | 119 |
return map; |
109 | 120 |
} |
110 | 121 |
|
111 | 122 |
|
112 |
|
|
123 |
/** |
|
124 |
* Hazelcast documents a few ways to implement this method, depending on specific |
|
125 |
* usage. Preloading all of the GUIDs may be an unnecessarily long operation, |
|
126 |
* so this implementation returns NULL, and loading will be shifted to the other |
|
127 |
* method calls. |
|
128 |
*/ |
|
113 | 129 |
@Override |
114 | 130 |
public Set<Identifier> loadAllKeys() { |
131 |
return null; |
|
132 |
|
|
133 |
/* ---- this would be another way to implement, using existing methods |
|
134 |
* ---- in IdentifierManager, and DBUtil. but it is still problematic |
|
135 |
* ---- in how it goes from docid to GUID wrt revisions |
|
136 |
* ---- |
|
137 |
* ---- better would be a new call to the identifier table listing all GUIDs |
|
138 |
* ---- (from new method in IdentifierManager) |
|
115 | 139 |
Set<Identifier> set = Collections.synchronizedSet(new HashSet<Identifier>()); |
116 | 140 |
|
117 | 141 |
List<String> docids = null; |
... | ... | |
119 | 143 |
docids = im.getAllLocalIds(); |
120 | 144 |
for(String docid : docids) { |
121 | 145 |
Identifier id = new Identifier(); |
146 |
// TODO: need new query for going from localID to guid. |
|
122 | 147 |
id.setValue(im.getGUID(docid, im.getLatestRevForLocalId(docid))); |
123 | 148 |
set.add(id); |
124 | 149 |
} |
... | ... | |
127 | 152 |
e.printStackTrace(); |
128 | 153 |
} |
129 | 154 |
return set; |
155 |
*/ |
|
130 | 156 |
} |
131 | 157 |
} |
Also available in: Unified diff
further development of ObjectPathMapLoader.