private void doShip(final GoodPayload payload, long timeInMillis, final ShipResponse response)
      throws NoSuchArticleException {
    final List<Long> goodsToShip = new ArrayList<>();

    /* fetch good to ship ids */
    for (Map.Entry<Long, Integer> entry : payload.getGoods().entrySet()) {
      Collection<Long> goodIds =
          namedJdbcTemplate
              .getJdbcOperations()
              .query(
                  QUERY_FETCH_GOOD_IDS_TO_SHIP,
                  new Object[] {
                    /* article id */
                    entry.getKey(), /* goods count */ entry.getValue()
                  },
                  new ShipStatCollector(response));

      goodsToShip.addAll(goodIds);
    }

    if (goodsToShip.isEmpty()) {
      throw new NoSuchArticleException();
    }

    logger.info("remove good ids: " + goodsToShip);

    MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource();
    mapSqlParameterSource.addValue("shipTime", new Timestamp(timeInMillis), Types.TIMESTAMP);
    mapSqlParameterSource.addValue("goods", goodsToShip);
    namedJdbcTemplate.update(QUERY_SHIP_GOODS_BY_IDS, mapSqlParameterSource);
  }
示例#2
0
    protected void mergePatches(List<SchemaPatch> patches) {
      final List<DatabaseObject> objects = new ArrayList<>();

      Collections.sort(patches);

      for (SchemaPatch patch : patches) {
        validatePatch(patches, patch);

        objects.clear();
        List<DatabaseObject> tempObjects = new ArrayList<>();
        tempObjects.addAll(patch.getObjects());
        patch.clearObjects();
        patch.addObjects(mergeDatabaseObjects(tempObjects));

        targetStore.addPatch(patch);
      }
    }
  public static void main(String[] args) {
    // DBResourcesManager.initHibernate();

    OffertaEvento of = new OffertaEvento();
    of.setNome("ofevent");
    of.setTipologia("Concerto");
    of.setPrezzo(69);
    // of.setDataScadenza("21/08/2019");
    of.setCittà("Roma");

    Offerta offertaArray[] = {new OffertaEvento(), new OffertaPernotto(), new OffertaTrasporto()};
    /*
    for(Offerta o : offertaArray) {
        System.out.println(o.getClass().getSimpleName() + "\n");
        Method[] methods = o.getClass().getMethods();
        for (Method m : methods) {
            int l = m.getName().length();
            if (m.getName().substring(0, 3).equals("set") && !m.getName().substring(l - 2, l).equals("ID"))
                System.out.println(m.getName());
        }
    }*/
    /*
    OffertaBean object = new OffertaEventoBean();


    String query = "from "+ object.getClass().getSimpleName() + " where ";

    System.out.println(object.getClass().getSimpleName() + "\n");
    Method[] methods = object.getClass().getMethods();
    for (Method m : methods) {
        int l = m.getName().length();
        if (m.getName().substring(0, 3).equals("get") && !m.getName().substring(l - 2, l).equals("ID") && !m.getName().equals("getClass"))
        {
            String s = m.getName().substring(0,1).toLowerCase();
            String attributeLower = s + m.getName().substring(1);
            query = query + attributeLower + " = ";
        }
    }*/
    String città = "Roma";
    String dataScadenza = "11/07/2009";
    String nome = "Bubu";
    String prezzo = "4";
    String tipologia = "Museo";

    String query = "from OffertaEvento offertaEvento";

    query = query + " where ";
    if (città != null) query = query + "offertaEvento.città = '" + città + "' && ";
    if (dataScadenza != null)
      query = query + "offertaEvento.dataScadenza = '" + dataScadenza + "' && ";
    if (nome != null) query = query + "offertaEvento.nome = '" + nome + "' && ";
    if (prezzo != null) query = query + "offertaEvento.prezzo = '" + prezzo + "' && ";
    if (tipologia != null) query = query + "offertaEvento.tipologia = '" + tipologia + "'";

    System.out.println(query);

    ArrayList<String> ls = new ArrayList<String>();
    ls.add(città);
    ls.add(dataScadenza);
    ls.add(nome);
    ls.add(prezzo);
    ls.add(tipologia);
    System.out.println("\nNuova query\n");

    if (!ls.isEmpty()) query.join(" where");

    for (int i = 0; i < ls.size(); i++) {
      if (!ls.get(i).equals("") && i == 0)
        query.join(" && offertaEvento.città = '" + ls.get(i) + "'");
      if (!ls.get(i).equals("") && i == 1)
        query.join(" && offertaEvento.dataScadenza = '" + ls.get(i) + "'");
      if (!ls.get(i).equals("") && i == 2)
        query.join(" && offertaEvento.nome = '" + ls.get(i) + "'");
      if (!ls.get(i).equals("") && i == 3)
        query.join(" && offertaEvento.prezzo = '" + ls.get(i) + "'");
      if (!ls.get(i).equals("") && i == 4)
        query.join(" && offertaEvento.tipologia = '" + ls.get(i) + "'");
    }

    System.out.println(query);

    Offerta o = new OffertaEvento();

    List<Method> fields = Arrays.asList(o.getClass().getDeclaredMethods());

    Class c = o.getClass().getSuperclass();

    List<Method> superfields = Arrays.asList(c.getDeclaredMethods());

    List<Method> allfields = new ArrayList<Method>(fields);
    allfields.addAll(superfields);

    allfields.sort(
        new Comparator<Method>() {
          public int compare(Method o1, Method o2) {
            return o1.getName().compareTo(o1.getName());
          }
        });
    /*
    for(Method f: allfields){

    }*/
    java.sql.Date date = Date.valueOf(LocalDate.now());
    System.out.println(date);
    String datestring = date.toString();
    System.out.println(datestring);
    Date data2 = Date.valueOf(datestring);
    System.out.println(data2);
    // OffertaEventoDAO.store(of);

    // System.out.println(((List<OffertaEvento>)DAOFactory.getDAOFactory(TipoOfferta.OffertaEvento).getOffertaDAO().getList()).size());

    // DBResourcesManager.shutdown();

    // OffertaDaoAnnotations.findAllOffertaEntitysA("offertaevento","Concerto");
  }
 @Parameters(name = "{0} {1} {2}")
 public static Collection<Object> data() {
   List<Object> testCases = Lists.newArrayList();
   // Scan range is empty.
   testCases.addAll(foreach(ScanRanges.NOTHING, new int[] {1, 1, 1}, new KeyRange[] {}));
   // Scan range is everything.
   testCases.addAll(
       foreach(
           ScanRanges.EVERYTHING,
           new int[] {1, 1, 1},
           new KeyRange[] {
             getKeyRange(KeyRange.UNBOUND, true, Ka1A, false),
             getKeyRange(Ka1A, true, Ka1B, false),
             getKeyRange(Ka1B, true, Ka1E, false),
             getKeyRange(Ka1E, true, Ka1G, false),
             getKeyRange(Ka1G, true, Ka1I, false),
             getKeyRange(Ka1I, true, Ka2A, false),
             getKeyRange(Ka2A, true, KeyRange.UNBOUND, false)
           }));
   // Scan range lies inside first region.
   testCases.addAll(
       foreach(
           new KeyRange[][] {
             {getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true)},
             {getKeyRange(Bytes.toBytes("0"), true, Bytes.toBytes("0"), true)},
             {getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("Z"), true)}
           },
           new int[] {1, 1, 1},
           new KeyRange[] {getKeyRange(KeyRange.UNBOUND, true, Ka1A, false)}));
   // Scan range lies in between first and second, intersecting bound on second.
   testCases.addAll(
       foreach(
           new KeyRange[][] {
             {getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true)},
             {
               getKeyRange(Bytes.toBytes("0"), true, Bytes.toBytes("0"), true),
               getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true)
             },
             {getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true)}
           },
           new int[] {1, 1, 1},
           new KeyRange[] {
             getKeyRange(KeyRange.UNBOUND, true, Ka1A, false),
             getKeyRange(Ka1A, true, Ka1B, false),
           }));
   // Scan range spans third, split into 3 due to concurrency config.
   testCases.addAll(
       foreach(
           new KeyRange[][] {
             {getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true)},
             {getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true)},
             {getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("E"), false)}
           },
           new int[] {1, 1, 1},
           new KeyRange[] {
             getKeyRange(Ka1B, true, Ka1C, false),
             getKeyRange(Ka1C, true, Ka1D, false),
             getKeyRange(Ka1D, true, Ka1E, false),
           }));
   // Scan range spans third, split into 3 due to concurrency config.
   testCases.addAll(
       foreach(
           new KeyRange[][] {
             {getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true)},
             {getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true)},
             {getKeyRange(Bytes.toBytes("B"), true, Bytes.toBytes("E"), false)}
           },
           new int[] {1, 1, 1},
           new KeyRange[] {
             getKeyRange(Ka1B, true, Ka1C, false),
             getKeyRange(Ka1C, true, Ka1D, false),
             getKeyRange(Ka1D, true, Ka1E, false),
           }));
   // Scan range spans 2 ranges, split into 4 due to concurrency config.
   testCases.addAll(
       foreach(
           new KeyRange[][] {
             {getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true)},
             {getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true)},
             {getKeyRange(Bytes.toBytes("F"), true, Bytes.toBytes("H"), false)}
           },
           new int[] {1, 1, 1},
           new KeyRange[] {
             getKeyRange(Ka1E, true, Ka1F, false),
             getKeyRange(Ka1F, true, Ka1G, false),
             getKeyRange(Ka1G, true, Ka1H, false),
             getKeyRange(Ka1H, true, Ka1I, false),
           }));
   // Scan range spans more than 3 range, no split.
   testCases.addAll(
       foreach(
           new KeyRange[][] {
             {
               getKeyRange(Bytes.toBytes("a"), true, Bytes.toBytes("a"), true),
               getKeyRange(Bytes.toBytes("b"), true, Bytes.toBytes("b"), true)
             },
             {
               getKeyRange(Bytes.toBytes("1"), true, Bytes.toBytes("1"), true),
               getKeyRange(Bytes.toBytes("2"), true, Bytes.toBytes("2"), true),
             },
             {
               getKeyRange(Bytes.toBytes("A"), true, Bytes.toBytes("A"), true),
               getKeyRange(Bytes.toBytes("C"), true, Bytes.toBytes("D"), true),
               getKeyRange(Bytes.toBytes("G"), true, Bytes.toBytes("G"), true)
             }
           },
           new int[] {1, 1, 1},
           new KeyRange[] {
             getKeyRange(Ka1A, true, Ka1B, false),
             getKeyRange(Ka1B, true, Ka1E, false),
             getKeyRange(Ka1G, true, Ka1I, false),
             getKeyRange(Ka2A, true, KeyRange.UNBOUND, false)
           }));
   return testCases;
 }