Package ch.inftec.ju.util

Examples of ch.inftec.ju.util.XString


   
    public JuEmfUtil build() {
      AssertUtil.assertNotEmpty("PersistenceUnit name must be specified", this.persistenceUnitName);
     
      // Build a unique identifier String to see if we already have this EmfUtil available.
      XString xs = new XString();
      xs.addItems("|", this.persistenceUnitName, this.connectionUrl);
     
      if (!JuEmfUtilBuilder.emfUtils.containsKey(xs)) {
        // Create a new EmfUtil
       
        String dialect = null;
View Full Code Here


   * <p>
   * The prefix will be added before every image URL to load them.
   * @param pathPrefix Path prefix for image URLs
   */
  public ImageLoader(String pathPrefix) {
    XString prefix = new XString(pathPrefix);
    prefix.assertEmptyOrText("/");
   
    this.pathPrefix = prefix.toString();
  }
View Full Code Here

    final double expectedLineHeight = 18;
       
    final double expectedDefaultHeight = 200;
   
    // Initialize the PrefColumnSize to the length of the longest line in the Detail Message
    XString xs = XString.parseLines(textArea.textProperty().getValue());
    int lineCount = xs.getLineCount();
    int columnCount = xs.getLongestLineLength();
   
    double calcHeight = (double)lineCount / textArea.getPrefRowCount() * textArea.getPrefHeight() * prefSizeFactor;
    double calcWidth = (double)columnCount / textArea.getPrefColumnCount() * textArea.getPrefWidth() * prefSizeFactor;
   
    double prefHeight = calcHeight > 0 ? calcHeight : expectedLineHeight * lineCount;
 
View Full Code Here

     
      String actualQuery = this.baseQuery;
     
      // Replace where clause (if any)
      if (this.baseQuery.indexOf(this.whereClausePlaceholder) > 0) {
        XString xsWhere = new XString();
       
        if (this.filterObject != null) {
          // Construct where clause using filter object
          try {
            BeanInfo bi = Introspector.getBeanInfo(this.filterObject.getClass());
            for (PropertyDescriptor pd : bi.getPropertyDescriptors()) {
              String name = pd.getName();
              if (!this.excludedFilterObjectProperties.contains(name)) {
                String mappedName = this.getActualColumnName(name);
               
                // Workaround for boolean property that uses the "is" instead of "get" syntax
                Method readMethod = pd.getReadMethod();
                if (readMethod == null && pd.getPropertyType() == Boolean.class) {
                  String methodName = "is" + StringUtils.capitalize(pd.getName());
                  try {
                    readMethod = this.filterObject.getClass().getMethod(methodName);
                  } catch (NoSuchMethodException ex) {
                    logger.debug(String.format("Couldn't find method %s on object %s"
                        , methodName, filterObject.getClass()));
                    // Ignore...
                  }
                }
                AssertUtil.assertNotNull("Property is not readable: " + pd.getName(), readMethod);
               
                Object value = readMethod.invoke(this.filterObject);
                if (value != null) {
                  xsWhere.assertEmptyOrText(" AND ");
                 
                  // Handle wildcard search
                  String operator = "=";
                  if (this.wildcardSearch && value instanceof String && value.toString().indexOf(DB_WILDCARD_CHAR) >= 0) {
                    // TODO: Wildcard escaping...
                    operator = " like ";
                  }
                 
                  // Handle case insensitive search
                  String convertedColumn = mappedName;
                  if (this.caseInsensitiveSearch && value instanceof String) {
                    convertedColumn = this.emUtil.asConnUtil().getDbHandler().wrapInLowerString(mappedName);
                    value = value.toString().toLowerCase();
                  }
                 
                  xsWhere.addFormatted("%s%s:%s", convertedColumn, operator, mappedName);
                 
                  this.queryAttributes.put(mappedName, value);
                }
              }
            }
          } catch (Exception ex) {
            throw new JuRuntimeException("Couldn't introspect bean", ex);
          }
        }
       
        if (xsWhere.isEmpty()) {
          xsWhere.addText("1 = 1");
        }
        String whereClause = String.format("(%s)", xsWhere.toString());
       
        while (actualQuery.indexOf(this.whereClausePlaceholder) > 0) {
          actualQuery = actualQuery.replace(this.whereClausePlaceholder, whereClause);
        }
      }
     
      // Add order by clause
      if (this.ordering.size() > 0) {
        XString xsOrderBy = new XString();
        for (AttributeOrdering ao : this.ordering) {
          xsOrderBy.assertEmptyOrText(", ");
          xsOrderBy.addText(this.getActualColumnName(ao.getAttributeName()));
          if (ao.getOrdering() == Ordering.DESCENDING) xsOrderBy.addText(" desc");
        }
       
        while (actualQuery.indexOf(this.orderByClausePlaceholder) > 0) {
          actualQuery = actualQuery.replace(this.orderByClausePlaceholder, xsOrderBy.toString());
        }
      }
     
      logger.debug(actualQuery);
     
View Full Code Here

        // Create user

        String tableSpace = "USERS";

        XString xs = new XString();
        xs.addFormatted("CREATE USER %s IDENTIFIED BY %s", builder.getName(), builder.getPassword());
        xs.addFormatted(" DEFAULT TABLESPACE %s", tableSpace);
        xs.addFormatted(" QUOTA UNLIMITED ON %s", tableSpace);
        jt.execute(xs.toString());

        // Grants
        if (builder.isDefaultGrants()) {
          jt.execute(String.format("GRANT CREATE SESSION TO %s", builder.getName()));
          jt.execute(String.format("GRANT CREATE TABLE TO %s", builder.getName()));
View Full Code Here

     */
    public ExportBuilder addTableSorted(String tableName, String... orderColumns) {
      if (orderColumns.length == 0) {
        return this.addTable(tableName);
      } else {
        XString xs = new XString();
        xs.addFormatted("SELECT * FROM %s ORDER BY ", tableName);
        for (String orderColumn : orderColumns) {
          xs.assertText("ORDER BY ", ", ");
          xs.addText(orderColumn);
        }
       
        return this.addTable(tableName, xs.toString());
      }
    }
View Full Code Here

            eb.writeToXmlFile(targetFilePath);
          }
        } else if (dataSetExport.exportType() == ExportType.MEMORY) {
          // Log XML
          if (logger.isInfoEnabled()) {
            XString xs = new XString(targetFileName);
            xs.newLine();
            xs.addLine(XmlUtils.toString(doc, true, true));
            logger.info(xs.toString());
          }
        } else {
          // Shouldn't happen
          throw new IllegalArgumentException("Unsupported export type: " + dataSetExport.exportType());
        }
View Full Code Here

      if (ite != null && ite.getTargetException() instanceof AssumptionViolatedException) {
        throw new AssumptionViolatedException(ite.getTargetException().getMessage());
      }

     
      XString causes = new XString("%s (Original Exception %s not serializable. Resolving chain"
          , t.getMessage()
          , t.getClass().getName());
         
      Throwable tChain = t;
      // Use cause (if possible / serializable)
      if (ite != null) {
        causes.addLineFormatted("%s [Target: %s]", ite.getMessage(), ite.getTargetException());
        if (ite.getTargetException() != null) {
          tChain = ite.getTargetException();
        }
      }
     
      Throwable cause = tChain.getCause();
      while (cause != null) {
        if (!IOUtil.isSerializable(cause)) {
                   
          causes.addLineFormatted("%s [Caused by: %s (non-serializable)", cause.getMessage(), cause.getClass().getName());
          cause = cause.getCause();
        } else {
          break;
        }
      }
     
      if (cause != null) {
        throw new JuRuntimeException(causes.toString(), cause);
      } else {
        causes.addLine("Check Server log for more details");
        throw new JuRuntimeException(causes.toString());
      }
    } else {
      throw t;
    }
  }
View Full Code Here

    super(dbConn, row, tableName);
  }
 
  @Override
  public void execute() {
    XString updateQry = null;
    try {
      Val[] changedColumns = this.getChangedColumns();
      if (changedColumns.length < 1) return;
     
      Object[] changedVals = new Object[changedColumns.length + 1];
     
      updateQry = new XString("UPDATE " + this.getTableName() + " SET ");
     
      int i = 0;
      for (Val changedColumn : changedColumns) {
        updateQry.assertText("SET ", ", ");
        updateQry.addText(changedColumn.getColumnName() + "=?");
        changedVals[i] = changedColumns[i].getChangedValue();
        i++;
      }
     
      updateQry.addText(" WHERE " + this.getPrimaryKeyValue().getColumnName() + "=?");
      changedVals[i] = this.getPrimaryKeyValue().getOriginalValue();
     
      int res = this.getDbConnection().getQueryRunner().update(updateQry.toString(), changedVals);
      if (res != 1) throw new JuDbException("Execution of query returned " + res + ", expected 1: " + updateQry);
    } catch (Exception ex) {
      throw new JuRuntimeException("Failed to execute update: " + updateQry, ex);
    }
  }
View Full Code Here

        && ObjectUtils.notEqual(this.getOriginalValue(), this.getChangedValue());
    }
   
    @Override
    public String toString() {
      XString val = new XString();
      val.addFormatted("%s(%s", this.getColumnName(), this.getOriginalValue());
      if (this.hasChanged()) val.addText(">", this.getChangedValue());
      val.addText(")");
     
      return val.toString();
    }
View Full Code Here

TOP

Related Classes of ch.inftec.ju.util.XString

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.