@Transactional @Test public void testDeleteToken() { jpaTokenStore.initializeSegment(null, "delete", 0); jpaTokenStore.fetchToken("delete", 0); entityManager.flush(); jpaTokenStore.deleteToken("delete", 0); assertEquals(0L, (long) entityManager.createQuery("SELECT count(t) FROM TokenEntry t " + "WHERE t.processorName = :processorName", Long.class) .setParameter("processorName", "delete") .getSingleResult()); }
@Override public void deleteToken(String processorName, int segment) throws UnableToClaimTokenException { EntityManager entityManager = entityManagerProvider.getEntityManager(); int updates = entityManager.createQuery( "DELETE FROM TokenEntry te " + "WHERE te.owner = :owner AND te.processorName = :processorName " + "AND te.segment = :segment") .setParameter("processorName", processorName) .setParameter("segment", segment) .setParameter("owner", nodeId) .executeUpdate(); if (updates == 0) { throw new UnableToClaimTokenException("Unable to remove token. It is not owned by " + nodeId); } }
JpaTokenStore implements TokenStore { @Override public void deleteToken(String processorName, int segment) throws UnableToClaimTokenException { EntityManager entityManager = entityManagerProvider.getEntityManager(); int updates = entityManager.createQuery( "DELETE FROM TokenEntry te " + "WHERE te.owner = :owner AND te.processorName = :processorName " + "AND te.segment = :segment") .setParameter("processorName", processorName) .setParameter("segment", segment) .setParameter("owner", nodeId) .executeUpdate(); if (updates == 0) { throw new UnableToClaimTokenException("Unable to remove token. It is not owned by " + nodeId); } } }
JpaTokenStore implements TokenStore { @Override public void deleteToken(String processorName, int segment) throws UnableToClaimTokenException { EntityManager entityManager = entityManagerProvider.getEntityManager(); int updates = entityManager.createQuery( "DELETE FROM TokenEntry te " + "WHERE te.owner = :owner AND te.processorName = :processorName " + "AND te.segment = :segment") .setParameter("processorName", processorName) .setParameter("segment", segment) .setParameter("owner", nodeId) .executeUpdate(); if (updates == 0) { throw new UnableToClaimTokenException("Unable to remove token. It is not owned by " + nodeId); } } protected  JpaTokenStore(Builder builder); }
JpaTokenStore implements TokenStore { @Override public void deleteToken(String processorName, int segment) throws UnableToClaimTokenException { EntityManager entityManager = entityManagerProvider.getEntityManager(); int updates = entityManager.createQuery( "DELETE FROM TokenEntry te " + "WHERE te.owner = :owner AND te.processorName = :processorName " + "AND te.segment = :segment") .setParameter("processorName", processorName) .setParameter("segment", segment) .setParameter("owner", nodeId) .executeUpdate(); if (updates == 0) { throw new UnableToClaimTokenException("Unable to remove token. It is not owned by " + nodeId); } } protected  JpaTokenStore(Builder builder); static Builder builder(); @Override void initializeTokenSegments(String processorName, int segmentCount); @Override void initializeTokenSegments(String processorName, int segmentCount, TrackingToken initialToken); @Override void storeToken(TrackingToken token, String processorName, int segment); @Override void releaseClaim(String processorName, int segment); @Override void initializeSegment(TrackingToken token, String processorName, int segment); @Override boolean requiresExplicitSegmentInitialization(); @Override void deleteToken(String processorName, int segment); @Override TrackingToken fetchToken(String processorName, int segment); @Override void extendClaim(String processorName, int segment); @Override int[] fetchSegments(String processorName); @Override Optional<String> retrieveStorageIdentifier(); Serializer serializer(); }
JpaTokenStore implements TokenStore { @Override public void deleteToken(String processorName, int segment) throws UnableToClaimTokenException { EntityManager entityManager = entityManagerProvider.getEntityManager(); int updates = entityManager.createQuery( "DELETE FROM TokenEntry te " + "WHERE te.owner = :owner AND te.processorName = :processorName " + "AND te.segment = :segment") .setParameter("processorName", processorName) .setParameter("segment", segment) .setParameter("owner", nodeId) .executeUpdate(); if (updates == 0) { throw new UnableToClaimTokenException("Unable to remove token. It is not owned by " + nodeId); } } protected  JpaTokenStore(Builder builder); static Builder builder(); @Override void initializeTokenSegments(String processorName, int segmentCount); @Override void initializeTokenSegments(String processorName, int segmentCount, TrackingToken initialToken); @Override void storeToken(TrackingToken token, String processorName, int segment); @Override void releaseClaim(String processorName, int segment); @Override void initializeSegment(TrackingToken token, String processorName, int segment); @Override boolean requiresExplicitSegmentInitialization(); @Override void deleteToken(String processorName, int segment); @Override TrackingToken fetchToken(String processorName, int segment); @Override void extendClaim(String processorName, int segment); @Override int[] fetchSegments(String processorName); @Override Optional<String> retrieveStorageIdentifier(); Serializer serializer();  }