Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<ExcepcionPorProductoDetalle> getDetallesByCodigoExcepcion(ExcepcionPorProductoDetalle excepcion) throws Exception {
- ExcepcionPorProductoDetalle productos = new ExcepcionPorProductoDetalle();
- productos.setCodigoExcepcion(excepcion.getCodigoExcepcion());
- List<ExcepcionPorProductoDetalle> detalles = null;
- MapConfig config;
- LoadSettings settings = new LoadSettings();
- settings.setQueryStatement(LoadListByExcepcion);
- settings.setColumns(
- ExcepcionPorProductoDetalle.Columnas.CODIGO_ABONADO,
- ExcepcionPorProductoDetalle.Columnas.CODIGO_DETALLE,
- ExcepcionPorProductoDetalle.Columnas.IDENTIFICADOR,
- ExcepcionPorProductoDetalle.Columnas.CODIGO_EXCEPCION,
- ExcepcionPorProductoDetalle.Columnas.LIMIT,
- ExcepcionPorProductoDetalle.Columnas.OFFSET
- );
- settings.setPreventTopLoad(false);
- settings.setParalelizeMultiPartition(true);
- if (excepcion.getLineaPdvMaxicarga().getCodigoPuntoVenta() == null) {
- config = new MapConfig(ExcepcionPorProductoDetalle.class, null, false);
- } else {
- config = new MapConfig(ExcepcionPorProductoDetalle.class, DefaultView.class, false);
- }
- int inicio = excepcion.getOffset();
- int limit = excepcion.getLimit();
- List<PartitionInfo> listaParticiones = new ArrayList<PartitionInfo>();
- listaParticiones.addAll(cantRegEnParticiones.keySet());
- int i = 0;
- int registros = 0;
- /* Se ordenan las particiones por PartitionId, para recorrer las particiones
- * en un orden establecido */
- listaParticiones.sort(Comparator.comparing(PartitionInfo::getPartitionId));
- for (i = 0; i < listaParticiones.size(); i++) {
- PartitionInfo pI = listaParticiones.get(i);
- registros += cantRegEnParticiones.get(pI);
- if (registros >= inicio) {
- int cantAnterior = registros - cantRegEnParticiones.get(pI);
- if (i > 0) {
- excepcion.setOffset(inicio - cantAnterior);
- }
- detalles = super.singlePartitionedLoadList(excepcion, config, pI.getPartitionKey(), settings);
- i++;
- break;
- }
- }
- /*
- * Si la lista de abonados aún no se llenó con la cantidad buscada en el limit
- * se consulta en otra particion existente en la tabla.
- */
- while (detalles.size() < limit && i < listaParticiones.size()) {
- // Se trae de la siguiente partición los elementos que faltan;
- excepcion.setLimit(limit - detalles.size());
- excepcion.setOffset(0);
- PartitionInfo pI = listaParticiones.get(i);
- List<ExcepcionPorProductoDetalle> restantes = super.singlePartitionedLoadList(excepcion, config, pI.getPartitionKey(), settings);
- detalles.addAll(restantes);
- i++;
- }
- return detalles;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement