public class Bean { private List<Entity> entities; private Map<Long, Boolean> checked = new HashMap<Long, Boolean>(); public void submit() { for (Entity entity : entities) { if (checked.get(entity.getId())) { // Entity is checked. Do your thing here. } } } // ... }
String sql = "UPDATE entity SET name = ?, value = ? WHERE id = ?"; // ... statement = connection.prepareStatement(sql); for (Entity entity : entities) { statement.setString(1, entity.getName()); statement.setInt(2, entity.getValue()); statement.setLong(3, entity.getId()); // ... statement.addBatch(); } statement.executeBatch(); // ...
for (final Entity entity: entities){ synchronized( entity.getId().intern() ){ processEntity(entity); } }
private Integer persistEntity(Entity entity) { ... manager.persist(entity); ... transaction.commit(); return entity.getId(); .. }
for(Entity entity: entityList) { Model model = models.get(entity.getId()); if (model != null) { merge(entity, model); } }
equals(Object other){ if (this == o) return true; if (o==null) return false; if (!Entity.class.isAssignableFrom(other.getClass()) return false; Entity otherEntity = (Entity) other; if (otherEntity.getId() == getId()) return true; if (otherEntity.getId() == null) return false; return otherEntity.getId().equals(getId()); } hashCode(){ if (getId()) == null return super.hashCode(); return getId().hashCode(); }
Entity entity = entityManager.merge(newEntity); System.out.println("This is id of stored entity:", entity.getId())
class EntityResolver { private Map<Integer, Entity> entities; public EntityResolver(EntitiesOwner[] owners) { entities = new HashMap<Integer, Entity>(owners.length); for (EntitiesOwner owner : owners) { for (Entity entity : owner.getEntities()) { entities.put(entity.getId(), entity); } } } public Entity getById(int id) { return entities.get(id); } }
private static final Set<String> entitiesInProcess = Sets.newConcurrentHashSet(); public void processEntities(Entities entities) { for (final Entity entity : entities) { final String id = entity.getId(); final boolean isInProcess = !entitiesInProcess.add(id); if (isInProcess) continue; try { processEntity(entity); } finally { entitiesInProcess.remove(id); } } }
/** * Find the resource with this id in the list. * * @param items * The list of items. * @param id * The item id. * @return The index position in the list of the item with this id, or -1 if not found. */ protected int findResourceInList(List resources, String id) { for (int i = 0; i < resources.size(); i++) { // if this is the one, return this index if (((Entity) (resources.get(i))).getId().equals(id)) return i; } // not found return -1; } // findResourceInList
@RequestMapping(value="", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResponseEntity<Object> getAll() { List<Entity> entityList = entityManager.findAll(); List<JSONObject> entities = new ArrayList<JSONObject>(); for (Entity n : entityList) { JSONObject Entity = new JSONObject(); entity.put("id", n.getId()); entity.put("address", n.getAddress()); entities.add(entity); } return new ResponseEntity<Object>(entities, HttpStatus.OK); }
/** * {@inheritDoc} */ public String getDescription(Entity entity) { if (!isAvailable()) return null; if (!(entity instanceof RWikiEntity)) return null; return entity.getId(); }
@Transactional public void mySnycMethod() { Entity entity = new MyEntity(); // fill entity dao.save(entity); // performLongRunningTask will start after the transaction has been // commited TransactionSynchronizationManager .registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCommit() { asyncService.performLongRunningTask(entity.getId()); } }); }
/** * Read in properties from the database - when the properties and the main table are related by the id * * @param r * The resource for which properties are to be read. * @param p * The properties object to fill. */ public void readProperties(Connection conn, Entity r, ResourcePropertiesEdit p) { readProperties(conn, m_resourcePropertyTableName, m_resourceTableIdField, caseId(r.getId()), p); }
/** * Read in properties from the database - when the properties and the main table are related by the id * * @param r * The resource for which properties are to be read. * @param p * The properties object to fill. */ public void readProperties(Entity r, ResourcePropertiesEdit p) { readProperties(null, m_resourcePropertyTableName, m_resourceTableIdField, caseId(r.getId()), p); }
/** * Read in properties from the database - when the properties and the main table are related by the id * * @param r * The resource for which properties are to be read. * @param p * The properties object to fill. */ public void readProperties(Connection conn, Entity r, ResourcePropertiesEdit p) { readProperties(conn, m_resourcePropertyTableName, m_resourceTableIdField, caseId(r.getId()), p); }
/** * Read in properties from the database - when the properties and the main table are related by the id * * @param r * The resource for which properties are to be read. * @param p * The properties object to fill. */ public void readProperties(Entity r, ResourcePropertiesEdit p) { readProperties(null, m_resourcePropertyTableName, m_resourceTableIdField, caseId(r.getId()), p); }
/** * Replace any properties for this resource with the resource's current set of properties. * * @param conn * optional database connection to use. * @param r * The resource for which properties are to be written. * @param props * The properties to write. */ public void writeProperties(Entity r, ResourceProperties props) { writeProperties(m_resourcePropertyTableName, m_resourceTableIdField, caseId(r.getId()), null, null, props); }
for(Entity e : entities){ if(!e.isRight()) entityTypes[e.getId()].getAtlas().findRegion(e.getFrame()).flip(true, false); batch.draw(entityTypes[e.getId()].getAtlas().findRegion(e.getFrame()), e.getPosition().x, e.getPosition().y); if(!e.isRight()) entityTypes[e.getId()].getAtlas().findRegion(e.getFrame()).flip(true, false); }
/** * Replace any properties for this resource with the resource's current set of properties. * * @param conn * optional database connection to use. * @param r * The resource for which properties are to be written. * @param props * The properties to write. */ public void writeProperties(Entity r, ResourceProperties props) { writeProperties(m_resourcePropertyTableName, m_resourceTableIdField, caseId(r.getId()), null, null, props); }