0

以下是我试图搜索 WT 部分的代码

public static WTSet searchWTPart(String partNumber, String type, boolean exactMatch ,String productfamilyforjsp,String ordertypeformjsp) throws WTException {

        System.out.println("Method partNumber "+partNumber);
        long branchId = 0;
        int iPartMaster, iPart;
        String criteria;
        QueryResult qr = null;



        //wt.pds.PartialResultException qr1 = new PartialResultException(arg0);
        QuerySpec qs= new QuerySpec();
        iPartMaster = qs.addClassList(WTPartMaster.class,true);

        int defindex = qs.addClassList(StringDefinition.class, false);
        int valueindex = qs.addClassList(StringValue.class, false);


        // search  product Family as per jsp product family Input  

        if(productfamilyforjsp.equalsIgnoreCase("Helical/Emill"))
        {
            productfamilyforjsp="Helical";
        }

        if(productfamilyforjsp.equalsIgnoreCase("Fluid Coupling"))
        {
            productfamilyforjsp="Fluid Coupling";
        }
        if(productfamilyforjsp.equalsIgnoreCase("Worm/Altra"))
        {
            productfamilyforjsp="Worm";
        }

        if(productfamilyforjsp.equalsIgnoreCase("Gear Motor"))
        {
            productfamilyforjsp="Geared motor";
        }
        if(productfamilyforjsp.equalsIgnoreCase("Planetary"))
        {
            productfamilyforjsp="Planetary";
        }
        if(productfamilyforjsp.equalsIgnoreCase("Lift"))
        {
            productfamilyforjsp="Lift";
        }





        if(partNumber.contains("*")){
            System.out.println("Leng: "+partNumber.length());
            partNumber=partNumber.substring(0, (partNumber.length()-1));
            partNumber=partNumber+"%";
            partNumber=partNumber.toUpperCase();

            System.out.println("Key: "+partNumber);
        }
        else{
            partNumber="%"+partNumber+"%";
            partNumber=partNumber.toUpperCase();

        }
        System.out.println("Process part NO :-"+partNumber);
        iPart=qs.appendClassList(WTPart.class,false);
        if(exactMatch){criteria = SearchCondition.EQUAL;}
        else{criteria = SearchCondition.LIKE;}
        System.out.println("criteria for check :-"+criteria);
        SearchCondition sc_number=new SearchCondition(WTPartMaster.class, WTPartMaster.NUMBER, criteria, partNumber);
        SearchCondition sc_master=new SearchCondition(WTPart.class, "masterReference.key.id", WTPartMaster.class, "thePersistInfo.theObjectIdentifier.id");

        TypeDefinitionReference tref=TypedUtility.getTypeDefinitionReference(type);
        branchId = tref.getKey().getBranchId();
        SearchCondition sc_branch=new SearchCondition(WTPart.class,"typeDefinitionReference.key.branchId",SearchCondition.EQUAL,branchId);
        qs.appendWhere(sc_master,new int []{iPart,iPartMaster});
        qs.appendAnd();
        qs.appendWhere(sc_number, new int[]{iPartMaster});
        qs.appendAnd();

        qs.appendWhere(sc_branch, new int[]{iPart});

        /*qs.appendAnd();

        qs.appendWhere(new SearchCondition(StringDefinition.class,
                StringDefinition.NAME, SearchCondition.EQUAL, "WERKS"),
                defindex);

        qs.appendAnd();

        qs.appendWhere(new SearchCondition(StringValue.class,
                StringValue.VALUE, SearchCondition.EQUAL, productfamilyforjsp),
                valueindex);
        qs.appendAnd();
        // to check value and name is equal 
        qs.appendWhere(new SearchCondition(StringDefinition.class,
                "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                "definitionReference.key.id"),
                new int[] { defindex, valueindex });
        */
        qs.appendAnd();
        if(ordertypeformjsp.equalsIgnoreCase("ZUNT - Unit Sales"))
        {
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    StringDefinition.NAME, SearchCondition.EQUAL, "MTART"),
                    defindex);

            qs.appendAnd();

            qs.appendWhere(new SearchCondition(StringValue.class,
                    StringValue.VALUE, SearchCondition.LIKE, "ZFRT"),
                    valueindex);
                qs.appendAnd();
            // to check value and name is equal 
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                    "definitionReference.key.id"),
                    new int[] { defindex, valueindex });
            //qs.appendHaving(new SearchCondition(StringDefinition.class,StringDefinition.NAME, SearchCondition.EQUAL, "MTART"), defindex);



        }

        if(ordertypeformjsp.equalsIgnoreCase("ZEXP - Export Sales"))
        {
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    StringDefinition.NAME, SearchCondition.EQUAL, "MTART"),
                    defindex);

            qs.appendAnd();

            qs.appendWhere(new SearchCondition(StringValue.class,
                    StringValue.VALUE, SearchCondition.EQUAL, "ZFRT"),
                    valueindex);
            qs.appendAnd();
            // to check value and name is equal 
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                    "definitionReference.key.id"),
                    new int[] { defindex, valueindex });

            qs.appendOr();

            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    StringDefinition.NAME, SearchCondition.EQUAL, "MTART"),
                    defindex);

            qs.appendAnd();

            qs.appendWhere(new SearchCondition(StringValue.class,
                    StringValue.VALUE, SearchCondition.EQUAL, "ZSPR"),
                    valueindex);
            qs.appendAnd();
            // to check value and name is equal 
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                    "definitionReference.key.id"),
                    new int[] { defindex, valueindex });


        }

        if(ordertypeformjsp.equalsIgnoreCase("ZDEX - Deemed Exports"))
        {
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    StringDefinition.NAME, SearchCondition.EQUAL, "MTART"),
                    defindex);

            qs.appendAnd();

            qs.appendWhere(new SearchCondition(StringValue.class,
                    StringValue.VALUE, SearchCondition.EQUAL, "ZFRT"),
                    valueindex);
            qs.appendAnd();
            // to check value and name is equal 
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                    "definitionReference.key.id"),
                    new int[] { defindex, valueindex });

            qs.appendOr();

            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    StringDefinition.NAME, SearchCondition.EQUAL, "MTART"),
                    defindex);

            qs.appendAnd();

            qs.appendWhere(new SearchCondition(StringValue.class,
                    StringValue.VALUE, SearchCondition.EQUAL, "ZSPR"),
                    valueindex);
            qs.appendAnd();
            // to check value and name is equal 
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                    "definitionReference.key.id"),
                    new int[] { defindex, valueindex });


        }

        if(ordertypeformjsp.equalsIgnoreCase("ZSPA - Spares Sales"))
        {
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    StringDefinition.NAME, SearchCondition.EQUAL, "MTART"),
                    defindex);

            qs.appendAnd();

            qs.appendWhere(new SearchCondition(StringValue.class,
                    StringValue.VALUE, SearchCondition.EQUAL, "ZSPR"),
                    valueindex);
            qs.appendAnd();
            // to check value and name is equal 
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                    "definitionReference.key.id"),
                    new int[] { defindex, valueindex });




        }

        if(ordertypeformjsp.equalsIgnoreCase("ZTRD - Third Party Sales"))
        {
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    StringDefinition.NAME, SearchCondition.EQUAL, "MTART"),
                    defindex);

            qs.appendAnd();

            qs.appendWhere(new SearchCondition(StringValue.class,
                    StringValue.VALUE, SearchCondition.EQUAL, "ZSPR"),
                    valueindex);
            qs.appendAnd();
            // to check value and name is equal 
            qs.appendWhere(new SearchCondition(StringDefinition.class,
                    "thePersistInfo.theObjectIdentifier.id", StringValue.class,
                    "definitionReference.key.id"),
                    new int[] { defindex, valueindex });




        }
        System.out.println("\n\n ======== QUERY =======\n" + qs.toString() + "\n====================\n");
        qr = new QueryResult();
        qr = PersistenceHelper.manager.find((StatementSpec) qs);

    //  qs.setQueryLimit(-1);

        System.out.println("searchWTPart");
        System.out.println("Query size : " + qr.size());

        WTSet set = new WTHashSet(qr);
        System.out.println("Found " + set.size() + " objects!");


        //System.out.println("PART querystring: \n "+qs.toString());


                    System.out.println("size"+set.size());
            Iterator<?> it = null;
            it = set.persistableIterator();
            String number="";

            WTPart part =null;
        while(it.hasNext())
        {
            WTPartMaster partMaster = (WTPartMaster) it.next();
             part = (WTPart) VersionControlHelper.service.allIterationsOf(partMaster).nextElement();
             number=part.getNumber();
             System.out.println(number);

        }
return set;

}
4

1 回答 1

0

使用 StringValue 作为主类执行 QuerySpec 搜索。之后,您可以获得拥有该值的对象的引用。

于 2016-02-23T16:23:18.630 回答