Delete by primary key.

@param entity
the entity
@param pKey
the key
432769
@Override
    public void delete(Object entity, Object pKey)
    {
        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entity.getClass());
        MetamodelImpl metamodel = (MetamodelImpl) KunderaMetadataManager.getMetamodel(kunderaMetadata,
                entityMetadata.getPersistenceUnit());

        String idColumnName = ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName();

        Table schemaTable = tableAPI.getTable(entityMetadata.getTableName());

        PrimaryKey key = schemaTable.createPrimaryKey();

        if (metamodel.isEmbeddable(entityMetadata.getIdAttribute().getBindableJavaType()))
        {
            EmbeddableType embeddableId = metamodel.embeddable(entityMetadata.getIdAttribute().getBindableJavaType());
            Set<Attribute> embeddedAttributes = embeddableId.getAttributes();

            for (Attribute embeddedAttrib : embeddedAttributes)
            {
                String columnName = ((AbstractAttribute) embeddedAttrib).getJPAColumnName();
                Object embeddedColumn = PropertyAccessorHelper.getObject(pKey, (Field) embeddedAttrib.getJavaMember());

                NoSqlDBUtils.add(schemaTable.getField(columnName), key, embeddedColumn, columnName);
            }
        }
        else
        {
            NoSqlDBUtils.add(schemaTable.getField(idColumnName), key, pKey, idColumnName);
        }

        tableAPI.delete(key, null, null);
        KunderaCoreUtils.printQuery("Delete data from " + entityMetadata.getTableName() + " for PK " + pKey, showQuery);
    }
138564
public static void removeCache(Class<? extends BaseEntity> entityClass,String key){
    	if(CacheHandler.cacheProvider == null)return;
    	String entityClassName = entityClass.getSimpleName();
		key = entityClassName + CacheHandler.SPLIT_PONIT + key;
		String cacheGroupKey = entityClassName + CacheHandler.GROUPKEY_SUFFIX;
		
		CacheHandler.cacheProvider.remove(key);
		CacheHandler.cacheProvider.removeFromGroup(cacheGroupKey, key);
		
	}
678889
private boolean hasPrimaryKey(T entity) {
        Object pk = getPrimaryKey(entity);
        if (pk == null) {
            return false;
        } else {
            if (pk instanceof Number && ((Number) pk).longValue() == 0) {
                return false;
            }
        }
        return true;
    }
166738
public static void delete( Key key ) { 
    Value val = DKV.get(key);
    if( val==null ) return;
    ((Lockable)val.get()).delete();
  }
824171
@Override
  protected void deleteEntity(DbEntityOperation operation) {

    final DbEntity dbEntity = operation.getEntity();

    // get statement
    String deleteStatement = dbSqlSessionFactory.getDeleteStatement(dbEntity.getClass());
    ensureNotNull("no delete statement for " + dbEntity.getClass() + " in the ibatis mapping files", "deleteStatement", deleteStatement);

    LOG.executeDatabaseOperation("DELETE", dbEntity);

    // execute the delete
    int nrOfRowsDeleted = executeDelete(deleteStatement, dbEntity);
    operation.setRowsAffected(nrOfRowsDeleted);

    // It only makes sense to check for optimistic locking exceptions for objects that actually have a revision
    if (dbEntity instanceof HasDbRevision && nrOfRowsDeleted == 0) {
      operation.setFailed(true);
      return;
    }

    // perform post delete action
    entityDeleted(dbEntity);
  }
198761
public void delete(int key) {
        int i = ContainerHelpers.binarySearch(mKeys, mSize, key);

        if (i >= 0) {
            if (mValues[i] != DELETED) {
                mValues[i] = DELETED;
                mGarbage = true;
            }
        }
    }
629560
public void deleteByColumn(String schemaName, String tableName, String columnName, Object columnValue)
    {
        try
        {
            handler.deleteRow(columnValue, schemaName, tableName);
            KunderaCoreUtils.printQuery("Delete data from " + tableName + " for PK " + columnValue, showQuery);
        }
        catch (IOException ioex)
        {
            log.error("Error during get columns by key. Caused by: .", ioex);
            throw new PersistenceException(ioex);
        }
    }
710824
@Override
    public synchronized void dropEntity(final DbEntity entity) throws DatabaseEngineException {
        dropSequences(entity);
        dropTable(entity);
        entities.remove(entity.getName());
        logger.trace("Entity {} dropped", entity.getName());
    }
1092905
@Override
    public T remove(T entity) {
        EntityManager entityManager = getEntityManager();
        if (entityManager.contains(entity)) {
            entityManager.remove(entity);
        } else {
            entityManager.remove(entityManager.merge(entity));
        }
        return entity;
    }
129473
public function deleteEntity($entity)
    {
        if (!$this->isExtendedField($entity)) {
            return parent::deleteEntity($entity);
        }

        // Pre-delete event (same as core).
        $id    = $entity->getId();
        $event = $this->dispatchEvent('pre_delete', $entity);
        $this->getRepository()->deleteEntity($entity);

        $schema        = $this->getSchemaDefinition($entity->getName(), $entity->getType());
        $secure        = 'extendedFieldSecure' === $entity->getObject() ? '_secure' : '';
        $extendedTable = MAUTIC_TABLE_PREFIX.'lead_fields_leads_'.$schema['type'].$secure.'_xref';
        $column        = [
            'lead_field_id' => $entity->getId(),
        ];
        $this->em->getConnection()->delete(
            $extendedTable,
            $column
        );

        // Post-delete event (same as core).
        // set the id for use in events
        $entity->deletedId = $id;
        $this->dispatchEvent('post_delete', $entity, false, $event);
    }
1231167
@Override
  public final <T> void deleteEntityWhere(final Map<String, Object> pAddParam,
    final Class<T> pEntityClass, final String pWhere) throws Exception {
    if (pWhere == null) {
      throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER,
        "param_null_not_accepted");
    }
    getSrvDatabase().executeDelete(pEntityClass.getSimpleName()
      .toUpperCase(), pWhere);
  }
1140701
@Override
    public void detach(Object entity) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "em.detach(" + entity + ");\n" + toString());

        getEMInvocationInfo(false).detach(entity);
    }
1046713
@Override
    protected void delete(Object entity, Object pKey)
    {

        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entity.getClass());
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(entityMetadata.getPersistenceUnit());
        EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz());

        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);
        }
        Delete delete = table.newDelete();
        PartialRow row = delete.getRow();
        String idColumnName = ((AbstractAttribute) entityMetadata.getIdAttribute()).getName();

        Field field = (Field) entityType.getAttribute(idColumnName).getJavaMember();
        Object value = PropertyAccessorHelper.getObject(entity, field);
        Type idType = KuduDBValidationClassMapper.getValidTypeForClass(field.getType());

        if (entityType.getAttribute(idColumnName).getJavaType().isAnnotationPresent(Embeddable.class))
        {
            // Composite Id
            EmbeddableType embeddableIdType = metaModel.embeddable(entityType.getAttribute(idColumnName).getJavaType());
            Field[] fields = entityType.getAttribute(idColumnName).getJavaType().getDeclaredFields();
            addPrimaryKeyToRow(row, embeddableIdType, fields, metaModel, value);
        }
        else
        {
            // Simple Id
            KuduDBDataHandler.addToRow(row, ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName(),
                    value, idType);
        }

        try
        {
            session.apply(delete);
        }
        catch (Exception e)
        {
            logger.error("Cannot delete row from table : " + entityMetadata.getTableName(), e);
            throw new KunderaException("Cannot delete row from table : " + entityMetadata.getTableName(), e);
        }
        finally
        {
            try
            {
                session.close();
            }
            catch (Exception e)
            {
                logger.error("Cannot close session", e);
                throw new KunderaException("Cannot close session", e);
            }
        }
    }
715776
public function delete($entity)
    {
        $this->gateway->delete($this->tableName, $this->builder->reduce($entity), $this->getIdentifier($entity));
    }
1246415
public <E> void delete(Class<E> entityClass, DatastoreKey parentKey, long id) {
    try {
      EntityMetadata entityMetadata = EntityIntrospector.introspect(entityClass);
      Key nativeKey = Key.newBuilder(parentKey.nativeKey(), entityMetadata.getKind(), id).build();
      nativeWriter.delete(nativeKey);
    } catch (DatastoreException exp) {
      throw DatastoreUtils.wrap(exp);
    }
  }
292551
@Override
    public void delete(Object entity, Object pKey)
    {
        if (!isOpen())
        {
            throw new PersistenceException("PelopsClient is closed.");
        }
        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entity.getClass());

        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                metadata.getPersistenceUnit());
        AbstractManagedType managedType = (AbstractManagedType) metaModel.entity(metadata.getEntityClazz());
        // For secondary tables.
        List<String> secondaryTables = ((DefaultEntityAnnotationProcessor) managedType.getEntityAnnotation())
                .getSecondaryTablesName();
        secondaryTables.add(metadata.getTableName());

        for (String tableName : secondaryTables)
        {
            if (isCql3Enabled(metadata))
            {
                String deleteQuery = onDeleteQuery(metadata, tableName, metaModel, pKey);
                executeCQLQuery(deleteQuery, isCql3Enabled(metadata));
            }
            else
            {
                if (metadata.isCounterColumnType())
                {
                    deleteRecordFromCounterColumnFamily(pKey, tableName, metadata, getConsistencyLevel());
                }
                else
                {
                    RowDeletor rowDeletor = clientFactory.getRowDeletor(pool);
                    rowDeletor.deleteRow(tableName, Bytes.fromByteBuffer(CassandraUtilities.toBytes(pKey, metadata
                            .getIdAttribute().getJavaType())), getConsistencyLevel());

                }
            }
        }
        getIndexManager().remove(metadata, entity, pKey);

        // Delete from Inverted Index if applicable
        Object conn = getConnection();
        try
        {
            invertedIndexHandler.delete(entity, metadata, getConsistencyLevel(), kunderaMetadata);
        }
        finally
        {
            if (conn != null)
            {
                releaseConnection(conn);
            }
        }
    }
662561
public void deleteByKey(DatastoreKey key) {
    try {
      nativeWriter.delete(key.nativeKey());
    } catch (DatastoreException exp) {
      throw DatastoreUtils.wrap(exp);
    }
  }