private String gidStringForObject(EOEnterpriseObject eo) { EOKeyGlobalID gid = ((ERXGenericRecord) eo).permanentGlobalID(); String pk = ERXKeyGlobalID.globalIDForGID(gid).asString(); return pk; }
public EOKeyGlobalID eoKeyGlobalId() { String gidString = _doc.get(GID); EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); return gid; }
public void setObject(EOEnterpriseObject eo) { EOGlobalID gid; if (gid() == null) { if (eo instanceof ERXGenericRecord) { gid = ((ERXGenericRecord) eo).permanentGlobalID(); } else { throw new IllegalArgumentException("Can't handle non ERXGenericRecord"); } ERXKeyGlobalID keyGID = ERXKeyGlobalID.globalIDForGID((EOKeyGlobalID) gid); setGid(keyGID); } }
public EOEnterpriseObject object() { EOKeyGlobalID gid = gid().globalID(); return editingContext().faultForGlobalID(gid, editingContext()); }
@Override public void init(EOEditingContext ec) { super.init(ec); EOEnterpriseObject user = ERCoreBusinessLogic.actor(ec); if (user != null && user instanceof ERXGenericRecord) { ERXKeyGlobalID gid = ERXKeyGlobalID.globalIDForGID(((ERXGenericRecord) user).permanentGlobalID()); setUserGlobalID(gid); } setCreated(new NSTimestamp()); }
public EOEnterpriseObject user() { if (userGlobalID() == null) { return null; } EOKeyGlobalID gid = userGlobalID().globalID(); EOEnterpriseObject eo = editingContext().faultForGlobalID(gid, editingContext()); try { eo.willRead(); return eo; } catch (EOObjectNotAvailableException e) { return null; } }
public IndexDocument createDocumentForGlobalID(EOKeyGlobalID globalID) { Document doc = new Document(); String pk = ERXKeyGlobalID.globalIDForGID(globalID).asString(); doc.add(new Field(GID, pk, Field.Store.YES, Field.Index.NOT_ANALYZED)); return new IndexDocument(doc); }
private EOEnterpriseObject objectForGidString(EOEditingContext ec, String gidString) { EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); return ec.faultForGlobalID(gid, ec); }
public ERCAuditTrail auditTrailForObject(EOEditingContext ec, EOEnterpriseObject eo) { EOKeyGlobalID gid = null; if (eo instanceof ERXGenericRecord) { gid = ((ERXGenericRecord) eo).permanentGlobalID(); } else { throw new IllegalArgumentException("Can't handle non ERXGenericRecord"); } ERCAuditTrail trail = (ERCAuditTrail) ERXEOControlUtilities.objectWithQualifier(ec, ENTITY_NAME, ERXQ.equals(Key.GID, ERXKeyGlobalID.globalIDForGID(gid))); if (trail == null) { trail = (ERCAuditTrail) EOQualifier.filteredArrayWithQualifier(ec.insertedObjects(), ERXQ.equals("entityName", ENTITY_NAME).and(ERXQ.equals(Key.GID + ".globalID", gid))).lastObject(); } return trail; }
protected void handleChange(EOEditingContext ec, EOEnterpriseObject eo, ERCAuditTrailType type, String keyPath, Object oldValue, Object newValue) { ERXGenericRecord rec = (ERXGenericRecord) eo; ERCAuditTrail trail = ERCAuditTrail.clazz.auditTrailForObject(ec, eo); if (trail == null) { trail = ERCAuditTrail.clazz.createAuditTrailForObject(ec, eo); } log.info("{} {}: {} {} from {} to {}", trail, type, rec.permanentGlobalID(), keyPath, oldValue, newValue); if (oldValue instanceof ERXGenericRecord) { ERXGenericRecord rec1 = (ERXGenericRecord) oldValue; oldValue = ERXKeyGlobalID.globalIDForGID(rec1.permanentGlobalID()).asString(); } if (newValue instanceof ERXGenericRecord) { ERXGenericRecord rec1 = (ERXGenericRecord) newValue; newValue = ERXKeyGlobalID.globalIDForGID(rec1.permanentGlobalID()).asString(); } trail.createEntry(type, keyPath, oldValue, newValue); } }
private NSArray<EOKeyGlobalID> findGlobalIDs(Query query) { NSMutableArray<EOKeyGlobalID> result = new NSMutableArray(); long start = System.currentTimeMillis(); try { Searcher searcher = indexSearcher(); Hits hits = searcher.search(query); log.info("Searched for: " + query + " in " + (System.currentTimeMillis() - start) + " ms"); for (Iterator iter = hits.iterator(); iter.hasNext();) { Hit hit = (Hit) iter.next(); String gidString = hit.getDocument().getField(GID).stringValue(); EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); result.addObject(gid); } log.info("Returning " + result.count() + " after " + (System.currentTimeMillis() - start) + " ms"); return result; } catch (IOException e) { throw NSForwardException._runtimeExceptionForThrowable(e); } }
public IndexDocument findDocument(EOKeyGlobalID globalID) { NSMutableArray<Document> result = new NSMutableArray(); long start = System.currentTimeMillis(); try { Searcher searcher = indexSearcher(); String pk = ERXKeyGlobalID.globalIDForGID(globalID).asString(); BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term(GID, pk)), Occur.MUST); Hits hits = searcher.search(query); log.info("Searched for: " + query.toString(GID) + " in " + (System.currentTimeMillis() - start) + " ms"); for (Iterator iter = hits.iterator(); iter.hasNext();) { Hit hit = (Hit) iter.next(); result.addObject(hit.getDocument()); } log.info("Returning " + result.count() + " after " + (System.currentTimeMillis() - start) + " ms"); } catch (IOException e) { throw NSForwardException._runtimeExceptionForThrowable(e); } return new IndexDocument(result.lastObject()); }
private NSArray<EOKeyGlobalID> findGlobalIDs(Query query, Filter filter, Sort sort, int start, int end) { NSMutableArray<EOKeyGlobalID> result = new NSMutableArray<>(); try { Searcher searcher = indexSearcher(); long startTime = System.currentTimeMillis(); sort = sort == null ? new Sort() : sort; TopFieldDocs topFielsDocs = searcher.search(query, filter, end, sort); log.info("Searched for: " + query + " in " + (System.currentTimeMillis() - startTime) + " ms"); for (int i = start; i < topFielsDocs.scoreDocs.length; i++) { String gidString = searcher.doc(topFielsDocs.scoreDocs[i].doc).getField(GID).stringValue(); EOKeyGlobalID gid = ERXKeyGlobalID.fromString(gidString).globalID(); result.addObject(gid); } log.info("Returning " + result.count() + " after " + (System.currentTimeMillis() - startTime) + " ms"); return result; } catch (IOException e) { throw NSForwardException._runtimeExceptionForThrowable(e); } }
protected NSDictionary serializeObject(EOEnterpriseObject eo) { NSMutableDictionary<String, Object> result = new NSMutableDictionary<>(); result.addEntriesFromDictionary(eo.snapshot()); for (Enumeration e = eo.snapshot().keyEnumerator(); e.hasMoreElements();) { String key = (String) e.nextElement(); Object value = result.objectForKey(key); if (value instanceof ERXConstant.Constant) { ERXConstant.Constant constant = (ERXConstant.Constant) value; result.setObjectForKey(constant.value(), key); } else if (value == NSKeyValueCoding.NullValue) { result.removeObjectForKey(key); } else if (value instanceof ERXGenericRecord) { ERXGenericRecord rec = (ERXGenericRecord) value; result.setObjectForKey(ERXKeyGlobalID.globalIDForGID(rec.permanentGlobalID()).asString(), key); } else if (value instanceof NSArray) { NSArray oldValue = (NSArray) value; NSMutableArray newValue = new NSMutableArray(oldValue.count()); for (Enumeration e1 = newValue.objectEnumerator(); e1.hasMoreElements();) { ERXGenericRecord rec = (ERXGenericRecord) e1.nextElement(); newValue.addObject(ERXKeyGlobalID.globalIDForGID(rec.permanentGlobalID()).asString()); } result.setObjectForKey(newValue, key); } } return result; }