private void incVersion(T chunk) { if (chunk == null || chunk.getVersion() < 2) { System.err.println(getClass() + " - WARNING: tried to incVersion of uninitialized chunk."); return; } chunk.incVersion(); }
/** * Updates the specified objects * * @return the id's of the failed objects (e.g. due to versioning) */ public Collection<Integer> bulkUpdate( Collection<T> objects, String indexName, boolean refresh, boolean enableVersioning) { // now using bulk API instead of feeding each doc separate with feedDoc BulkRequestBuilder brb = client.prepareBulk(); // this works differently then the direct call to refresh!? maybe refresh is not async? // brb.setRefresh(refresh); for (T o : objects) { if (o.getId() == null) { logger.warn("Skipped object without id when bulkUpdate:" + o); continue; } try { XContentBuilder source = createDoc(o); IndexRequest indexReq = Requests.indexRequest(indexName).type(getIndexType()).id(o.getId()).source(source); if (enableVersioning) indexReq.version(o.getVersion()); brb.add(indexReq); } catch (IOException ex) { logger.warn("Cannot add object:" + o + " to bulkIndexing action." + ex.getMessage()); } } if (brb.numberOfActions() > 0) { BulkResponse rsp = brb.execute().actionGet(); if (rsp.hasFailures()) { List<Integer> list = new ArrayList<Integer>(rsp.items().length); for (BulkItemResponse br : rsp.items()) { if (br.isFailed()) { // logger.info("Error:" + br.failureMessage()); list.add(br.itemId()); } } return list; } if (refresh) refresh(indexName); } return Collections.emptyList(); }
@Override public void writeTo( final T t, Class<?> type, final Type type1, final Annotation[] antns, final MediaType mt, final MultivaluedMap<String, Object> mm, final OutputStream out) throws IOException, WebApplicationException { try { final Marshaller m = WFSMarshallerPool.getInstance().acquireMarshaller(); final String version = t.getVersion(); if ("1.0.0".equals(version)) { m.setProperty( Marshaller.JAXB_SCHEMA_LOCATION, "http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd"); } else if ("1.1.0".equals(version)) { m.setProperty( Marshaller.JAXB_SCHEMA_LOCATION, "http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"); } else if ("2.0.0".equals(version)) { m.setProperty( Marshaller.JAXB_SCHEMA_LOCATION, "http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd"); } if (t instanceof WFSResponseWrapper) { m.marshal(((WFSResponseWrapper) t).getResponse(), out); } else { m.marshal(t, out); } WFSMarshallerPool.getInstance().recycle(m); } catch (JAXBException ex) { LOGGER.log(Level.SEVERE, "JAXB exception while writing the WFS response", ex); } }
public T findForUpdate(PK id, Integer version) { T entity = findById(id); if (logger.isDebugEnabled()) { logger.debug("Found entity with \"" + id + "\" of class " + type); } if (version != entity.getVersion()) { if (logger.isDebugEnabled()) { logger.debug( "The entity of type " + type + " with id " + id + " has been edited by another transaction"); } throw new OptimisticLockException( "The entity of type " + type + " with id " + id + " has been edited by another transaction"); } return entity; }
private boolean hasPotentialConflicts() { return aggregate.getUncommittedEventCount() > 0 && aggregate.getVersion() != null && !unseenEvents.isEmpty(); }
@Override public long getSequenceNumber() { return aggregate.getVersion(); }