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


    @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.DOUBLE)
            return 18;
View Full Code Here

   * the given ResultSet
   */
  private DBTableColumn addColumn(DBTable t, ResultSet rs)
      throws SQLException {
    String name = rs.getString("COLUMN_NAME");
    DataType empireType = getEmpireDataType(rs.getInt("DATA_TYPE"));
    int colSize = rs.getInt("COLUMN_SIZE");
    boolean required = false;
    String defaultValue = rs.getString("COLUMN_DEF");
    if (rs.getString("IS_NULLABLE").equalsIgnoreCase("NO"))
      required = true;
   
    // The following is a hack for MySQL which currently gets sent a string "CURRENT_TIMESTAMP" from the Empire-db driver for MySQL.
    // This will avoid the driver problem because CURRENT_TIMESTAMP in the db will just do the current datetime.
    // Essentially, Empire-db needs the concept of default values of one type that get mapped to another.
    // In this case, MySQL "CURRENT_TIMESTAMP" for Types.TIMESTAMP needs to emit from the Empire-db driver the null value and not "CURRENT_TIMESTAMP".
    if(rs.getInt("DATA_TYPE") == Types.TIMESTAMP && defaultValue != null && defaultValue.equals("CURRENT_TIMESTAMP")){
      required = false; // It is in fact not required even though MySQL schema is required because it has a default value. Generally, should Empire-db emit (required && defaultValue != null) to truly determine if a column is required?
      defaultValue = null; // If null (and required per schema?) MySQL will apply internal default value.
    }
   
    // AUTOINC indicator is not in java.sql.Types but rather meta data from DatabaseMetaData.getColumns()
    // getEmpireDataType() above is not enough to support AUTOINC as it will only return DataType.INTEGER
    DataType originalType = empireType;
    ResultSetMetaData metaData = rs.getMetaData();
    int colCount = metaData.getColumnCount();
    String colName;
    for (int i = 1; i <= colCount; i++) {
      colName = metaData.getColumnName(i);
View Full Code Here

   * the given ResultSet
   */
  private DBViewColumn addColumn(InMemoryView v, ResultSet rs)
      throws SQLException {
    String name = rs.getString("COLUMN_NAME");
    DataType empireType = getEmpireDataType(rs.getInt("DATA_TYPE"));
   
    log.info("\tCOLUMN:\t" + name + " ("+empireType+")");
    return v.addCol(name, empireType);
  }
View Full Code Here

  /**
   * converts a SQL DataType to a EmpireDataType
   */
  private DataType getEmpireDataType(int sqlType) {
    DataType empireType = DataType.UNKNOWN;
    switch (sqlType) {
    case Types.INTEGER:
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.BIGINT:
View Full Code Here

            return null;
        }
        try
        { // Get Value from Resultset
            clearError();
            DataType dataType = colList[index].getDataType();
            return db.driver.getResultValue(rset, index + 1, dataType);

        } catch (Exception e)
        { // Operation failed
            error(e);
View Full Code Here

     * @return the auto-generated value
     */
    public Object getColumnAutoValue(DBDatabase db, DBTableColumn column, Connection conn)
    {
        // Supports sequences?
        DataType type = column.getDataType();
        if (type == DataType.AUTOINC)
        {   // Use a numeric sequence
            if (isSupported(DBDriverFeature.SEQUENCES)==false)
                return null; // Create Later
            // Detect the Sequence Name
View Full Code Here

            return false;
        // Check if prepared statements are enabled
        if (db.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

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.