I'm trying to upsert a vertex representing a directory in a directory tree in accordance with this pattern (the old coalesce trick). The properties WORK_ENVIRONMENT_ID and PATH are combined in a unique index.
If the vertex does not exist, it is also connected to a given environmentVertex via an Edge labelled CONTAINS. The vertex's DISCOVERED_AT property is updated nonetheless.
Simplified query:
final String addedVertexStep = "addedVertex";
Vertex fileVertex = (Vertex) graph.traversal().V()
/* ... querying for unique properties */
.fold()
.coalesce(__.unfold(),
__.addV(VertexLabels.FILE)
/* setting unique properties */
.as(addedVertexStep)
.V(environmentVertex.id())
.addE(EdgeLabels.CONTAINS)
.to(addedVertexStep)
.property(PropertyKeys.WORK_ENVIRONMENT_ID, workEnvironmentId.asUUID())
.select(addedVertexStep)
)
/* updating properties */
.next();
Full query:
final String addedVertexStep = "addedVertex";
Vertex fileVertex = (Vertex) graph.traversal().V()
.hasLabel(VertexLabels.FILE)
.has(PropertyKeys.WORK_ENVIRONMENT_ID, workEnvironmentId.asUUID())
.has(PropertyKeys.PATH, fileMetaInformation.fullPath())
.fold()
.coalesce(__.unfold(),
__.addV(VertexLabels.FILE)
.property(PropertyKeys.PATH, fileMetaInformation.fullPath())
.property(PropertyKeys.NAME, fileMetaInformation.simpleName())
.property(PropertyKeys.WORK_ENVIRONMENT_ID, workEnvironmentId.asUUID())
.property(PropertyKeys.PARENT_PATH, fileMetaInformation.directory().path())
.property(PropertyKeys.ID, fileMetaInformation.getId().asUUID())
.as(addedVertexStep)
.V(environmentVertex.id())
.addE(EdgeLabels.CONTAINS)
.to(addedVertexStep)
.property(PropertyKeys.WORK_ENVIRONMENT_ID, workEnvironmentId.asUUID())
.select(addedVertexStep)
)
.property(PropertyKeys.DISCOVERED_AT, new Date())
.next();
This gets executed hundreds of times in a loop, in a cached thread pool, but using the same threaded transaction:
final Graph threadedGraph = graph.tx().createThreadedTx();
Is there something wrong with the design of the query or the way it is executed that causes a deadlock? Can I redesign it to prevent this? Here's the exception I'm getting.
org.janusgraph.core.JanusGraphException: Possible dead lock detected. Waited for transaction lock without success
at org.janusgraph.graphdb.transaction.lock.ReentrantTransactionLock.lock(ReentrantTransactionLock.java:46) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.transaction.lock.CombinerLock.lock(CombinerLock.java:45) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.transaction.lock.CombinerLock.lock(CombinerLock.java:42) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.addProperty(StandardJanusGraphTx.java:769) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.addProperty(StandardJanusGraphTx.java:745) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.vertices.AbstractVertex.property(AbstractVertex.java:152) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.core.JanusGraphVertex.property(JanusGraphVertex.java:72) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.util.ElementHelper.attachProperties(ElementHelper.java:80) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsTransaction.addVertex(JanusGraphBlueprintsTransaction.java:122) ~[janusgraph-core-0.4.0.jar:?]
at org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsTransaction.addVertex(JanusGraphBlueprintsTransaction.java:44) ~[janusgraph-core-0.4.0.jar:?]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep.map(AddVertexStep.java:81) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep.map(AddVertexStep.java:43) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.MapStep.processNextStart(MapStep.java:37) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep.processNextStart(GraphStep.java:158) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.MapStep.processNextStart(MapStep.java:36) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.MapStep.processNextStart(MapStep.java:36) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectOneStep.processNextStart(SelectOneStep.java:131) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:192) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.CoalesceStep.flatMap(CoalesceStep.java:58) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep.processNextStart(FlatMapStep.java:49) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep.processNextStart(SideEffectStep.java:38) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:128) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:38) ~[gremlin-core-3.4.1.jar:3.4.1]
at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.next(DefaultTraversal.java:200) ~[gremlin-core-3.4.1.jar:3.4.1]
Turns out that it was not a deadlock, but rather lock congestion because I was bulk loading thousands of vertices with uniqueness constraints within the same transaction.
To fix it, I opened a new transaction for each vertex (or vertex chain as in the directory example above) and committed the transaction before upserting the next vertex (chain).
Related
I'm trying to add x number of objects via a simple for-loop to a distributed hazelcast queue (IQueue).
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
BlockingQueue<String> configs = hazelcastInstance.getQueue("test");
for(int i = 0; i<1000;i++) {
configs.add("Some string"+i);
}
Changing the values and in the config (see below) doesn't have any influence on the execution speed. I'd assume that increasing would block the insert operations and increasing would not (actually the loop should be run through as quickly as if the #add operation was on a local queue). However, the time executing the for-loop is the same. Even if i set both values to 0. Why is that (it's a two-node cluster with one node on a different vm)?
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation=
"http://www.hazelcast.com/schema/config hazelcast-config-3.7.xsd"
xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<network>
<port auto-increment="true" port-count="20">5701</port>
<join>
<multicast enabled="false">
</multicast>
<tcp-ip enabled="true">
<member>172.105.66.xx</member>
</tcp-ip>
</join>
</network>
<queue name="test">
<statistics-enabled>false</statistics-enabled>
<max-size>0</max-size>
<backup-count>0</backup-count>
<async-backup-count>1</async-backup-count>
<empty-queue-ttl>-1</empty-queue-ttl>
</queue>
</hazelcast>
The async-backups are not blocking your calls, so there should be a minimal difference in setting 0 or 1. Setting another value is meaningless on the 2 nodes cluster.
What makes the difference is the fact if the owner of the partition with your data structure is a local one or a remote one. The performance issues are in such case usually caused by the network latency between the caller (your test) and data structure owner (remote Hazelcast instance).
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
IQueue<String> configs = hazelcastInstance.getQueue("test");
for(int i = 0; i<1000;i++) {
configs.add("Some string"+i);
}
Member localMember = hazelcastInstance.getCluster().getLocalMember();
Member partitionOwner = hazelcastInstance.getPartitionService().getPartition(configs.getName()).getOwner();
boolean localCall = localMember.equals(partitionOwner);
System.out.println("Local calls to IQueue: " + localCall);
I've got a question regarding Python 3 which I can't wrap my head around.
Let's say I got the following dictionary.
{'Noah': 'Liam', 'Ethan': 'Peter', 'Liam': 'Olivia', 'Emma': 'Ethan', 'Peter': 'Emma', 'Olivia': 'Noah'}
I need to find the longest cycle of key-value pairs in this dictionary.
In pseudo-code this would be
for key in dictionary:
find value in dictionary, make this key
continue process untill start key has been detected
In this example the longest cycle would be:
Noah --> Liam --> Olivia --> Noah (length of 3)
I have no clue how to go about this, even though I know exactly what I want to do. Would appreciate some help.
The keyword to your problem is recursion... Or google "linked lists". Draw what you want to do on a sheet of paper and think of each step individually.. with that small amount of data it is possible.
It's for sure not the prettiest solution but it works. And you get the point.
import copy
people = {'Noah': 'Liam', 'Ethan': 'Peter', 'Liam': 'Olivia', 'Emma': 'Ethan', 'Peter': 'Emma', 'Olivia': 'Noah'}
def walk_the_links(person, subtree, counter):
print(person)
if person in subtree:
counter += 1
next_person = subtree[person]
subtree.pop(person)
counter = walk_the_links(next_person, subtree, counter)
return counter
for person in people:
subtree = copy.deepcopy(people)
counter = 0
length_tree = walk_the_links(person, subtree, counter)
print(length_tree)
I'm trying to search for a term using XQuery in MarkLogic. When I run the following code I get nothing. Does anyone know what the problem is? I don't use a namespace, but I don't think that is the problem.
Note: when I run this query in Query Console in MarkLogic I get this message:
your query returned an empty sequence
Code:
{
for $article-title in /article/front/article-meta/title-group/article-title[cts:contains(., xdmp:get-request-field("term"))]
let $article-title := fn:tokenize(fn:string($article-title/article/front/article-meta/title-group/article-title), " ")[1 to 100]
let $journal-title := $article-title/article/front/journal-meta/journal-title-group/journal-title/text()
let $contrib := $article-title/article/front/article-meta/contrib-group/contrib/text()
let $year:= $article-title/article/front/article-meta/pub-date/text()
let $sec-title:= $article-title/article/body/section/sec-title/text()
return (
<tr>
<td colspan="10"><hr/></td>
</tr>,
<tr>
<td><b>{$article-title}</b></td>
<td><b>{$journal-title}</b></td>
<td>{$contrib}</td>
<td>{$year}</td>
<td>{$sec-title}</td>
</tr>,
<tr>
<td colspan="10" class="article-title">{$article-title} ...</td>
</tr>
)
}
XML sample:
<?xml version="1.0" encoding="UTF-8"?>
<article article-type="article" xml:lang="en" structure-type="article" dtd- version="1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<front>
<journal-meta>
<journal-title-group>
<journal-title xml:lang="en">Psychology of Addictive Behaviors</journal-title>
</journal-title-group>
<issn pub-type="print">0893-164X</issn>
<issn pub-type="online">1939-1501</issn>
<publisher>
<publisher-name>American Psychological Association</publisher-name>
</publisher>
</journal-meta>
<article-meta>
<article-id pub-id-type="apaID">adb_21_4_462</article-id>
<article-id pub-id-type="doi">10.1037/0893-164X.21.4.462</article-id>
<article-id pub-id-type="pi-uid">2007-18113-004</article-id>
<article-categories>
<subj-group subj-group-type="toc-heading">
<subject>Articles</subject>
</subj-group>
</article-categories>
<title-group>
<article-title>Social Dominance Mediates the Association of Testosterone and Neurobehavioral Disinhibition With Risk for Substance Use Disorder</article-title>
</title-group>
<contrib-group content-type="journal-editors">
<contrib contrib-type="editor" corresp="no" xlink:type="simple">
<string-name>
<given-names>Howard J.</given-names> <surname>Shaffer</surname>
</string-name>
<role>Editor</role>
</contrib>
</contrib-group>
<contrib-group content-type="primary-authors">
<contrib contrib-type="author" corresp="yes" rid="aff1 corr1" xlink:type="simple">
<string-name>
<given-names>Ralph E.</given-names> <surname>Tarter</surname>
</string-name>
</contrib>
<contrib contrib-type="author" corresp="no" rid="aff1" xlink:type="simple">
<string-name>
<given-names>Levent</given-names> <surname>Kirisci</surname>
</string-name>
</contrib>
<contrib contrib-type="author" corresp="no" rid="aff1" xlink:type="simple">
<string-name>
<given-names>Galina P.</given-names> <surname>Kirillova</surname>
</string-name>
</contrib>
<contrib contrib-type="author" corresp="no" rid="aff1" xlink:type="simple">
<string-name>
<given-names>Judy</given-names> <surname>Gavaler</surname>
</string-name>
</contrib>
<contrib contrib-type="author" corresp="no" rid="aff2" xlink:type="simple">
<string-name>
<given-names>Peter</given-names> <surname>Giancola</surname>
</string-name>
</contrib>
</contrib-group>
</article-meta>
</front>
</article>
I think the meta-question here is: how do you debug a complex query when running the query returns nothing (an empty sequence)? It's not very useful for us to debug the query for you, it's much more useful that you should know how to debug it yourself.
If you've got a schema for the source, then running it as a schema-aware query can be very useful, even if you only do this temporarily for debugging purposes. A schema-aware query processor will check your path expressions against the schema, and tell you if you are trying to select elements or paths that, according to the schema, can never exist.
After that it's a process of logical deduction, and/or experimentation to distill the query to its essence. Because you've only got one "for" clause, and the return clause always produces something, the only way of getting an empty sequence as the result is if the for clause selects nothing. So that reduces it to a problem with the expression
/article/front/article-meta/title-group/article-title
[cts:contains(., xdmp:get-request-field("term"))]
At this stage using an IDE like oXygen can really help: put your source document into the editor, open the XPath evaluator, and enter this path. You'll need to modify it, because it uses MarkLogic extension functions. But you can start by eliminating the predicate and seeing if the path selects anything. I attempted that, but unfortunately your XML isn't well-formed so I gave up. But it's not difficult to do yourself. If the path expression selects nothing, remove trailing steps from the path until you get a result: the last step that your removed is the one that's wrong.
First, there are some errors in your XPath. You were selecting an article-title element but treating it as an article element in the following XPath. Next, you reassigned the $article-title variable (which is not actually possible in most XQuery processors - MarkLogic is an exception) to a string, and then executed XPath on that as if it were a node. Then for the remaining variable assignments, you were both operating on a string as if it were a node AND treating the variable as an article, when it would have been an article-title.
I updated the query by changing the for variable assignment to article and moving the rest of the XPath into a predicate. Then the other variables were updated to query from the $article variable instead of $article-title, which is a string.
for $article in /article[front/article-meta/title-group/article-title/cts:contains(., xdmp:get-request-field("term"))]
let $article-title := fn:tokenize(fn:string($article/front/article-meta/title-group/article-title), " ")[1 to 100]
let $journal-title := $article/front/journal-meta/journal-title-group/journal-title/text()
let $contrib := $article/front/article-meta/contrib-group/contrib/text()
let $year:= $article/front/article-meta/pub-date/text()
let $sec-title:= $article/body/section/sec-title/text()
There are a couple other possibilities I would check, if you continue to have problems: 1) Be sure your call to xdmp:get-request-field() is actually returning the value you expect; 2) Database index settings affect the behavior of cts:contains, so if any of the elements in the path you are selecting are excluded from the index, then cts:contains will treat it as if it doesn't exist.
public void testCreate() throws ApplicationException {
DutyDrawback drawback = new DutyDrawback();
drawback.setSerialNumber("TEST123");
drawback.setSnProcessInd("Y");
drawback.setMediaNumber("TEST111");
drawback.setMnProcessInd("Y");
drawback.setConfirmedInd("Y");
drawback.setResponseCode("1");
drawback.setResponseMsg("MSG");
drawback.setLastChangedUser("USER");
drawback.setLastChangedDate(new Date(System.currentTimeMillis()));
mockILogger.expects(atLeastOnce()).method("informationalEvent");
Logger.setMockLogger((ILogger) mockILogger.proxy());
// Set up the statement expectations
Mock mockStatement = mock(PreparedStatement.class);
mockStatement.expects(atLeastOnce()).method("setString");
mockStatement.expects(once()).method("executeUpdate").will(returnValue(1));
Mock mockStatement1 = mock(PreparedStatement.class);
mockStatement1.expects(atLeastOnce()).method("setString");
mockStatement1.expects(once()).method("executeUpdate").will(returnValue(1));
// Set up the connection expectations
mockConnection.expects(once()).method("setAutoCommit");
mockConnection.expects(once()).method("commit");
mockConnection.expects(once()).method("prepareStatement").will(returnValue(mockStatement1.proxy()));
mockConnection.expects(once()).method("prepareStatement").will(returnValue(mockStatement.proxy()));
TVSUtils.setMockConnection((Connection) mockConnection.proxy());
DutyDrawbackDAO drawbackDAO = new DutyDrawbackDAO();
int count = drawbackDAO.create(drawback);
assertEquals(2, count);
}
I am getting the following trace:
org.jmock.core.DynamicMockError: mockPreparedStatement: unexpected invocation
Invoked: mockPreparedStatement.executeUpdate()
Allowed:
expected at least once and has been invoked: setString, is void
expected once and has been invoked: executeUpdate, returns <1>
at org.jmock.core.AbstractDynamicMock.mockInvocation(AbstractDynamicMock.java:96)
at org.jmock.core.CoreMock.invoke(CoreMock.java:39)
at $Proxy2.executeUpdate(Unknown Source)
at com.cat.tvs.dao.DutyDrawbackDAO.create(DutyDrawbackDAO.java:102)
at com.cat.tvs.dao.DutyDrawbackDAOTest.testCreate(DutyDrawbackDAOTest.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:164)
at org.jmock.core.VerifyingTestCase.runBare(VerifyingTestCase.java:39)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I am not sure what am I doing wrong here?
Thanks.
Firstly, you seem to be using jmock1, you might consider moving to jmock2.
The failure says that you're calling executeUpdate() when it's not expected. Are you calling it more than once?
Finally, I usually recommend not writing mock tests against JDBC, even though I wrote a paper many years ago showing how to do it. We talk about "only mock types you own" for a number of reasons, one of which is that mock tests assume that the third party implementation doesn't change. For JDBC, I'd recommend writing integration tests that run against a small instance of the real database.
I have so many things in my QGraphicsScene. The situation is I am creating a chessboard, and is using Graphics scene. So the QGraphicsScene is having so many QGraphicsPixmapItems. Now In this how can I get the King.
Update:
In this QGraphicsScene, I am adding QGraphicsPixmapItems which are nothing but coins(board,king,queen,soldiers,etc). Now if I want to move a particular coin say King, then How can I get it. There are some methods like using iterators. But is there any way to find a particular QGraphicsPixmapItem by it's name.
When you say you need to get the King, how do you make the difference in your program between the white King and the black one ?
If you need to get a Pawn, how do you know which one ? Anyone ? The first one you can find in your items ?
I haven't thought a lot about it, but maybe what you can do is using a QMap. The key would be a enumeration of the different pieces and the value would be a pointer to the relevant QGraphicsItem. Something like this :
enum Piece_e {
KING,
QUEEN,
ROOK1,
ROOK2,
...
PAWN1,
PAWN2,
...
};
QMap<Piece_e, QGraphicsPixmapItem*> WhitePiecesItems;
QMap<Piece_e, QGraphicsPixmapItem*> BlackPiecesItems;
When you are creating your scene and instanciating your pieces, you'll fill the map :
...
WhitePiecesItem[KING] = new QGraphicsPixmapItem(QPixmap("whiteking_pic"));
WhitePiecesItem[PAWN1] = new QGraphicsPixmapItem(QPixmap("whitepawn_pic"));
...
BlackPiecesItem[QUEEN] = new QGraphicsPixmapItem(QPixmap("whitequeen_pic"));
BlackPiecesItem[PAWN1] = new QGraphicsPixmapItem(QPixmap("whitepawn_pic"));
...
When you need to find the object corresponding to the white king, you could do something like this :
QGraphicsPixmapItem* pItem = WhitePiecesItem[KING];