Package org.apache.empire.data

Examples of org.apache.empire.data.DataType


   *
   * @param column the column to get the type for
   */
  public Class<?> getJavaType(DBColumn column)
  {
    DataType type = getDataType(column);
    // We added the attribute of original datatype to AUTOINC columns
    // in CodeGenParser.addColumn(). Now we need to use it so that
    // the g/setters deal with the right Java type.
   
    // If the original data type was not set as an attribute for some
    // reason this will just fall through to the bottom and
    // return "Byte[]", so no problem.
    if (DataType.AUTOINC.equals(type) && null != column.getAttribute("AutoIncDataType"))
    {
      type = (DataType)column.getAttribute("AutoIncDataType");
    }
   
    // TODO might be better to add this to the enum
    // TODO use primitives for non-nullable columns?
    switch(type){
    case INTEGER:
      return Long.class;
    case TEXT:
      return String.class;
    case DATE:
      return Date.class;
    case DATETIME:
      return Date.class;
    case CHAR:
      return String.class;
    case DOUBLE:
      return Double.class;
    case DECIMAL:
      return BigDecimal.class;
    case BOOL:
      return Boolean.class;
    case CLOB:
      return String.class;
    case BLOB:
      return Byte[].class;
    case UNKNOWN:
      return Byte[].class;
    default:
      log.warn("SQL column type " + type.toString() + " not supported, falling back to byte array.");
      return Byte[].class;
    }
  }
View Full Code Here


    public final void addSQL(StringBuilder sql, String template, Object[] params, long context)
    {
        // Get Template
        if (params != null)
        {   // Replace Params
            DataType dataType = expr.getDataType();
            for (int i = 0; i < params.length; i++)
            {   // String test  =(params[i] != null) ? params[i].toString() : "";
                String value = getObjectValue(dataType, params[i], CTX_DEFAULT, ",");
                // template = template.replaceAll("\\{" + String.valueOf(i) + "\\}", value);
                template = StringUtils.replaceAll(template, "{"+ String.valueOf(i) + "}", value);
View Full Code Here

     *
     */
    @Override
    public DataType getDataType()
    {
        DataType type = expr.getDataType();
        // Special treatment for adding days to dates
        if (type.isDate())
        {   // see whether the value is a date too
            if ((value instanceof Date) ||
                (value instanceof DBDatabase.DBSystemDate) ||
               ((value instanceof DBColumnExpr) && ((DBColumnExpr)value).getDataType().isDate()))
            {   // Yes, result is a decimal
                return DataType.DECIMAL;
            }
        }
        else if ((value instanceof DBColumnExpr))
        {   // Use the value type?
            DataType type2 =  ((DBColumnExpr)value).getDataType();
            if (type2.isNumeric() && type2.ordinal()>type.ordinal())
                return type2;
        }
        // type
        return type;
    }
View Full Code Here

    {
        // Zusammenbauen
        expr.addSQL(buf, context);
        buf.append(op);
        // Special treatment for adding days to dates
        DataType type = expr.getDataType();
        if (type.isNumeric()==false && (value instanceof Number))
            type = DataType.DECIMAL;
        // append
        buf.append(getObjectValue(type, value, context, op));
    }
View Full Code Here

    @Override
    protected Object parseValue(String value, Locale locale, Column column)
    {
        // Check Data Type
        DataType type = column.getDataType();
        if (type==DataType.TEXT)
            return value;
        // Check other types
        if (type==DataType.INTEGER)
        {   return parseInteger(value);
View Full Code Here

            // Empty String
            return "";
        }
        // Format Value
        Column column = vi.getColumn();
        DataType dataType = getValueType(value, (column != null) ? column.getDataType() : DataType.UNKNOWN);
        if (dataType == DataType.TEXT || dataType == DataType.UNKNOWN)
        { // String
            String s = String.valueOf(value);
            if (hasFormatOption(vi, "noencode"))
                return s;
View Full Code Here

    // ------- Input Helpers -------

    protected int getMaxInputLength(Column col)
    {
        // cast to DBTableColumn
        DataType type = col.getDataType();
        if (type==DataType.AUTOINC ||
            type==DataType.INTEGER)
            return 10;
        if (type==DataType.FLOAT)
            return 18;
View Full Code Here

        // Check params
        if (index < 0 || index >= colList.length)
            throw new InvalidArgumentException("index", index);
        try
        {   // Get Value from Resultset
            DataType dataType = colList[index].getDataType();
            return db.driver.getResultValue(rset, index + 1, dataType);

        } catch (SQLException e)
        { // Operation failed
            throw new EmpireSQLException(this, e);
View Full Code Here

            return false;
        // Check if prepared statements are enabled
        if (isPreparedStatementsEnabled())
            return true;
        // Only use a command param if column is of type BLOB or CLOB
        DataType dt = col.getDataType();
        return ( dt==DataType.BLOB || dt==DataType.CLOB );
    }
View Full Code Here

        String tbl = getName().toLowerCase();
        String key = MESSAGE_KEY_PREFIX + tbl + "." + col;
        column.setTitle(key);

        // Set Default Control Type
        DataType type = column.getDataType();
        column.setControlType((type == DataType.BOOL) ? "checkbox" : "text");

        // Add Column
        super.addColumn(column);
    }
View Full Code Here

TOP

Related Classes of org.apache.empire.data.DataType

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.