/** @since 3.1 */ @Override public <T extends Persistent> T localObject(T objectFromAnotherContext) { if (objectFromAnotherContext == null) { throw new NullPointerException("Null object argument"); } ObjectId id = objectFromAnotherContext.getObjectId(); // first look for the ID in the local GraphManager synchronized (getGraphManager()) { T localObject = (T) getGraphManager().getNode(id); if (localObject != null) { return localObject; } // create a hollow object, optimistically assuming that the ID we // got from // 'objectFromAnotherContext' is a valid ID either in the parent // context or in // the DB. This essentially defers possible FaultFailureExceptions. ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(id.getEntityName()); Persistent persistent = (Persistent) descriptor.createObject(); persistent.setObjectContext(this); persistent.setObjectId(id); persistent.setPersistenceState(PersistenceState.HOLLOW); getGraphManager().registerNode(id, persistent); return (T) persistent; } }
public String toString(int indentCount) { String indent = ""; for (int i = 0; i < indentCount; i++) { indent += ". "; } String str = indent + "PersonalProfileDO:"; ObjectId oid = getOId(); String id = "virgin"; if (null != oid) id = oid.toString(); str += " OID=" + id; if (null != data) str = str + "\n" + indent + "MinAge=" + data.MinAge + "\n" + indent + "MaxAge=" + data.MaxAge + "\n" + indent + "Nationality=" + (null == data.Nationality ? null : data.Nationality.toString(indentCount + 1)) + "\n" + indent + "Sex=" + data.Sex; return str + "\n" + indent + "SUPER=" + super.toString(indentCount); // return str; }
public void testReadTree() throws Exception { // Prepare tree GitIndex index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a:b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new File(trash, "a/b")); index.add(trash, new File(trash, "a:b")); index.add(trash, new File(trash, "a.b")); index.write(); ObjectId id = index.writeTree(); System.out.println("wrote id " + id); assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); GitIndex index2 = new GitIndex(db); index2.readTree(db.mapTree(ObjectId.fromString("c696abc3ab8e091c665f49d00eb8919690b3aec3"))); Entry[] members = index2.getMembers(); assertEquals(3, members.length); assertEquals("a.b", members[0].getName()); assertEquals("a/b", members[1].getName()); assertEquals("a:b", members[2].getName()); assertEquals(3, members.length); GitIndex indexr = new GitIndex(db); indexr.read(); Entry[] membersr = indexr.getMembers(); assertEquals(3, membersr.length); assertEquals("a.b", membersr[0].getName()); assertEquals("a/b", membersr[1].getName()); assertEquals("a:b", membersr[2].getName()); assertEquals(3, membersr.length); if (canrungitstatus) assertEquals(0, system(trash, "git status")); }
public String toString(int indentCount) { String indent = ""; for (int i = 0; i < indentCount; i++) { indent += ". "; } String str = indent + "TreeLeafDO:"; ObjectId oid = getOId(); String id = "virgin"; if (null != oid) id = oid.toString(); str += " OID=" + id; if (null != data) str = str + "\n" + indent + "LeafNumber=" + data.LeafNumber + "\n" + indent + "Profile=" + (null == data.Profile ? null : data.Profile.toString(indentCount + 1)) + "\n" + indent + "Mandatory=" + data.Mandatory; return str + "\n" + indent + "SUPER=" + super.toString(indentCount); // return str; }
protected void putObjectId(String name, ObjectId oid) { _put(OID, name); // according to spec, values should be stored big endian _buf.writeIntBE(oid._time()); _buf.writeIntBE(oid._machine()); _buf.writeIntBE(oid._inc()); }
protected void putDBPointer(String name, String ns, ObjectId oid) { _put(REF, name); _putValueString(ns); _buf.writeInt(oid._time()); _buf.writeInt(oid._machine()); _buf.writeInt(oid._inc()); }
public AbstractMacroBaseUnitTestCase() { // log4j: PropertyConfigurator.configure( AbstractMacroBaseUnitTestCase.class.getClassLoader().getResource("log4j.properties")); // CMIS Repository Map<String, ConfluenceCMISRepository> repoConfigs = new WeakHashMap<String, ConfluenceCMISRepository>(); ConfluenceCMISRepository repoConfig = new ConfluenceCMISRepository( TEST_SERVER_NAME, TEST_REALM, TEST_USERNAME, TEST_PASSWORD, null); repoConfigs.put(TEST_SERVER_NAME, repoConfig); bandanaManager = mock(BandanaManager.class); when(bandanaManager.getValue((BandanaContext) anyObject(), anyString())) .thenReturn(repoConfigs); // CMIS ObjectId documentObjectId = mock(ObjectId.class); when(documentObjectId.getId()).thenReturn(TEST_DOCUMENT_ID); Document documentObject = getTestDocument(); List<CmisObject> documentList = new ArrayList<CmisObject>(); documentList.add(documentObject); ObjectId folderObjectId = mock(ObjectId.class); when(folderObjectId.getId()).thenReturn(TEST_FOLDER_ID); ItemIterable<CmisObject> children = mock(ItemIterable.class); when(children.getTotalNumItems()).thenReturn(1l); when(children.getHasMoreItems()).thenReturn(true).thenReturn(false); when(children.iterator()).thenReturn(documentList.iterator()); Folder folderObject = createMockedCmisObject( new String[][] { {PropertyIds.NAME, "Name", "A folder"}, {PropertyIds.BASE_TYPE_ID, "Base Type Id", "cmis:folder"}, {PropertyIds.OBJECT_TYPE_ID, "Object Type Id", "cmis:folder"}, {PropertyIds.OBJECT_ID, "Object Type Id", TEST_FOLDER_ID} }, Folder.class); when(folderObject.getId()).thenReturn(TEST_FOLDER_ID); when(folderObject.getChildren()).thenReturn(children); Session session = mock(Session.class); when(session.createObjectId(TEST_DOCUMENT_ID)).thenReturn(documentObjectId); when(session.createObjectId(TEST_FOLDER_ID)).thenReturn(folderObjectId); when(session.getObject(documentObjectId)).thenReturn(documentObject); when(session.getObject(folderObjectId)).thenReturn(folderObject); confluenceCMISRepository = mock(ConfluenceCMISRepository.class); when(confluenceCMISRepository.getSession()).thenReturn(session); }
@Override public Map<Integer, List<String>> splitByDataSource(Collection<String> ids) { Map<Integer, List<String>> map = new HashMap<Integer, List<String>>(); for (String s : ids) { ObjectId oi = new ObjectId(s); int shard = oi.getShard(); int datasource = shard / getShardsPerDataSource(); List<String> list = map.get(datasource); if (list == null) { list = new ArrayList<String>(); map.put(datasource, list); } list.add(s); } return map; }
public void testCheckout() throws Exception { // Prepare tree, remote it and checkout GitIndex index = new GitIndex(db); File aslashb = writeTrashFile("a/b", "data:a/b"); File acolonb = writeTrashFile("a:b", "data:a:b"); File adotb = writeTrashFile("a.b", "data:a.b"); index.add(trash, aslashb); index.add(trash, acolonb); index.add(trash, adotb); index.write(); index.writeTree(); delete(aslashb); delete(acolonb); delete(adotb); delete(aslashb.getParentFile()); GitIndex index2 = new GitIndex(db); assertEquals(0, index2.getMembers().length); index2.readTree(db.mapTree(ObjectId.fromString("c696abc3ab8e091c665f49d00eb8919690b3aec3"))); index2.checkout(trash); assertEquals("data:a/b", content(aslashb)); assertEquals("data:a:b", content(acolonb)); assertEquals("data:a.b", content(adotb)); if (canrungitstatus) assertEquals(0, system(trash, "git status")); }
/** * Set the OID to query. WARNING! This method assumes that table <CODE>SoftwareCandidate</CODE> * has a column named <CODE>"oid"</CODE>. This method is called from the DO classes to retrieve an * object by id. * * @param oid The object id to query. */ public void setQueryOId(ObjectId oid) { // Remove from cacheHits any DOs that do not meet this // setQuery requirement. if (null == oid) return; requireUniqueInstance(); for (int i = 0; i < cacheHits.size(); i++) { SoftwareCandidateDO DO = (SoftwareCandidateDO) cacheHits.elementAt(i); if (null == DO) continue; boolean equals = true; ObjectId id = DO.getOId(); if (null == id || !id.equals(oid)) cacheHits.removeElementAt(i--); } // Also prepare the SQL needed to query the database // in case there is no cache, or the query involves other tables. builder.addWhereClause("oid", oid.toBigDecimal(), QueryBuilder.NOT_NULL); }
public void testWriteTree() throws Exception { GitIndex index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a:b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new File(trash, "a/b")); index.add(trash, new File(trash, "a:b")); index.add(trash, new File(trash, "a.b")); index.write(); ObjectId id = index.writeTree(); assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name()); writeTrashFile("a/b", "data:a/b"); index.add(trash, new File(trash, "a/b")); if (canrungitstatus) assertEquals(0, system(trash, "git status")); }
@Override public int compareTo(Event event) { if (when < event.when) { return -1; } if (when > event.when) { return 1; } return id.compareTo(event.id); }
public void testReadTree2() throws Exception { // Prepare a larger tree to test some odd cases in tree writing GitIndex index = new GitIndex(db); File f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a"); File f2 = writeTrashFile("a/c/c", "data:a/c/c"); File f3 = writeTrashFile("a/b", "data:a/b"); File f4 = writeTrashFile("a:b", "data:a:b"); File f5 = writeTrashFile("a/d", "data:a/d"); File f6 = writeTrashFile("a.b", "data:a.b"); index.add(trash, f1); index.add(trash, f2); index.add(trash, f3); index.add(trash, f4); index.add(trash, f5); index.add(trash, f6); index.write(); ObjectId id = index.writeTree(); System.out.println("wrote id " + id); assertEquals("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.name()); GitIndex index2 = new GitIndex(db); index2.readTree(db.mapTree(ObjectId.fromString("ba78e065e2c261d4f7b8f42107588051e87e18e9"))); Entry[] members = index2.getMembers(); assertEquals(6, members.length); assertEquals("a.b", members[0].getName()); assertEquals("a/a/a/a", members[1].getName()); assertEquals("a/b", members[2].getName()); assertEquals("a/c/c", members[3].getName()); assertEquals("a/d", members[4].getName()); assertEquals("a:b", members[5].getName()); // reread and test GitIndex indexr = new GitIndex(db); indexr.read(); Entry[] membersr = indexr.getMembers(); assertEquals(6, membersr.length); assertEquals("a.b", membersr[0].getName()); assertEquals("a/a/a/a", membersr[1].getName()); assertEquals("a/b", membersr[2].getName()); assertEquals("a/c/c", membersr[3].getName()); assertEquals("a/d", membersr[4].getName()); assertEquals("a:b", membersr[5].getName()); }
@Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null || !(object instanceof Event)) { return false; } Event event = (Event) object; return id.equals(event.id); }
@org.junit.Test public void testGetObject() throws Exception { when(objects.getNode()).thenReturn(nodeList); when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); NodeId nodeId2 = new NodeId(objectId.getValue()); // into getnode when(node.getNodeId()).thenReturn(nodeId2); Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), node); when(objects.getNode()).thenReturn(nodeListnull); when(objects.getConnection()).thenReturn(connectionList); when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); ConnectionId connectionId2 = new ConnectionId(objectId.getValue()); // into getconnection when(connection.getConnectionId()).thenReturn(connectionId2); Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), connection); when(objects.getNode()).thenReturn(nodeListnull); when(objects.getConnection()).thenReturn(connectionListnull); when(objects.getFlow()).thenReturn(flowList); when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); FlowId flowId2 = new FlowId(objectId.getValue()); // into getflow when(flow.getFlowId()).thenReturn(flowId2); Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), flow); }
/** * @param xref the reference ID of the object this link points to. May contain bracketing '@' * characters. */ public final void initLink(final ObjectId xref) { if (getParent() == null) { setFromString(""); } else { setFromString(getParent().getString()); } if (xref == null) { setToString(""); } else { setToString(xref.getIdString().replace("@", "")); } }
/** * Returns a map key for a given to-many map relationship and a target object. * * @since 3.0 */ protected Object getMapKey(String relationshipName, Object value) { EntityResolver resolver = objectContext.getEntityResolver(); ClassDescriptor descriptor = resolver.getClassDescriptor(objectId.getEntityName()); if (descriptor == null) { throw new IllegalStateException("DataObject's entity is unmapped, objectId: " + objectId); } PropertyDescriptor property = descriptor.getProperty(relationshipName); if (property instanceof ToManyMapProperty) { return ((ToManyMapProperty) property).getMapKey(value); } throw new IllegalArgumentException( "Relationship '" + relationshipName + "' is not a to-many Map"); }
@SuppressWarnings("nls") @Override public String toString() { StringBuilder r = new StringBuilder(); r.append("SymbolicRef["); Ref cur = this; while (cur.isSymbolic()) { r.append(cur.getName()); r.append(" -> "); cur = cur.getTarget(); } r.append(cur.getName()); r.append('='); r.append(ObjectId.toString(cur.getObjectId())); r.append("]"); return r.toString(); }
@Override public ExtendedDataSource getDataSourceByObjectId(String id) { ObjectId oi = new ObjectId(id); return getDataSourceByShardId(oi.getShard()); }
@Override public int hashCode() { return id.hashCode(); }
/** * @param parent parent object of this source * @param xref cross reference to this source */ public Source(final GedObject parent, final ObjectId xref) { super(parent, xref.getIdString()); }