Package org.apache.empire.data

Examples of org.apache.empire.data.DataType


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

    protected int getMaxInputLength(Column col)
    {
        // cast to DBTableColumn
        DataType type = col.getDataType();
        if (type==DataType.CHAR ||
            type==DataType.TEXT)
            return (int)Math.round(col.getSize());
        if (type==DataType.AUTOINC ||
            type==DataType.INTEGER)
View Full Code Here


     * @return a DBDecodeExpr object
     */
    public DBColumnExpr decode(Map<?,?> valueMap, Object otherwise)
    {
        // Detect data type
        DataType dataType = DataType.UNKNOWN;
        if (otherwise!=null)
        {
            dataType = detectDataType(otherwise);
        }
        if (dataType==DataType.UNKNOWN)
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"));
   
    double colSize = rs.getInt("COLUMN_SIZE");
    if (empireType==DataType.DECIMAL || empireType==DataType.FLOAT)
    {  // decimal digits
      int decimalDig = rs.getInt("DECIMAL_DIGITS");
      if (decimalDig>0)
      {  // parse
        try {
          int intSize = rs.getInt("COLUMN_SIZE");
          colSize = Double.parseDouble(String.valueOf(intSize)+'.'+decimalDig);
        } catch(Exception e) {
          log.error("Failed to parse decimal digits for column "+name);
        }
      }
      // make integer?
      if (colSize<1.0d)
      {  // Turn into an integer
        empireType=DataType.INTEGER;
      }
    }
   
    // mandatory field?
    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

     */
    @SuppressWarnings("unchecked")
    public DBColumnExpr decode(Map valueMap, Object otherwise)
    {
        // Detect data type
        DataType dataType = DataType.UNKNOWN;
        if (otherwise!=null)
        {
            dataType = detectDataType(otherwise);
        }
        if (dataType==DataType.UNKNOWN)
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

        }
    }
   
    protected boolean useCmdParam(DBColumn col)
    {
        DataType dt = col.getDataType();
        return ( dt==DataType.BLOB || dt==DataType.CLOB );
    }
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

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.