Revision 6416
Added by rnahf over 12 years ago
ObjectPathMapLoader.java | ||
---|---|---|
57 | 57 |
* the data. The doctype value for metadata can vary, but for data |
58 | 58 |
* is always 'BIN', so using a simple if-then-else to separate |
59 | 59 |
*/ |
60 |
private String pathToDocid(String docid) throws SQLException {
|
|
60 |
private String pathToDocid(String localid) throws McdbDocNotFoundException {
|
|
61 | 61 |
|
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; |
|
62 |
Hashtable<String, Object> ht = im.getDocumentInfo(localid); |
|
63 |
if (ht.get("doctype").equals("BIN")) { |
|
64 |
return dataPath + FileUtil.getFS() + localid; |
|
68 | 65 |
} else { |
69 |
return metadataPath + FileUtil.getFS() + docid + "." + revision;
|
|
66 |
return metadataPath + FileUtil.getFS() + localid;
|
|
70 | 67 |
} |
71 | 68 |
} |
72 | 69 |
|
73 | 70 |
|
74 | 71 |
/** |
75 | 72 |
* Implementation of hazelcast MapLoader interface method. |
76 |
* for the provided Identifier (as key), looks up the localID |
|
77 |
* and revision |
|
73 |
* For the provided Identifier (as key), returns the path to the |
|
74 |
* document on the local filesystem. Returns null if it can't |
|
75 |
* create the path. |
|
78 | 76 |
*/ |
79 | 77 |
@Override |
80 | 78 |
public String load(Identifier key) |
... | ... | |
88 | 86 |
// TODO Auto-generated catch block |
89 | 87 |
e.printStackTrace(); |
90 | 88 |
return null; |
91 |
} catch (SQLException e) { |
|
92 |
// TODO Auto-generated catch block |
|
93 |
e.printStackTrace(); |
|
94 | 89 |
} |
95 | 90 |
return path; |
96 | 91 |
} |
97 | 92 |
|
98 | 93 |
|
99 | 94 |
/** |
100 |
* Implementation of hazelcast MapLoader interface method. |
|
95 |
* Implementation of hazelcast MapLoader interface method. This method loads |
|
96 |
* mappings for all Identifiers in the parameters. Any Identifier not found |
|
97 |
* is not included in the resulting map. |
|
101 | 98 |
*/ |
102 | 99 |
@Override |
103 | 100 |
public Map<Identifier, String> loadAll(Collection<Identifier> identifiers) { |
... | ... | |
109 | 106 |
map.put(id, pathToDocid(docid)); |
110 | 107 |
|
111 | 108 |
} catch (McdbDocNotFoundException e) { |
112 |
// TODO Auto-generated catch block |
|
109 |
// TODO should the map load an empty path instead of |
|
110 |
// leaving out the entire entry? |
|
113 | 111 |
e.printStackTrace(); |
114 |
} catch (SQLException e) { |
|
115 |
// TODO Auto-generated catch block |
|
116 |
e.printStackTrace(); |
|
117 | 112 |
} |
118 | 113 |
} |
119 | 114 |
return map; |
... | ... | |
121 | 116 |
|
122 | 117 |
|
123 | 118 |
/** |
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. |
|
119 |
* Return the full set of guids in the local metacat repository as |
|
120 |
* dataone Identifiers. |
|
121 |
* |
|
122 |
* (Hazelcast allows avoiding pre-loading by returning NULL, so consider |
|
123 |
* re-implementing if that serves the purpose of this class better) |
|
128 | 124 |
*/ |
129 | 125 |
@Override |
130 | 126 |
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) |
|
127 |
|
|
128 |
List<String> guids = im.getAllGUIDs(); |
|
129 |
|
|
139 | 130 |
Set<Identifier> set = Collections.synchronizedSet(new HashSet<Identifier>()); |
140 |
|
|
141 |
List<String> docids = null; |
|
142 |
try { |
|
143 |
docids = im.getAllLocalIds(); |
|
144 |
for(String docid : docids) { |
|
145 |
Identifier id = new Identifier(); |
|
146 |
// TODO: need new query for going from localID to guid. |
|
147 |
id.setValue(im.getGUID(docid, im.getLatestRevForLocalId(docid))); |
|
148 |
set.add(id); |
|
149 |
} |
|
150 |
} catch (Exception e) { |
|
151 |
// TODO Auto-generated catch block |
|
152 |
e.printStackTrace(); |
|
131 |
for (String guid : guids) { |
|
132 |
Identifier id = new Identifier(); |
|
133 |
id.setValue(guid); |
|
134 |
set.add(id); |
|
153 | 135 |
} |
154 | 136 |
return set; |
155 |
*/ |
|
156 | 137 |
} |
157 | 138 |
} |
Also available in: Unified diff
fixed logic wrt localID and docid. Implemented new method in IdentifierManager to getAllGUIDs from identifier table for implementation of loadAllKeys in ObjectPathMapLoader.