Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.github.molcikas.photon.query;
import com.github.molcikas.photon.PhotonEntityState;
import com.github.molcikas.photon.blueprints.entity.EntityBlueprint;
import com.github.molcikas.photon.blueprints.entity.FieldBlueprint;
import com.github.molcikas.photon.blueprints.table.TableBlueprint;
import com.github.molcikas.photon.blueprints.table.TableValue;
import com.github.molcikas.photon.options.PhotonOptions;
import java.sql.Connection;
import java.util.*;
import java.util.stream.Collectors;
public class Orphans
{
public static void findAndDelete(
EntityBlueprint entityBlueprint,
List populatedEntities,
PopulatedEntity parentPopulatedEntity,
FieldBlueprint parentFieldBlueprint,
PhotonEntityState photonEntityState,
Connection connection,
PhotonOptions photonOptions)
{
if(parentFieldBlueprint == null)
{
return;
}
TableBlueprint tableBlueprint = entityBlueprint.getTableBlueprint();
List childIds = populatedEntities
.stream()
.map(PopulatedEntity::getPrimaryKeyValue)
.filter(Objects::nonNull) // Auto increment entities that have not been inserted yet will have null primary key values.
.map(TableValue::new)
.collect(Collectors.toList());
Set trackedKeys =
photonEntityState.getTrackedChildrenKeys(parentFieldBlueprint, parentPopulatedEntity.getPrimaryKey());
if(trackedKeys != null && new HashSet<>(childIds).equals(trackedKeys))
{
return;
}
if(tableBlueprint.isPrimaryKeyMappedToField())
{
String primaryKeyColumnName = tableBlueprint.getPrimaryKeyColumnName();
String selectOrphansSql = tableBlueprint.getSelectOrphansSql();
if(selectOrphansSql == null)
{
// If the primary key and foreign key to parent are equal, there won't be any select orphans sql because
// there can't be any orphans, so just return.
return;
}
List