Package org.apache.ws.jaxme.sqls

Examples of org.apache.ws.jaxme.sqls.SelectStatement


     * </pre></p>
     */
    private ColumnReference getCountStatement(String pColumnName, String pFilter,
                        TableReference pAkteReference, String pTableAlias) {
        // SELECT COUNT(*) FROM DBBeteiligte klc WHERE klc.aFilter='Klaeger' AND klc.aAktenId=a.aID
        SelectStatement st = sqlFactory.newSelectStatement();
        st.setTable(dbBeteiligte);
        SelectTableReference tRef = st.getSelectTableReference();
        tRef.setAlias(pTableAlias);
        addEQ(tRef, st.getWhere(), dbBeteiligte.getColumn("aFilter"), pFilter);
        addAktenId(st.getWhere(), pAkteReference, tRef);
        VirtualColumn vc = new VirtualColumn(pColumnName, Column.Type.INTEGER);
        vc.setValue("COUNT(*)");
        st.addResultColumn(vc);

        VirtualColumn result = new VirtualColumn(pColumnName, Column.Type.INTEGER);
        result.setValue(st);
        return result;
    }
View Full Code Here


      Column aName = dbBeteiligte.getColumn("aName");
        Column aVorname = dbBeteiligte.getColumn("aVorname");
        Column aAktenId = dbBeteiligte.getColumn("aAktenId");
        Column aFilter = dbBeteiligte.getColumn("aFilter");

        SelectStatement st = sqlFactory.newSelectStatement();
        st.setTable(dbBeteiligte);
        SelectTableReference ref = st.getSelectTableReference();
        VirtualColumn num = new VirtualColumn("NUM", Column.Type.INTEGER);
        num.setValue("COUNT(*) OVER (PARTITION BY " + aAktenId.getName() + ")");
        st.addResultColumn(num);
        VirtualColumn minAName = new VirtualColumn("MINANAME", Column.Type.VARCHAR);
        minAName.setValue("MIN(UPPER(" + aName.getName() + ")) OVER (PARTITION BY " +
                      aAktenId.getName() + ")");
        st.addResultColumn(minAName);
        VirtualColumn minAVorname = new VirtualColumn("MINAVORNAME", Column.Type.VARCHAR);
        minAVorname.setValue("MIN(UPPER(NVL(" + aVorname.getName() +
                       ", ' '))) OVER (PARTITION BY " +
                        aAktenId.getName() + ", UPPER(" + aName.getName() +
                        "))");
        st.addResultColumn(minAVorname);
        st.addResultColumn(ref.newColumnReference(aName));
        st.addResultColumn(ref.newColumnReference(aVorname));
        st.addResultColumn(ref.newColumnReference(aAktenId));
        BooleanConstraint bc = st.getWhere().createEQ();
        bc.addPart(st.getTableReference().newColumnReference(aFilter));
        bc.addPart(pFilter);
        Table t = st.createView((Table.Name) null);

        SelectStatement st2 = sqlFactory.newSelectStatement();
        st2.setTable(t);
        SelectTableReference ref2 = st2.getSelectTableReference();
        st2.addResultColumn(ref2.newColumnReference(t.getColumn("NUM")));
        Column aName2 = t.getColumn(aName.getName());
        st2.addResultColumn(ref2.newColumnReference(aName2));
        Column aVorname2 = t.getColumn(aVorname.getName());
        st2.addResultColumn(ref2.newColumnReference(aVorname2));
        st2.addResultColumn(ref2.newColumnReference(t.getColumn(aAktenId.getName())));

        bc = st2.getWhere().createEQ();
        bc.addPart(ref2.newColumnReference(t.getColumn("MINAVORNAME")));
        Function f = st2.createFunction("MIN");
        Function f2 = st.createFunction("UPPER");
        Function f3 = st.createFunction("NVL");
        f3.addPart(ref2.newColumnReference(aVorname2));
        f3.addPart(" ");
        f2.addPart(f3);
        bc.addPart(f);

        bc = st2.getWhere().createEQ();
        bc.addPart(ref2.newColumnReference(t.getColumn("MINANAME")));
        f = st2.createFunction("MIN");
        f2 = st.createFunction("UPPER");
        f2.addPart(ref2.newColumnReference(aName2));
        f.addPart(f2);
        bc.addPart(f);
        Table t2 = st2.createView(pTableAlias);

        JoinReference result = pJoinReference.leftOuterJoin(t2);
        bc = result.getOn().createEQ();
        bc.addPart(pAkteReference.newColumnReference(dbAkte.getColumn("aId")));
        bc.addPart(result.newColumnReference(t2.getColumn(aAktenId.getName())));
View Full Code Here

       
        Function f = pAkteReference.getStatement().createFunction("UPPER");
        f.addPart(result.newColumnReference(dbBeteiligte.getColumn("aName")));
        bc.addPart(f);
       
        SelectStatement minStatement = sqlFactory.newSelectStatement();
        minStatement.setTable(dbBeteiligte);
        SelectTableReference minTableRef = minStatement.getSelectTableReference();
        minTableRef.setAlias(pTableAlias + "min");
        BooleanConstraint bc2 = minStatement.getWhere().createEQ();
        bc2.addPart(result.newColumnReference(dbBeteiligte.getColumn("aAktenId")));
        bc2.addPart(minTableRef.newColumnReference(dbBeteiligte.getColumn("aAktenId")));
       
        bc2 = minStatement.getWhere().createEQ();
        bc2.addPart(minTableRef.newColumnReference(dbBeteiligte.getColumn("aFilter")));
        bc2.addPart(pFilter);

        f = pAkteReference.getStatement().createFunction("MIN");
        Function f2 = pAkteReference.getStatement().createFunction("UPPER");
        f.addPart(f2);
        f2.addPart(minTableRef.newColumnReference(dbBeteiligte.getColumn("aName")));
        VirtualColumn vc = new VirtualColumn("MIN", Column.Type.VARCHAR);
        vc.setValue(f);
        minStatement.addResultColumn(vc);

        bc.addPart(minStatement);
        return result;
    }
View Full Code Here

        bc.addPart(minStatement);
        return result;
    }

    private SelectStatement newStatement(boolean pUseView) {
        SelectStatement st = sqlFactory.newSelectStatement();
        st.setTable(dbAkte);
        SelectTableReference akte = st.getSelectTableReference();
        akte.setAlias("a");

        //aktenzeichen joinen
        JoinReference az = akte.join(dbAktenzeichen);
        az.setAlias("az");
        CombinedConstraint onClause = az.getOn();
        BooleanConstraint bc = onClause.createEQ();
        bc.addPart(akte.newColumnReference(dbAkte.getColumn("aId")));
        bc.addPart(az.newColumnReference(dbAktenzeichen.getColumn("aAktenId")));
        bc = onClause.createEQ();
        bc.addPart(az.newColumnReference(dbAktenzeichen.getColumn("aFilter")));
        bc.addPart("Hauptverfahren");

        //beteiligte joinen
        JoinReference kl, be;
        if (pUseView) {
            kl = getFirstRowStatement2("Klaeger", akte, az, "kl");
            be = getFirstRowStatement2("Beklagter", akte, kl, "be");
        } else {
            kl = getFirstRowStatement("Klaeger", akte, az, "kl");
            be = getFirstRowStatement("Beklagter", akte, kl, "be");
            st.addResultColumn(getCountStatement("anzahlKlaeger", "Klaeger", akte, "klc"));
            st.addResultColumn(getCountStatement("anzahlBeklagte", "Beklagter", akte, "bec"));
        }
        JoinReference ber = be.leftOuterJoin(dbBeteiligte);
        ber.setAlias("ber");
        addAktenId(ber.getOn(), akte, ber);
        addEQ(ber, ber.getOn(), dbBeteiligte.getColumn("aFilter"), "Beklagter");
View Full Code Here

    }

    /** <p>Creates a complex SELECT statement and runs the generator on it.</p>
     */
    public void testCreate1() {
        SelectStatement st = newStatement(false);
        String got = sqlGenerator.getQuery(st);
        String expect = "SELECT (SELECT COUNT(*) AS anzahlKlaeger FROM DBBeteiligte klc WHERE"
            + " (klc.aFilter='Klaeger' AND klc.aAktenId=a.aId)) AS anzahlKlaeger,"
            + " (SELECT COUNT(*) AS anzahlBeklagte FROM DBBeteiligte bec WHERE"
            + " (bec.aFilter='Beklagter' AND bec.aAktenId=a.aId)) AS anzahlBeklagte"
View Full Code Here

    }

    /** <p>Creates another complex SELECT statement and runs the generator on it.</p>
     */
    public void testCreate2() {
        SelectStatement st = newStatement(true);
        String got = sqlGenerator.getQuery(st);
        String expect = "SELECT * FROM DBAkte a, DBAktenzeichen az,"
            + " (SELECT DBBeteiligte.NUM, DBBeteiligte.aName, DBBeteiligte.aVorname,"
            + " DBBeteiligte.aAktenId FROM (SELECT COUNT(*) OVER (PARTITION BY aAktenId) AS NUM,"
            + " MIN(UPPER(aName)) OVER (PARTITION BY aAktenId) AS MINANAME,"
View Full Code Here

     *     ON KE.AID = VK.WURZELELEMENT
     *     WHERE KE.ORGANISATIONSID = ?
     * </pre>
     */
    private SelectStatement getSelectAidByOrganisationsId() {
        SelectStatement stmt = sqlFactory.newSelectStatement();
        stmt.setTable(kettenElement);
        SelectTableReference kettenElementRef = stmt.getSelectTableReference();
        JoinReference vertreterKetteRef = kettenElementRef.join(vertreterKette);
        addEQ(kettenElementRef, vertreterKetteRef, vertreterKetteRef.getOn(),
              kettenElement.getColumn("aId"),
              vertreterKette.getColumn("wurzelElement"));
        addEQ(kettenElementRef, stmt.getWhere(), kettenElement.getColumn("organisationsId"));
        stmt.addResultColumn(kettenElementRef.newColumnReference(kettenElement.getColumn("aId")));
        return stmt;
    }
View Full Code Here

      return result;
   }

   public SelectStatement getSelectStatement() {
       SQLFactory factory = getSchema().getSQLFactory();
       SelectStatement result = factory.newSelectStatement();
      result.setTable(this);
      TableReference ref = result.getTableReference();
      for (Iterator iter = getColumns();  iter.hasNext()) {
         Column column = (Column) iter.next();
         result.addResultColumn(factory.getObjectFactory().newColumnReference(ref, column));
      }
      return result;
   }
View Full Code Here

                   DirectAccessible pConn,
                   DirectAccessible pMap,
                   DirectAccessible pValues,
                   boolean pReturnValue) {
    Table table = pTableInfo.getTable();
    SelectStatement statement = table.getSelectStatement();
    statement.getWhere().addColumnSetQuery(pColumnSet, statement.getTableReference());
    String s = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(statement);
    Object query = JavaSource.getQuoted(s);
    if (isGeneratingLogging()) {
      LocalJavaField q = pMethod.newJavaField(String.class);
      q.addLine(query);
View Full Code Here

  /** <p>Basic test for creating a <code>SELECT</code> statement.</p>
   */
  public void testBasicSelect() {
    Table table = getBasicTable();
    SelectStatement selectStatement = table.getSelectStatement();
    SQLGenerator generator = getSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(selectStatement);
    assertEquals("SELECT MyIndex, MyName, MyDate FROM MySchema.MyTable", s);
  }
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.sqls.SelectStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.