Ejemplo n.º 1
1
  public boolean settleColorsIntoDB() {
    try {
      ArrayList<Color> colors = new ArrayList<>();
      File file = new File(MyPathManager.colorsPath);
      if (file.isFile() && file.exists()) {
        InputStreamReader read =
            new InputStreamReader(new FileInputStream(file), "UTF-8"); // 考虑到编码格式
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineTxt = null;
        while ((lineTxt = bufferedReader.readLine()) != null) {
          String[] data = lineTxt.split(" ", 7);
          //                    黑色 0 0 0 Black 1253.26 1253260
          colors.add(
              new Color(
                  data[0],
                  data[4],
                  Integer.valueOf(data[1]),
                  Integer.valueOf(data[2]),
                  Integer.valueOf(data[3]),
                  data[6],
                  data[5]));
        }
        read.close();

        Session session = HibernateSessionFactory.getSessionFactory().openSession();
        try {
          session.beginTransaction();
          session.createSQLQuery("ALTER TABLE colors AUTO_INCREMENT = 1;").executeUpdate();
          colors.forEach(hibernate.elements.Color::refresh);
          colors.forEach(session::persist);
          session.getTransaction().commit();
        } catch (Exception e) {
          session.getTransaction().rollback();
        } finally {
          session.close();
        }
        logger.debug("[FILE 99.txt] settles into database successfully.");
        return true;
      } else {
        logger.debug("[FILE 99.txt] 404 NOT FOUND!");
      }
    } catch (Exception e) {
      logger.debug(e.getMessage());
      logger.debug("READ [FILE 99.txt] ERROR");
      //            e.printStackTrace();
    }
    return false;
  }
Ejemplo n.º 2
0
  public boolean settleColorPrefixIntoDB() {
    Session session = HibernateSessionFactory.getSessionFactory().openSession();

    try {
      session.beginTransaction();
      List<Color> colors = session.createQuery("select c from Color as c").list();
      File file = new File(MyPathManager.colorPrefixPath);
      if (file.isFile() && file.exists()) {
        InputStreamReader read =
            new InputStreamReader(new FileInputStream(file), "UTF-8"); // 考虑到编码格式
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineTxt = null;
        for (Color color : colors) {
          if ((lineTxt = bufferedReader.readLine()) != null) {
            String[] data2 = lineTxt.split(",", 12);
            boolean[] data = new boolean[12];
            System.out.println(data2.length);
            for (int i = 0; i < 12; i++) {
              if (data2[i].equals("1")) {
                data[i] = true;
              } else {
                data[i] = false;
              }
            }
            color.setPrefixColor(
                data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8],
                data[9], data[10], data[11]);
          }
        }
        logger.debug("[FILE color-prefix.txt] settles into database successfully.");
        read.close();
        session.getTransaction().commit();
        return true;
      } else {
        logger.debug("[FILE color-prefix.txt] 404 NOT FOUND!");
      }
    } catch (Exception e) {
      logger.debug(e.getMessage());
      logger.debug("READ [FILE color-prefix.txt] ERROR");
      e.printStackTrace();
      session.getTransaction().rollback();
    } finally {
      session.close();
    }
    return false;
  }
Ejemplo n.º 3
0
 public boolean settleBDressesIntoDB() {
   try {
     ArrayList<HDress> dresses = new ArrayList<>();
     File file = new File(MyPathManager.B_DressPath);
     if (file.isFile() && file.exists()) {
       InputStreamReader read =
           new InputStreamReader(new FileInputStream(file), "UTF-8"); // 考虑到编码格式
       BufferedReader bufferedReader = new BufferedReader(read);
       String lineTxt = null;
       while ((lineTxt = bufferedReader.readLine()) != null) {
         String[] data = lineTxt.split(";", 4);
         //                 瑞丽;蛋糕裙;超短裙;高腰
         dresses.add(new HDress(data[3], data[0], data[1], data[2]));
       }
       read.close();
       Session session = HibernateSessionFactory.getSessionFactory().openSession();
       try {
         session.beginTransaction();
         session.createQuery("delete from HDress").executeUpdate();
         session
             .createSQLQuery("ALTER TABLE half_body_dresses AUTO_INCREMENT = 1;")
             .executeUpdate();
         dresses.forEach(session::persist);
         session.getTransaction().commit();
       } catch (Exception e) {
         session.getTransaction().rollback();
       } finally {
         session.close();
       }
       logger.debug("[FILE B-Dress.txt] settles into database successfully.");
       return true;
     } else {
       logger.debug("[FILE B-Dress.txt] 404 NOT FOUND!");
     }
   } catch (Exception e) {
     logger.debug(e.getMessage());
     logger.debug("READ [FILE B-Dress.txt] ERROR");
     e.printStackTrace();
   }
   return false;
 }