Revision 37002
Added by Sandro La Bruzzo about 9 years ago
GridFSObjectstoreDaoImpl.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStore; |
17 | 17 |
import eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao; |
18 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
18 | 19 |
import eu.dnetlib.miscutils.collections.MappedCollection; |
19 | 20 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
20 | 21 |
|
22 |
// TODO: Auto-generated Javadoc |
|
23 |
/** |
|
24 |
* The Class GridFSObjectstoreDaoImpl. |
|
25 |
*/ |
|
21 | 26 |
@SuppressWarnings("all") |
22 | 27 |
public class GridFSObjectstoreDaoImpl implements ObjectStoreDao { |
23 | 28 |
|
29 |
/** The Constant INTERPRETATION. */ |
|
24 | 30 |
public static final String INTERPRETATION = "interpretation"; |
31 |
|
|
32 |
/** The Constant OBJECTSTOREMETADATANAME. */ |
|
25 | 33 |
private final static String OBJECTSTOREMETADATANAME = "metadataObjectStore"; |
34 |
|
|
35 |
/** The Constant OBJECTSTOREIDFIELD. */ |
|
26 | 36 |
private final static String OBJECTSTOREIDFIELD = "obsId"; |
37 |
|
|
38 |
/** The db. */ |
|
27 | 39 |
private DB db; |
40 |
|
|
41 |
/** The upsert. */ |
|
28 | 42 |
private boolean upsert; |
43 |
|
|
44 |
/** The object store resturi. */ |
|
29 | 45 |
private String objectStoreRESTURI; |
30 | 46 |
|
47 |
/** |
|
48 |
* {@inheritDoc} |
|
49 |
* @see eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao#getObjectStore(java.lang.String) |
|
50 |
*/ |
|
31 | 51 |
@Override |
32 | 52 |
public ObjectStore getObjectStore(String obsId) { |
33 | 53 |
db.setWriteConcern(WriteConcern.SAFE); |
... | ... | |
38 | 58 |
return objectStore; |
39 | 59 |
} |
40 | 60 |
|
61 |
/** |
|
62 |
* Check indexes. |
|
63 |
* |
|
64 |
* @param id the id |
|
65 |
*/ |
|
41 | 66 |
private void checkIndexes(final String id) { |
42 | 67 |
DBCollection coll = db.getCollection(id + ".files"); |
43 | 68 |
List<DBObject> indexInfo = coll.getIndexInfo(); |
... | ... | |
53 | 78 |
} |
54 | 79 |
} |
55 | 80 |
|
81 |
/** |
|
82 |
* {@inheritDoc} |
|
83 |
* @see eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao#listObjectStores() |
|
84 |
*/ |
|
56 | 85 |
@Override |
57 | 86 |
public List<String> listObjectStores() { |
58 | 87 |
DBCollection metadata = db.getCollection(OBJECTSTOREMETADATANAME); |
... | ... | |
66 | 95 |
|
67 | 96 |
} |
68 | 97 |
|
98 |
/** |
|
99 |
* {@inheritDoc} |
|
100 |
* @see eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao#createObjectStore(java.lang.String, java.lang.String, java.lang.String) |
|
101 |
*/ |
|
69 | 102 |
@Override |
70 |
public boolean createObjectStore(final String obsId, final String interpretation) { |
|
71 |
DBCollection coll = db.getCollection(OBJECTSTOREMETADATANAME); |
|
72 |
final BasicDBObject obj = new BasicDBObject(); |
|
73 |
obj.put(OBJECTSTOREIDFIELD, obsId); |
|
74 |
obj.put(INTERPRETATION, interpretation); |
|
75 |
coll.save(obj); |
|
103 |
public boolean createObjectStore(final String obsId, final String interpretation, final String basePath) throws ObjectStoreServiceException { |
|
104 |
try { |
|
105 |
DBCollection coll = db.getCollection(OBJECTSTOREMETADATANAME); |
|
106 |
final BasicDBObject obj = new BasicDBObject(); |
|
107 |
obj.put(OBJECTSTOREIDFIELD, obsId); |
|
108 |
obj.put(INTERPRETATION, interpretation); |
|
109 |
coll.save(obj); |
|
110 |
} catch (Throwable e) { |
|
111 |
throw new ObjectStoreServiceException("Error on create object store with id: "+obsId, e); |
|
112 |
} |
|
76 | 113 |
return true; |
77 | 114 |
} |
78 | 115 |
|
116 |
/** |
|
117 |
* {@inheritDoc} |
|
118 |
* @see eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao#updateObjectStore(java.lang.String, java.lang.String) |
|
119 |
*/ |
|
79 | 120 |
@Override |
80 | 121 |
public boolean updateObjectStore(final String obsId, final String interpretation) { |
81 | 122 |
DBCollection coll = db.getCollection(OBJECTSTOREMETADATANAME); |
... | ... | |
87 | 128 |
return true; |
88 | 129 |
} |
89 | 130 |
|
131 |
/** |
|
132 |
* {@inheritDoc} |
|
133 |
* @see eu.dnetlib.data.objectstore.modular.connector.ObjectStoreDao#deleteObjectStore(java.lang.String) |
|
134 |
*/ |
|
90 | 135 |
@Override |
91 | 136 |
public boolean deleteObjectStore(String obsId) { |
92 | 137 |
DBCollection coll = db.getCollection(OBJECTSTOREMETADATANAME); |
... | ... | |
99 | 144 |
return true; |
100 | 145 |
} |
101 | 146 |
|
147 |
/** |
|
148 |
* Gets the db. |
|
149 |
* |
|
150 |
* @return the db |
|
151 |
*/ |
|
102 | 152 |
public DB getDb() { |
103 | 153 |
return db; |
104 | 154 |
} |
105 | 155 |
|
156 |
/** |
|
157 |
* Sets the db. |
|
158 |
* |
|
159 |
* @param db the new db |
|
160 |
*/ |
|
106 | 161 |
@Required |
107 | 162 |
public void setDb(final DB db) { |
108 | 163 |
this.db = db; |
109 | 164 |
} |
110 | 165 |
|
166 |
/** |
|
167 |
* Checks if is upsert. |
|
168 |
* |
|
169 |
* @return true, if is upsert |
|
170 |
*/ |
|
111 | 171 |
public boolean isUpsert() { |
112 | 172 |
return upsert; |
113 | 173 |
} |
114 | 174 |
|
175 |
/** |
|
176 |
* Sets the upsert. |
|
177 |
* |
|
178 |
* @param upsert the new upsert |
|
179 |
*/ |
|
115 | 180 |
@Required |
116 | 181 |
public void setUpsert(final boolean upsert) { |
117 | 182 |
this.upsert = upsert; |
118 | 183 |
} |
119 | 184 |
|
185 |
/** |
|
186 |
* Gets the object store resturi. |
|
187 |
* |
|
188 |
* @return the object store resturi |
|
189 |
*/ |
|
120 | 190 |
public String getObjectStoreRESTURI() { |
121 | 191 |
return objectStoreRESTURI; |
122 | 192 |
} |
123 | 193 |
|
194 |
/** |
|
195 |
* Sets the object store resturi. |
|
196 |
* |
|
197 |
* @param objectStoreRESTURI the new object store resturi |
|
198 |
*/ |
|
124 | 199 |
@Required |
125 | 200 |
public void setObjectStoreRESTURI(final String objectStoreRESTURI) { |
126 | 201 |
this.objectStoreRESTURI = objectStoreRESTURI; |
Also available in: Unified diff
implemented layer file system for Object Store Service