Package de.iritgo.aktera.util.string

Examples of de.iritgo.aktera.util.string.SuperString


  public Date getParameterAsDate(String name)
  {
    assert name != null;

    return new SuperString(getParameterAsString(name)).toDate();
  }
View Full Code Here


  public Date getParameterAsDate(String name)
  {
    assert name != null;

    return new SuperString(getParameterAsString(name)).toDate();
  }
View Full Code Here

          if (type.equalsIgnoreCase("java.util.Date"))
          {
            try
            {
              new SuperString(value.toString()).toDate();
            }
            catch (Exception e)
            {
              log.error("Value '" + value + " cannot be converted to a date", e);
              req.addError(name, "Value '" + value + "' cannot be converted to a date");
View Full Code Here

    if (getHelper() != null)
    {
      getHelper().beforeAdd(this);
    }

    SuperString sqlCommand = new SuperString(96);

    sqlCommand.append("INSERT INTO ");
    sqlCommand.append(myMetaData.getTableName());
    sqlCommand.append(" (");

    SuperString valuesCommand = new SuperString(64);

    valuesCommand.append(") VALUES (");

    boolean needCommaValues = false;

    String identityFieldName = null;

    for (Iterator i = myMetaData.getFieldNames().iterator(); i.hasNext();)
    {
      oneFieldName = (String) i.next();

      checkField(oneFieldName, getFieldString(oneFieldName));

      if ("identity".equals(myMetaData.getAutoIncremented(oneFieldName)))
      {
        identityFieldName = oneFieldName;

        continue;
      }

      if (needComma)
      {
        sqlCommand.append(", ");
      }

      sqlCommand.append(myMetaData.getDBFieldName(oneFieldName));
      needComma = true;

      if (needCommaValues)
      {
        valuesCommand.append(", ");
      }

      if (myMetaData.isAutoIncremented(oneFieldName))
      {
        /*
         * If identityFieldName is not null, we've already used the one
         * (and only) identity for this table
         */
        if ((identityFieldName == null) && myMetaData.isKeyField(oneFieldName)
                && myMetaData.getDatabaseType().isIdentitySupported()
                && (myMetaData.getIdGenerator(oneFieldName) == null))
        {
          // Native auto-inc is supported using "IDENTITY" type
          // syntax
          identityFieldName = oneFieldName;
          valuesCommand.append(myMetaData.getDatabaseType().getInsertIdentitySyntax());
        }
        else
        {
          setAutoIncrement(oneFieldName);
          valuesCommand.append("?");
        }
      }
      else
      {
        valuesCommand.append("?");
      }

      needCommaValues = true;
    } /* for each field */
    //Now we merge the values of the parallel loops
View Full Code Here

  private List runQuery(Connection myConnection, int myQueryId) throws QueryException
  {
    // =================================================
    // Bind parameters of the sql statement to actual values.
    // =================================================
    SuperString myStatement = bindParameters(myQueryId);

    // =================================================
    // Execute massaged sql statement
    // =================================================
    log.debug("Query statement after, join id,  param subsitution and append ORDER by clause:" + myStatement);
View Full Code Here

    // ===================================================
    // Now we complete the sql statement that is associated
    // with this tabular report type. The raw sql statement is provided in
    // a config file, but this must be modified before execution.
    // ===================================================
    SuperString myStatement = new SuperString(sql);

    log.debug("Config Query statement before param substitution:" + myStatement);

    // ===================================================
    // Modify sql statement from the config.
    //  - If there is no "order by" clause in config file, then order by queryjoin.name
    //    so that queryResult ordering  will match ObjectKeys ordering.
    //  - Replace any paramters in sql statement with runtime values passed via criteria inputs
    //    order by clauses at run time.
    //  - If objectKeys is not null, substitute $queryid with myQueryId governing the join.
    // ===================================================
    log.debug("Does Config Query have ORDER by clause, not if this index is -1:"
            + (myStatement.toString().toUpperCase().indexOf("ORDER BY ")));

    // modified by aleks
    if ((myStatement.toString().toUpperCase().indexOf("ORDER BY ")) == - 1 && myQueryId > 0)
    {
      log.debug("sindex not found, so append");
      myStatement.append("\n ORDER BY $orderByClause ");
    }

    // modified by aleks
    try
    {
      String oneCriteriaCode = null;

      for (int i = 0; i < criteria.length; i++)
      {
        oneCriteriaCode = criteria[i].getAttribute("name");

        // ==================================
        // Replace 0 or more occurancees of criteria code parameter with value
        // ==================================
        while (myStatement.toString().indexOf("$" + oneCriteriaCode) != - 1)
        {
          myStatement = new SuperString(myStatement.replace("$" + oneCriteriaCode,
          // BUEROBYTE: Don't cast to String, convert to String!

                  //                (String) criteriaInput.get(oneCriteriaCode)));
                  criteriaInput.get(oneCriteriaCode).toString()));

          // BUEROBYTE
        }

        // BUEROBYTE: Replace '%'-paramters with a '?' for prepared statements.
        while (myStatement.toString().indexOf("%" + oneCriteriaCode) != - 1)
        {
          myStatement = new SuperString(myStatement.replace("%" + oneCriteriaCode, "?"));
        }

        // BUEROBYTE
      }
    }
    catch (ConfigurationException ce)
    {
      throw new QueryException(ce);
    }

    myStatement = new SuperString(myStatement.replace("$orderByClause", "queryJoin.name"));
    myStatement = new SuperString(myStatement.replace("$queryid", (new Integer(myQueryId)).toString()));

    //Note: SuperString replace does not change "this", but only return value.  Is that desirable?
    return myStatement;
  }
View Full Code Here

      checkAllowed("L");
    }

    foundKeys = null;

    SuperString myStatement = new SuperString(48);

    myStatement.append("SELECT COUNT(*) FROM ");
    myStatement.append(myMetaData.getTableName());

    if (customWhereClause != null)
    {
      myStatement.append(customWhereClause);
    }
    else
    {
      myStatement.append(buildWhereClauseBuffer(true));
    }

    int retVal = 0;

    Statement s = null;
    ResultSet rs = null;

    Connection myConnection = null;

    try
    {
      if (currentTransaction != null)
      {
        myConnection = currentTransaction.getConnection();
      }
      else
      {
        myConnection = myDataSource.getConnection();
      }

      s = myConnection.createStatement();

      if (log.isDebugEnabled())
      {
        log.debug("Executing: " + myStatement.toString());
      }

      rs = s.executeQuery(myStatement.toString());

      if (rs.next())
      {
        retVal = rs.getInt(1);
      }
View Full Code Here

      getHelper().beforeDelete(this);
    }

    haveAllKeys(true, true);

    SuperString sqlCommand = new SuperString(64);

    sqlCommand.append("DELETE FROM ");
    sqlCommand.append(myMetaData.getTableName());

    if (customWhereClause != null)
    {
      sqlCommand.append(customWhereClause);
    }
    else
    {
      sqlCommand.append(buildWhereClauseBuffer(false));
    }

    Connection myConnection = null;
    Statement s = null;

    try
    {
      if (deleteDetails)
      {
        deleteDetails();
      } /* if we delete the details */
      if (currentTransaction != null)
      {
        myConnection = currentTransaction.getConnection();
      }
      else
      {
        myConnection = myDataSource.getConnection();
      }

      s = myConnection.createStatement();

      if (log.isDebugEnabled())
      {
        log.debug("Executing: " + sqlCommand.toString());
      }

      int updateCount = s.executeUpdate(sqlCommand.toString());

      s.close();
      s = null;

      if ((updateCount == 0) && (getCheckZeroUpdate()))
      {
        log.error("No record(s) deleted for SQL '" + sqlCommand.toString() + "'");
        throw new PersistenceException("No record(s) deleted.");
      }
    }
    catch (SQLException se)
    {
View Full Code Here

    else
    {
      recordSet.clear();
    }

    SuperString myStatement = new SuperString(64);

    myStatement.append("DELETE FROM ");

    myStatement.append(myMetaData.getTableName());

    if (customWhereClause != null)
    {
      myStatement.append(customWhereClause);
      customWhereClause = null;
    }
    else
    {
      myStatement.append(buildWhereClauseBuffer(true));
    }

    Connection myConnection = null;
    Statement s = null;

    try
    {
      if (currentTransaction != null)
      {
        myConnection = currentTransaction.getConnection();
      }
      else
      {
        myConnection = myDataSource.getConnection();
      }

      s = myConnection.createStatement();
      /* int up[dateCount = */
      s.executeUpdate(myStatement.toString());
      s.close();
      s = null;

      /*
       * Can't do the below check on MySQL (at least with current
View Full Code Here

    foundKeys = null;

    ArrayList retrievedFieldList = new ArrayList();

    SuperString myStatement = new SuperString(64);

    myStatement.append("SELECT ");

    String oneFieldName = null;

    for (Iterator i = myMetaData.getFieldNames().iterator(); i.hasNext();)
    {
      oneFieldName = (String) i.next();

      if (needComma)
      {
        myStatement.append(", ");
      }

      retrievedFieldList.add(oneFieldName);
      myStatement.append(selectFieldString(oneFieldName));

      needComma = true;
    } /* for */
    myStatement.append(" FROM ");
    myStatement.append(myMetaData.getTableName());

    if (customWhereClause != null)
    {
      myStatement.append(customWhereClause);
      customWhereClause = null;
    }
    else
    {
      myStatement.append(buildWhereClauseBuffer(true));
    }

    Connection myConnection = null;
    ResultSet rs = null;
    Statement s = null;

    try
    {
      if (currentTransaction != null)
      {
        myConnection = currentTransaction.getConnection();
      }
      else
      {
        myConnection = myDataSource.getConnection();
      }

      s = myConnection.createStatement();

      if (log.isDebugEnabled())
      {
        log.debug("Executing: " + myStatement.toString());
      }

      rs = s.executeQuery(myStatement.toString());

      Object oneFieldValue = null;
      StringBuffer oneKeyString = new StringBuffer("");

      if (foundKeys == null)
      {
        foundKeys = new ArrayList();
      }

      if (rs.next())
      {
        log.debug("Found record");

        int i = 1;

        for (Iterator it = retrievedFieldList.iterator(); it.hasNext();)
        {
          oneFieldName = (String) it.next();

          if (rs.getString(i) == null && myMetaData.allowsNull(oneFieldName))
          {
            i++;
          }
          else
          {
            oneFieldValue = retrieveField(oneFieldName, rs, i);
            setField(oneFieldName, oneFieldValue);
            i++;
          }

          if (myMetaData.isKeyField(oneFieldName))
          {
            if (i > 1)
            {
              oneKeyString.append("/");
            }

            oneKeyString.append(oneFieldValue);
          } /* if field is key */
        } /* for each field */
        foundKeys.add(oneKeyString.toString());
      }
      else
      {
        if (log.isDebugEnabled())
        {
          log.debug("No matching record for " + myStatement.toString());
        }

        return false;
      }

View Full Code Here

TOP

Related Classes of de.iritgo.aktera.util.string.SuperString

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.