Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中创建父子关系?_Java_Database_Parent - Fatal编程技术网

如何在Java中创建父子关系?

如何在Java中创建父子关系?,java,database,parent,Java,Database,Parent,我需要为以下字符串创建父子关系: ((OPERATING_CARRIER='AB' OR OPERATING_CARRIER='EY' OR (OPERATING_CARRIER='VA' AND (FLIGHT_NO=604 OR FLIGHT_NO=603)))) 我必须将它们插入数据库表中,如下所示 ID PARENT_ID ENTITY OPERATOR VALUE 1 OPERATING_CARRIER =

我需要为以下字符串创建父子关系:

((OPERATING_CARRIER='AB' OR OPERATING_CARRIER='EY' OR (OPERATING_CARRIER='VA' AND (FLIGHT_NO=604 OR FLIGHT_NO=603))))
我必须将它们插入数据库表中,如下所示

ID  PARENT_ID   ENTITY             OPERATOR     VALUE
1               OPERATING_CARRIER   =           AB
2               OPERATING_CARRIER   =           EY
3               OPERATING_CARRIER   =           VA
4   3           FLIGHT_NO           =           604
5   3           FLIGHT_NO           =           603
使用以下代码

  package whereclause;

    import java.util.Iterator;
    import java.util.Stack;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

    public class QueryMatcher {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String sa="((OPERATING_CARRIER='AB' OR OPERATING_CARRIER='AB' OR (OPERATING_CARRIER='VA' AND (FLIGHT_NO=604 OR FLIGHT_NO=603))))";
            Matcher m = Pattern.compile("\\w+\\s*=\\s*(?:'[^']+'|\\d+)").matcher(sa);
            System.out.println("contains "+sa.contains("((("));
            Stack<String> in_cond = new Stack<String>();
            Iterator<String> iter = in_cond.iterator();
            String new_sa=sa;
            while(m.find()) {
                String aMatch = m.group();
                // add aMatch to match list...
                System.out.println(aMatch);
                in_cond.push(aMatch);
            }
            System.out.println("string stack is "+in_cond);
            int i=0;
            for (String new_sa1:in_cond)
            {   
                if(new_sa.contains(in_cond.get(i)))
                {   
                    new_sa=new_sa.replace(in_cond.get(i),"&"+i);
                    System.out.println("String Contains "+in_cond.get(i));
                }
                i++;
            }       
            System.out.println("new String is "+new_sa);
        }

    }

但是现在我不知道如何继续,需要帮助。

我已经使用下面的代码来拆分字符串 以及建立父子关系:

String input="name = 'name_1' AND in_stock IN {'in_stock_1','in_stock_2'} AND ( price BETWEEN '01-jan-2015' and '31-may-2015' OR price = 'price_3' )";

String sa =input;
String[] arr = sa.replaceAll("[()]+","").split("\\s*(\\sOR|\\sAND)\\s*");
for(int i=0;i<arr.length;i++)
{
    System.out.println(arr[i]);
}


            String og_st=orig_input;
            Stack<String> temp_bool=new Stack<String>();
            String[] bool_arr = og_st.split("\\s+");
            String[] bool_op=new String[inout.length-1];
            for(String bool:bool_arr)
            {
                if(bool.equals("AND") || bool.equals("OR"))
                {
                    temp_bool.push(bool);
                }
                else
                {
                    //nothing here
                }
            }       
            for (int i=0;i<temp_bool.size();i++)
            {
                bool_op[i]=temp_bool.get(i);
            }
            Conditions c=new Conditions();
            String[] arr=null;
            arr=inout;
            //Stack<String> arr2 =new Stack<String>();
            String[] atr=null;
            if(arr[l].contains(" BETWEEN "))
            {
                atr=arr[l].split(" BETWEEN ");
                c.id=l+1;
                c.entity=atr[0];
                c.operator=" BETWEEN ";
                String c_value=atr[1];
                //c_value=c_value.replace("'","");
                c.value=c_value;
            }
            else
            {
                atr=arr[l].split(" ");
                c.id=l+1;
                c.entity=atr[0];
                c.operator=atr[1];
                String c_value=atr[2];
                //c_value=c_value.replace("'","");
                c.value=c_value;
            }
            /*for(int k=0;k<arr2.size();k++)
            {
                if(arr[l].contains(" BETWEEN "))
                {   
                    System.out.println("inside if");
                    atr=arr[l].split(" BETWEEN ");
                    c.id=l+1;
                    c.entity=atr[0];
                    c.operator=" BETWEEN ";
                    String c_value=atr[1];
                    c_value=c_value.replace("'","");
                    c.value=c_value;
                    System.out.println(c.entity+" "+c.operator+" "+c.value );
                }
                else
                {
                    System.out.println("inside else");
                    atr=arr[l].split(" ");
                    for(int o=0;o<atr.length;o++)
                    {
                        arr2.push(atr[o].toString());
                    }

                c.id=l+1;
                c.entity=atr[0];
                c.operator=atr[1];
                String c_value=atr[2];
                c_value=c_value.replace("'","");
                c.value=c_value;
                }
            }*/
            c.enopva=arr[l];
            int c_id=getDecompressedString(arr,orig_input,l);
            if (c_id==0)
            {
                c.parent_id=c_id;
            }
            else if(c_id>0)
            {
                c.parent_id=c_id;
            }
            if(l>=bool_op.length)
            {
                c.bool_op=null;
            }
            else if(l<bool_op.length)
            {
                c.bool_op=bool_op[l].toString();
            }
            IncentiveProLog.insertLog(" Class has been generated as  "+c.toString(),id);
            try 
            {
                insertData(c.id,c_id,c.entity,c.operator,c.value,c.bool_op);
            }
            catch (SQLException e) 
            {
                e.printStackTrace();
            } 
String input=“name='name_1'和in_stock in{'in_stock_1'、'in_stock_2'}和(价格介于'2015年1月1日'和'2015年5月31日'之间或价格='price_3')”;
字符串sa=输入;
字符串[]arr=sa.replaceAll(“[()]”+“,”).split(\\s*(\\sOR | \\ sAND)\\s*”);

for(int i=0;i看起来像一个打字错误。你在你想要的输出中有一个
OPERATING_CARRIER
值'EY',但它不在代码或输入字符串中。似乎你需要查找一些关于解析上下文无关语言的资料。是的,Erick是一个打字错误堆栈器。我已经用下面的代码来拆分字符串,设法解决了这个问题
String input="name = 'name_1' AND in_stock IN {'in_stock_1','in_stock_2'} AND ( price BETWEEN '01-jan-2015' and '31-may-2015' OR price = 'price_3' )";

String sa =input;
String[] arr = sa.replaceAll("[()]+","").split("\\s*(\\sOR|\\sAND)\\s*");
for(int i=0;i<arr.length;i++)
{
    System.out.println(arr[i]);
}


            String og_st=orig_input;
            Stack<String> temp_bool=new Stack<String>();
            String[] bool_arr = og_st.split("\\s+");
            String[] bool_op=new String[inout.length-1];
            for(String bool:bool_arr)
            {
                if(bool.equals("AND") || bool.equals("OR"))
                {
                    temp_bool.push(bool);
                }
                else
                {
                    //nothing here
                }
            }       
            for (int i=0;i<temp_bool.size();i++)
            {
                bool_op[i]=temp_bool.get(i);
            }
            Conditions c=new Conditions();
            String[] arr=null;
            arr=inout;
            //Stack<String> arr2 =new Stack<String>();
            String[] atr=null;
            if(arr[l].contains(" BETWEEN "))
            {
                atr=arr[l].split(" BETWEEN ");
                c.id=l+1;
                c.entity=atr[0];
                c.operator=" BETWEEN ";
                String c_value=atr[1];
                //c_value=c_value.replace("'","");
                c.value=c_value;
            }
            else
            {
                atr=arr[l].split(" ");
                c.id=l+1;
                c.entity=atr[0];
                c.operator=atr[1];
                String c_value=atr[2];
                //c_value=c_value.replace("'","");
                c.value=c_value;
            }
            /*for(int k=0;k<arr2.size();k++)
            {
                if(arr[l].contains(" BETWEEN "))
                {   
                    System.out.println("inside if");
                    atr=arr[l].split(" BETWEEN ");
                    c.id=l+1;
                    c.entity=atr[0];
                    c.operator=" BETWEEN ";
                    String c_value=atr[1];
                    c_value=c_value.replace("'","");
                    c.value=c_value;
                    System.out.println(c.entity+" "+c.operator+" "+c.value );
                }
                else
                {
                    System.out.println("inside else");
                    atr=arr[l].split(" ");
                    for(int o=0;o<atr.length;o++)
                    {
                        arr2.push(atr[o].toString());
                    }

                c.id=l+1;
                c.entity=atr[0];
                c.operator=atr[1];
                String c_value=atr[2];
                c_value=c_value.replace("'","");
                c.value=c_value;
                }
            }*/
            c.enopva=arr[l];
            int c_id=getDecompressedString(arr,orig_input,l);
            if (c_id==0)
            {
                c.parent_id=c_id;
            }
            else if(c_id>0)
            {
                c.parent_id=c_id;
            }
            if(l>=bool_op.length)
            {
                c.bool_op=null;
            }
            else if(l<bool_op.length)
            {
                c.bool_op=bool_op[l].toString();
            }
            IncentiveProLog.insertLog(" Class has been generated as  "+c.toString(),id);
            try 
            {
                insertData(c.id,c_id,c.entity,c.operator,c.value,c.bool_op);
            }
            catch (SQLException e) 
            {
                e.printStackTrace();
            }