Skip to content

Commit d885228

Browse files
committed
Fix bug : missing _createTimestamp when DataObject is created with a given _oid
1 parent 93bdb61 commit d885228

File tree

2 files changed

+102
-52
lines changed

2 files changed

+102
-52
lines changed

src/main/java/picoded/dstack/core/Core_DataObject.java

Lines changed: 80 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -61,78 +61,108 @@ public class Core_DataObject implements DataObject {
6161

6262
// Constructor
6363
//----------------------------------------------
64+
65+
/**
66+
* Setup a DataObject against a DataObjectMap backend.
67+
*
68+
* Generates a new GUID for the object.
69+
*
70+
* @param inTable The DataObjectMap backend to use
71+
*/
72+
public Core_DataObject(DataObjectMap inTable){
73+
this(inTable, null);
74+
}
75+
76+
/**
77+
* Setup a DataObject against a DataObjectMap backend.
78+
*
79+
* Generates a new GUID for the object if inOID is null, else uses the provided inOID.
80+
*
81+
* @param inTable The DataObjectMap backend to use
82+
* @param inOID The GUID to use for the new DataObject, can be null
83+
*/
84+
public Core_DataObject(DataObjectMap inTable, String inOID){
85+
86+
// Main table to use
87+
mainTable = (Core_DataObjectMap) inTable;
88+
89+
// Issue a GUID
90+
if (inOID == null) {
91+
_oid = GUID.base58();
92+
} else {
93+
_oid = inOID;
94+
}
95+
96+
if (_oid.length() < 4) {
97+
throw new RuntimeException("_oid should be atleast 4 character long");
98+
}
99+
100+
// // D= GUID collision check for LOLZ
101+
// remoteDataMap = mainTable.DataObjectRemoteDataMap_get(_oid);
102+
// if (remoteDataMap.size() > 0) {
103+
// throw new SecurityException("GUID Collision =.= DO YOU HAVE REAL ENTROPY? : " + _oid);
104+
// }
105+
106+
// Ensure oid is savable, needed to save blank objects
107+
deltaDataMap.put("_oid", _oid);
108+
deltaDataMap.put("_createTimestamp", System.currentTimeMillis());
109+
110+
// Create remote data map (blank)
111+
remoteDataMap = new HashMap<String, Object>();
112+
113+
// Indicated that the provided map is "complete"
114+
isCompleteRemoteDataMap = true;
115+
116+
}
64117

65118
/**
66119
* Setup a DataObject against a DataObjectMap backend.
67120
*
68121
* This allow the setup in the following modes
69122
*
70-
* + No (or invalid) GUID : Assume a new DataObject is made with NO DATA. Issues a new GUID for the object
71123
* + GUID without remote data, will pull the required data when required
72124
* + GUID with complete remote data
73125
* + GUID with incomplete remote data, will pull the required data when required
74126
*
75127
* @param Meta table to use
76-
* @param GUID to use, can be null
128+
* @param GUID to use
77129
* @param Remote mapping data used (this should be modifiable)
78130
* @param is complete remote map, use false if incomplete data
79131
**/
80132
public Core_DataObject(DataObjectMap inTable, String inOID, Map<String, Object> inRemoteData,
81133
boolean isCompleteData) {
134+
135+
// null / empty check for inOID
136+
if(inOID == null || inOID.isEmpty()){
137+
throw new IllegalArgumentException("inOID cannot be null or empty");
138+
}
139+
82140
// Main table to use
83141
mainTable = (Core_DataObjectMap) inTable;
84142

85-
// Generates a GUID if not given
86-
if (inOID == null) {
87-
// Issue a GUID
88-
if (_oid == null) {
89-
_oid = GUID.base58();
90-
}
91-
92-
if (_oid.length() < 4) {
93-
throw new RuntimeException("_oid should be atleast 4 character long");
94-
}
95-
96-
// // D= GUID collision check for LOLZ
97-
// remoteDataMap = mainTable.DataObjectRemoteDataMap_get(_oid);
98-
// if (remoteDataMap.size() > 0) {
99-
// throw new SecurityException("GUID Collision =.= DO YOU HAVE REAL ENTROPY? : " + _oid);
100-
// }
101-
102-
// Ensure oid is savable, needed to save blank objects
103-
deltaDataMap.put("_oid", _oid);
104-
deltaDataMap.put("_createTimestamp", System.currentTimeMillis());
105-
106-
// Create remote data map (blank)
107-
remoteDataMap = new HashMap<String, Object>();
108-
109-
// Indicated that the provided map is "complete"
110-
isCompleteRemoteDataMap = true;
111-
112-
} else {
113-
// _oid setup
114-
_oid = inOID;
115-
116-
// Loading remote data map, only valid if _oid is given
117-
remoteDataMap = inRemoteData;
118-
119-
// Indicates that isComplete is flagged if given
120-
if (remoteDataMap != null) {
121-
isCompleteRemoteDataMap = isCompleteData;
122-
}
143+
// _oid setup
144+
_oid = inOID;
145+
146+
// Loading remote data map, only valid if _oid is given
147+
remoteDataMap = inRemoteData;
148+
149+
// Indicates that isComplete is flagged if given
150+
if (remoteDataMap != null) {
151+
isCompleteRemoteDataMap = isCompleteData;
123152
}
153+
124154
}
125155

126-
/**
127-
* Constructor, with DataObjectMap and GUID (auto generated if null)
128-
* This is the shorten version of the larger constructor
129-
*
130-
* @param Meta table to use
131-
* @param GUID to use, can be null
132-
**/
133-
public Core_DataObject(DataObjectMap inTable, String inOID) {
134-
this(inTable, inOID, null, false);
135-
}
156+
// /**
157+
// * Constructor, with DataObjectMap and GUID (auto generated if null)
158+
// * This is the shorten version of the larger constructor
159+
// *
160+
// * @param Meta table to use
161+
// * @param GUID to use, can be null
162+
// **/
163+
// public Core_DataObject(DataObjectMap inTable, String inOID) {
164+
// this(inTable, inOID, null, false);
165+
// }
136166

137167
// DataObject ID
138168
//----------------------------------------------

src/main/java/picoded/dstack/core/Core_DataObjectMap.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,37 @@ public DataObject remove(Object key) {
283283
//--------------------------------------------------------------------------
284284

285285
/**
286-
* Generates a new blank object, with a GUID
286+
* Generates a new blank object and issue a new GUID for it
287287
*
288288
* @return the DataObject
289289
**/
290290
public DataObject newEntry() {
291291
// Generating a new object
292-
DataObject ret = new Core_DataObject(this, null, null, false);
292+
DataObject ret = new Core_DataObject(this);
293293

294294
// Actual return
295295
return ret;
296296
}
297+
298+
/**
299+
* Generates a new blank object with the specified OID
300+
* @param oid The OID to use for the new DataObject
301+
* @return The newly created DataObject
302+
*/
303+
public DataObject newEntry(String oid) {
304+
305+
// do a collision check, to ensure the OID is not already in use
306+
if (get(oid) != null) {
307+
throw new RuntimeException("_oid already taken");
308+
}
309+
310+
// Generating a new object
311+
DataObject ret = new Core_DataObject(this, oid);
312+
313+
// Actual return
314+
return ret;
315+
316+
}
297317

298318
/**
299319
* Get a DataObject, and returns it. Skips existance checks if required

0 commit comments

Comments
 (0)