On persist.

@param entityMetadata
the entity metadata
@param entity
the entity
@param id
the id
@param rlHolders
the rl holders
507817
@Override
    protected void onPersist(EntityMetadata entityMetadata, Object entity, Object id, List<RelationHolder> rlHolders)
    {

        KuduSession session = kuduClient.newSession();
        KuduTable table = null;
        try
        {
            table = kuduClient.openTable(entityMetadata.getTableName());
        }
        catch (Exception e)
        {
            logger.error("Cannot open table : " + entityMetadata.getTableName(), e);
            throw new KunderaException("Cannot open table : " + entityMetadata.getTableName(), e);
        }
        Operation operation = isUpdate ? table.newUpdate() : table.newInsert();
        PartialRow row = operation.getRow();
        populatePartialRow(row, entityMetadata, entity);
        try
        {
            session.apply(operation);
        }
        catch (Exception e)
        {
            logger.error("Cannot insert/update row in table : " + entityMetadata.getTableName(), e);
            throw new KunderaException("Cannot insert/update row in table : " + entityMetadata.getTableName(), e);
        }
        finally
        {
            try
            {
                session.close();
            }
            catch (Exception e)
            {
                logger.error("Cannot close session", e);
                throw new KunderaException("Cannot close session", e);
            }
        }
    }
899204
public void delete(Object entity) {
    try {
      entityManager.executeEntityListeners(CallbackType.PRE_DELETE, entity);
      Key nativeKey = Marshaller.marshalKey(entityManager, entity);
      nativeWriter.delete(nativeKey);
      entityManager.executeEntityListeners(CallbackType.POST_DELETE, entity);
    } catch (DatastoreException exp) {
      throw DatastoreUtils.wrap(exp);
    }
  }
507614
@Override
    protected void onPersist(EntityMetadata metadata, Object entity, Object id, List<RelationHolder> relationHolders)
    {
        boolean proxyRemoved = removeKunderaProxies(metadata, entity, relationHolders);

        Transaction tx = null;

        s = getStatelessSession();
        tx = onBegin();
        try
        {
            if (!isUpdate)
            {
                id = s.insert(entity);

                // Update foreign Keys
                updateForeignKeys(metadata, id, relationHolders);
                onCommit(tx);/* tx.commit(); */
            }
            else
            {
                s.update(entity);

                if (proxyRemoved)
                {
                    updateForeignKeys(metadata, id, relationHolders);
                }

                onCommit(tx);
            }
        }
        // TODO: Bad code, get rid of these exceptions, currently necessary for
        // handling many to one case
        catch (org.hibernate.exception.ConstraintViolationException e)
        {
            s.update(entity);
            log.info(e.getMessage());
            onCommit(tx);
            // tx.commit();
        }
        catch (HibernateException e)
        {
            log.error("Error while persisting object of {}, Caused by {}.", metadata.getEntityClazz(), e);
            throw new PersistenceException(e);
        }
    }
825251
public void addEntityListener(String repoFullName, EntityListener entityListener) {
    lock.writeLock().lock();
    try {
      verifyRepoRegistered(repoFullName);
      SetMultimap<Object, EntityListener> entityListeners =
          this.entityListenersByRepo.get(repoFullName);
      entityListeners.put(entityListener.getEntityId(), entityListener);
    } finally {
      lock.writeLock().unlock();
    }
  }
406025
private void setId(EntityMetadata m, Object entity, Object columnValue, boolean isCql3Enabled)
    {
        if (isCql3Enabled && !m.getType().equals(Type.SUPER_COLUMN_FAMILY))
        {
            setFieldValueViaCQL(entity, columnValue, m.getIdAttribute());
        }
        else
        {
            setFieldValue(entity, columnValue, m.getIdAttribute());
        }
    }
717560
protected void store(Object id, Object entity)
    {
        store(id, entity, Boolean.TRUE);
    }
808367
public void persist(Node node)
    {
        Object entity = node.getData();
        Object id = node.getEntityId();
        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, node.getDataClass());
        isUpdate = node.isUpdate();
        List<RelationHolder> relationHolders = getRelationHolders(node);
        onPersist(metadata, entity, id, relationHolders);
        id = PropertyAccessorHelper.getId(entity, metadata);
        node.setEntityId(id);
        indexNode(node, metadata);
    }
294487
@Override
    protected void indexNode(Node node, EntityMetadata entityMetadata)
    {
        // Do nothing as
        if (this.indexManager.getIndexer() != null
                && !this.indexManager.getIndexer().getClass().getSimpleName().equals("RedisIndexer"))
        {
            super.indexNode(node, entityMetadata);
        }
    }
909094
public function persist(AbstractEntity $entity)
    {
        if ($this->prepareEntityForPersist($entity)) {
            $this->getRepository()->persist($entity);
        }

        $this->afterPersist($entity);
    }
881454
public void addEntityId(long entityId)
    {
        if(this.entityIds == null)
            this.entityIds = new ArrayList<Long>();
        this.entityIds.add(entityId);
    }
629169
private void updateDocument(EntityMetadata metadata, final MetamodelImpl metaModel, Object entity, String parentId,
            Class<? extends Object> class1, boolean b)
    {
        updateOrCreateIndex(metadata, metaModel, entity, parentId, entity.getClass(), true);
        onCommit();
    }
241258
private void updateDeletedObjectsThroughEntityManager(List<String> oids, Long timestamp) {
        for (String id : oids) {
            EDBObject o = new EDBObject(id);
            o.updateTimestamp(timestamp);
            o.setDeleted(true);
            JPAObject j = EDBUtils.convertEDBObjectToJPAObject(o);
            entityManager.persist(j);
        }
    }
876387
public void store(Object entity, String id) {
        storeInternal(entity, null, id, ConcurrencyCheckMode.AUTO);
    }
410881
protected void addAssociatedEntitiesToDocument(EntityMetadata metadata, Object entity, Document document,
        MetamodelImpl metaModel) {
        try {
            IndexCollection indexes = metadata.getEntityClazz().getAnnotation(IndexCollection.class);
            if (indexes != null) {
                List<String> columnsNameToBeIndexed = new ArrayList<String>();
                for (com.impetus.kundera.index.Index indexedColumn : indexes.columns()) {
                    Attribute attrib = metaModel.getEntityAttribute(entity.getClass(), indexedColumn.name());
                    columnsNameToBeIndexed.add(((AbstractAttribute) attrib).getJPAColumnName());
                }

                String indexName = metadata.getIndexName();
                List<Relation> relations = metadata.getRelations();
                for (Relation relation : relations) {
                    if (relation.getType().equals(ForeignKey.MANY_TO_ONE)
                        || relation.getType().equals(ForeignKey.ONE_TO_ONE)) {
                        String propertyName = relation.getJoinColumnName(null);
                        if (propertyName != null && columnsNameToBeIndexed.contains(propertyName)) {
                            java.lang.reflect.Field property = relation.getProperty();
                            Object obj = PropertyAccessorHelper.getObject(entity, property);
                            if (obj != null) {
                                EntityMetadata relMetaData = metaModel.getEntityMetadata(obj.getClass());
                                Object id = PropertyAccessorHelper.getId(obj, relMetaData);
                                if (id != null) {
                                    Field luceneField =
                                        new Field(getCannonicalPropertyName(indexName, propertyName), id.toString(),
                                            Field.Store.YES, Field.Index.ANALYZED_NO_NORMS);

                                    document.add(luceneField);
                                } else {
                                    LOG.warn("value is null for field" + property.getName());
                                }
                            }
                        }
                    }
                }
            }
        } catch (PropertyAccessException e) {
            LOG.error("Error in accessing field, Caused by:" + e.getMessage());
            throw new LuceneIndexingException("Error in creating indexes on associated columns", e);
        }
    }
1059055
private void onFamilyType(EntityMetadata entityMetadata, final Class clazz, Field f)
    {
        if (entityMetadata.getType() == null || !entityMetadata.getType().equals(Type.SUPER_COLUMN_FAMILY))
        {
            if ((f.isAnnotationPresent(Embedded.class) && f.getType().getAnnotation(Embeddable.class) != null))
            {
                entityMetadata.setType(Type.SUPER_COLUMN_FAMILY);
            }
            else if (f.isAnnotationPresent(ElementCollection.class) && !MetadataUtils.isBasicElementCollectionField(f))
            {
                entityMetadata.setType(Type.SUPER_COLUMN_FAMILY);
            }
            else
            {
                entityMetadata.setType(Type.COLUMN_FAMILY);
            }
        }
    }
197356
public void persist(Object e)
    {
        if (e == null)
        {
            throw new IllegalArgumentException(
                    "Entity object is invalid, operation failed. Please check previous log message for details");
        }

        // Create an object graph of the entity object.
        ObjectGraph graph = new GraphGenerator().generateGraph(e, this);
        // Call persist on each node in object graph.
        Node node = graph.getHeadNode();
        try
        {
            // Get write lock before writing object required for transaction.
            lock.writeLock().lock();

            node.setPersistenceDelegator(this);
            node.persist();

            // build flush stack.
            flushManager.buildFlushStack(node, com.impetus.kundera.persistence.context.EventLog.EventType.INSERT);

            // Flushing data.
            flush();

            // Add node to persistence context after successful flush.
            getPersistenceCache().getMainCache().addHeadNode(node);
        }
        finally
        {
            lock.writeLock().unlock();
        }

        // Unlocking object.
        graph.clear();
        graph = null;
        if (log.isDebugEnabled())
        {
            log.debug("Data persisted successfully for entity {}.", e.getClass());
        }
    }
480151
@Synchronized
    @SneakyThrows
    public void buildMetadataResolverAggregate(final String entityId) {
        LOGGER.trace("Building metadata resolver aggregate");
        this.metadataResolver = new ChainingMetadataResolver();
        val resolvers = new ArrayList<MetadataResolver>();
        val entries = this.metadataResources.entrySet();
        entries.forEach(entry -> {
            val resource = entry.getKey();
            LOGGER.debug("Loading [{}]", resource.getFilename());
            resolvers.addAll(loadMetadataFromResource(entry.getValue(), resource, entityId));
        });
        this.metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
        this.metadataResolver.setResolvers(resolvers);
        LOGGER.debug("Collected metadata from [{}] resolvers(s). Initializing aggregate resolver...", resolvers.size());
        this.metadataResolver.initialize();
        LOGGER.info("Metadata aggregate initialized successfully.");
    }