/*
(non-Javadoc)

@see
com.impetus.kundera.client.ClientBase#onPersist(com.impetus.kundera.metadata
.model.EntityMetadata, java.lang.Object, java.lang.Object,
java.util.List)
3795
@Override
    protected void onPersist(EntityMetadata entityMetadata, Object entity, Object id, List<RelationHolder> rlHolders)
    {
        Object connection = getConnection();
        // Create a hashset and populate data into it
        //

        Pipeline pipeLine = null;
        try
        {
            if (isBoundTransaction())
            {
                pipeLine = ((Jedis) connection).pipelined();
                onPersist(entityMetadata, entity, id, rlHolders, pipeLine);
            }
            else
            {
                onPersist(entityMetadata, entity, id, rlHolders, connection);
            }
        }
        finally
        {
            //
            if (pipeLine != null)
            {
                pipeLine.sync(); // send I/O.. as persist call. so no need to
                                 // read
            } // response?

            onCleanup(connection);
        }

    }
136747
public static void registerDataPersisters(DataPersister... dataPersisters) {
		// we build the map and replace it to lower the chance of concurrency issues
		List<DataPersister> newList = new ArrayList<DataPersister>();
		if (registeredPersisters != null) {
			newList.addAll(registeredPersisters);
		}
		for (DataPersister persister : dataPersisters) {
			newList.add(persister);
		}
		registeredPersisters = newList;
	}
755739
@Override
    protected List<Object> populateEntities(EntityMetadata m, Client client)
    {
        return onQuery(m, client);
    }
602743
private void onParseRelation(Object entity, final PersistenceDelegator pd, EntityMetadata targetEntityMetadata,
            Object relationEntity, Relation relation, boolean lazilyloaded, Map<Object, Object> relationStack)
    {
        parseRelations(entity, getEntity(relationEntity), getPersistedRelations(relationEntity), pd,
                targetEntityMetadata, lazilyloaded, relationStack);

        // if relation ship is unary, no problem else we need to add
        setRelationToEntity(entity, relationEntity, relation);
    }
1321766
@Override
	public void cacheResult(List<CPFriendlyURLEntry> cpFriendlyURLEntries) {
		for (CPFriendlyURLEntry cpFriendlyURLEntry : cpFriendlyURLEntries) {
			if (entityCache.getResult(
						CPFriendlyURLEntryModelImpl.ENTITY_CACHE_ENABLED,
						CPFriendlyURLEntryImpl.class,
						cpFriendlyURLEntry.getPrimaryKey()) == null) {
				cacheResult(cpFriendlyURLEntry);
			}
			else {
				cpFriendlyURLEntry.resetOriginalValues();
			}
		}
	}
720769
protected void onColumn(EntityMetadata m, boolean isRelation, List<String> relations, List<Object> entities,
        List<Column> columns, List<AbstractManagedType> subManagedType, ByteBuffer key) {
        if (!columns.isEmpty()) {
            Object id = PropertyAccessorHelper.getObject(m.getIdAttribute().getJavaType(), key.array());
            ThriftRow tr = new ThriftRow(id, m.getTableName(), columns, new ArrayList<SuperColumn>(0),
                new ArrayList<CounterColumn>(0), new ArrayList<CounterSuperColumn>(0));
            Object o = null;

            if (!subManagedType.isEmpty()) {
                for (AbstractManagedType subEntity : subManagedType) {
                    EntityMetadata subEntityMetadata =
                        KunderaMetadataManager.getEntityMetadata(kunderaMetadata, subEntity.getJavaType());

                    o = getDataHandler().populateEntity(tr, subEntityMetadata, KunderaCoreUtils.getEntity(o),
                        subEntityMetadata.getRelationNames(), isRelation);
                    if (o != null) {
                        break;
                    }
                }
            } else {
                o = getDataHandler().populateEntity(tr, m, KunderaCoreUtils.getEntity(o), relations, isRelation);
            }

            if (log.isInfoEnabled()) {
                log.info("Populating data for entity of clazz {} and row key {}.", m.getEntityClazz(), tr.getId());
            }

            if (o != null) {
                entities.add(o);
            }
        }
    }
1020579
public void requestPermanent(AddOnModel addOnModel, Identification source, boolean nonJava) {
        debug("requesting permanent for addon: " + addOnModel);
        boolean notUsing = isUsing.compareAndSet(false, true);
        if (!notUsing) {
            debug("already used by " + permanentAddOn);
            synchronized (permanentUserReadWriteLock) {
                if (permanentAddOn != null && permanentAddOn.equals(addOnModel)) {
                    if (knownIdentification == null)
                        knownIdentification = source;
                    return;
                } else {
                    endPermanent(permanentAddOn);
                    addAsPermanent(addOnModel, source, nonJava);
                }
            }
        } else {
            addAsPermanent(addOnModel, source, nonJava);
        }
    }
1246656
static synchronized <T extends Model> void load(T entity, Cursor cursor) {
		sAdapterHolder.getModelAdapter(entity.getClass()).load(entity, cursor);
	}
256679
public function postPersist(ClassMetadata $class, $document)
    {
        $class->invokeLifecycleCallbacks(Event::postPersist, $document, [new LifecycleEventArgs($document, $this->dm)]);
        $this->evm->dispatchEvent(Event::postPersist, new LifecycleEventArgs($document, $this->dm));
        $this->cascadePostPersist($class, $document);
    }
1370999
public void setUserIdList(java.util.Collection<String> userIdList) {
        if (userIdList == null) {
            this.userIdList = null;
            return;
        }

        this.userIdList = new java.util.ArrayList<String>(userIdList);
    }
891737
@Override
  public void onNodesUpdated(final List<NodeReport> nodeReports) {
    for (final NodeReport nodeReport : nodeReports) {
      this.nodeIdToRackName.put(nodeReport.getNodeId().toString(), nodeReport.getRackName());
      this.onNodeReport(nodeReport);
    }
  }
922926
private void parsePersistence(Map<Object, Object> props) {
        parseKeepAliveEnabled(props);
        if (isKeepAliveEnabled()) {
            parseMaxPersist(props);
        }
    }
514094
public function postPersist(EventArgs $eventArgs)
    {
        if (method_exists($eventArgs, 'getEntity')) {
            $this->_triggerEvent(Events::postPersist, $eventArgs->getEntity(), $eventArgs);
        }
    }
789026
@Override
	public void cacheResult(List<CommerceWishListItem> commerceWishListItems) {
		for (CommerceWishListItem commerceWishListItem : commerceWishListItems) {
			if (entityCache.getResult(
						CommerceWishListItemModelImpl.ENTITY_CACHE_ENABLED,
						CommerceWishListItemImpl.class,
						commerceWishListItem.getPrimaryKey()) == null) {
				cacheResult(commerceWishListItem);
			}
			else {
				commerceWishListItem.resetOriginalValues();
			}
		}
	}
155323
private void registerNotificationListener(String type, BiConsumer<ObjectName, Tags> perObject) {
        NotificationListener notificationListener = (notification, handback) -> {
            MBeanServerNotification mbs = (MBeanServerNotification) notification;
            ObjectName o = mbs.getMBeanName();
            perObject.accept(o, Tags.concat(tags, nameTag(o)));
        };

        NotificationFilter filter = (NotificationFilter) notification -> {
            if (!MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(notification.getType()))
                return false;
            ObjectName obj = ((MBeanServerNotification) notification).getMBeanName();
            return obj.getDomain().equals(JMX_DOMAIN) && obj.getKeyProperty("type").equals(type);
        };

        try {
            mBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, notificationListener, filter, null);
            notificationListenerCleanUpRunnables.add(() -> {
                try {
                    mBeanServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, notificationListener);
                } catch (InstanceNotFoundException | ListenerNotFoundException ignored) {
                }
            });
        } catch (InstanceNotFoundException e) {
            throw new RuntimeException("Error registering Kafka MBean listener", e);
        }
    }
1084573
public final void update(EntityMetadata metadata, Object entity, Object parentId, Class<?> clazz)
    {
        try
        {
            if (indexer != null)
            {
                if (indexer.getClass().getName().equals(IndexingConstants.LUCENE_INDEXER))
                {
                    MetamodelImpl metamodel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                            metadata.getPersistenceUnit());
                    Object id = PropertyAccessorHelper.getId(entity, metadata);
                    boolean isEmbeddedId = metamodel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType());

                    boolean documentExistsInIndex = ((com.impetus.kundera.index.lucene.Indexer) indexer)
                            .documentExistsInIndex(metadata, id, kunderaMetadata, isEmbeddedId, clazz);

                    if (documentExistsInIndex)
                    {
                        ((com.impetus.kundera.index.lucene.Indexer) indexer).update(metadata, metamodel, entity, id,
                                parentId != null ? parentId.toString() : null);
                    }
                    else
                    {

                        boolean documentExists = ((com.impetus.kundera.index.lucene.Indexer) indexer)
                                .entityExistsInIndex(entity.getClass(), kunderaMetadata, metadata);
                        if (documentExists)
                        {
                            ((com.impetus.kundera.index.lucene.Indexer) indexer).unindex(metadata, id, kunderaMetadata,
                                    clazz);
                            ((com.impetus.kundera.index.lucene.Indexer) indexer).flush();
                        }
                        ((com.impetus.kundera.index.lucene.Indexer) indexer).index(metadata, metamodel, entity,
                                parentId != null ? parentId.toString() : null, clazz);
                    }
                }
                else
                {
                    MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                            metadata.getPersistenceUnit());

                    Map<String, PropertyIndex> indexProperties = metadata.getIndexProperties();
                    Map<String, Object> indexCollection = new HashMap<String, Object>();
                    Object id = PropertyAccessorHelper.getId(entity, metadata);
                    for (String columnName : indexProperties.keySet())
                    {
                        PropertyIndex index = indexProperties.get(columnName);
                        Field property = index.getProperty();
                        // String propertyName = index.getName();
                        Object obj = PropertyAccessorHelper.getObject(entity, property);
                        indexCollection.put(columnName, obj);
                    }

                    indexCollection.put(((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName(), id);

                    EntityMetadata parentMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, clazz);
                    if (parentId != null)
                        indexCollection.put(((AbstractAttribute) parentMetadata.getIdAttribute()).getJPAColumnName(),
                                parentId);

                    onEmbeddable(entity, metadata.getEntityClazz(), metaModel, indexCollection);
                    indexer.index(metadata.getEntityClazz(), metadata, indexCollection, parentId, clazz);
                }
            }
        }
        catch (PropertyAccessException e)
        {
            throw new IndexingException("Can't access ID from entity class " + metadata.getEntityClazz(), e);
        }
    }
1050306
public function postPersist(LifecycleEventArgs $args): void
    {
        // Get the object and make sure it is what we need.
        $object = $args->getObject();
        if (!$object instanceof PublishableInterface) {
            return;
        }

        // Execute published event after the object is persisted.
        if ($object->isPublished()) {
            $event = new EntityPublishedEvent($object);
            $this->event_dispatcher->dispatch(EntityPublishedEvent::NAME, $event);
        }
    }