首页 > 解决方案 > 如何从不同的包中调用类

问题描述

大家早上好,当我想用​​不同的包裹打电话给我的班级时,我遇到了问题。我有用

private void getExecutionReport(quickfix.Message message, String tipeMessage) {
            // TODO Auto-generated method stub
             try {
                 System.out.print("Message "+ message);
                StringField msgType = message.getHeader().getField(new MsgType());
                System.out.print("getExecutionReport "+tipeMessage);
                String symbol = message.getString(Symbol.FIELD);
                System.out.print("getExecutionReport "+symbol);
                String clorid = message.getString(ClOrdID.FIELD);
                String orderid = message.getString(OrderID.FIELD);
                String execid = message.getString(ExecID.FIELD);
                String execTransType = message.getString(ExecTransType.FIELD);
                String ordertype = message.getString(OrdType.FIELD);
                String exectype = message.getString(ExecType.FIELD);
                String orderstatus = message.getString(OrdStatus.FIELD);
                int side = message.getInt(Side.FIELD);
                Double orderqty = message.getDouble(OrderQty.FIELD);
                int leavesqty = message.getInt(LeavesQty.FIELD);
                 double price = message.getDouble(Price.FIELD);
                int cumqty = message.getInt(CumQty.FIELD);
                int lastqty = message.getInt(LastQty.FIELD);
                 //call Class in different package 

DAOInsert.newOrderSingleInsert(tipeMessage,symbol,clorid,orderid,execid,execTransType,ordertype,exectype,orderstatus,side,orderqty,leavesqty,price,cumqty,lastqty);

            } catch (FieldNotFound e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

但是当我想上这门课时

public class DAOInsert {
    private DAOInsert dAOInsert;
    static Session sessionObj;
    static SessionFactory sessionFactoryObj;

    public final static Logger logger = Logger.getLogger(DAOInsert.class);

    // This Method Is Used To Create The Hibernate's SessionFactory Object
    private static SessionFactory buildSessionFactory() {
        // Creating Configuration Instance & Passing Hibernate Configuration File
        Configuration configObj = new Configuration();
        configObj.configure("hibernate.cfg.xml");

        // Since Hibernate Version 4.x, ServiceRegistry Is Being Used
        ServiceRegistry serviceRegistryObj = new StandardServiceRegistryBuilder().applySettings(configObj.getProperties()).build(); 

        // Creating Hibernate SessionFactory Instance
        sessionFactoryObj = configObj.buildSessionFactory(serviceRegistryObj);
        return sessionFactoryObj;
    }

    public static void newOrderSingleInsert(String tipeMessage, String symbol, String clorid, String orderid, String execid, String execTransType, String ordertype, String exectype, String orderstatus, int side, Double orderqty, int leavesqty, double price, int cumqty, int lastqty){
          int count = 0;
          NewOrderSingle newordersingleObj = null;
          try {
              System.out.print("DAOInsert "+tipeMessage);
              // Getting Session Object From SessionFactory
              sessionObj = buildSessionFactory().openSession();
              // Getting Transaction Object From Session Object
              sessionObj.beginTransaction();

              // Creating Transaction Entities
            //  newordersingleObj = new NewOrderSingle();             
              //newordersingleObj.setFixProtocol("FIX.4.2");
              //newordersingleObj.setBodyLength(250);
                  //sessionObj.save(newordersingleObj);

              // Committing The Transactions To The Database
              //sessionObj.getTransaction().commit();
              //logger.info("\nSuccessfully Created '" + count + "' Records In The Database!\n");
          } catch(Exception sqlException) {
              if(null != sessionObj.getTransaction()) {
                  logger.info("\n.......Transaction Is Being Rolled Back.......\n");
                  sessionObj.getTransaction().rollback();
              }
              sqlException.printStackTrace();
          } finally {
              if(sessionObj != null) {
                  sessionObj.close();
              }
          }
      }



}

我无法使用我的第一种方法来上课。我上课时有什么问题?请帮我解决我的问题

标签: javaclassoop

解决方案


推荐阅读