Package org.apache.empire.db

Examples of org.apache.empire.db.DBTableColumn


        // Enable Column default for the database
        // This is needed for adding required fields to non-empty tables
        db.getDriver().setDDLColumnDefaults(true);

        // First, add a new column to the Table object
        DBTableColumn C_FOO = db.T_EMPLOYEES.addColumn("FOO", DataType.TEXT, 20, DataMode.Nullable);

        // Now create the corresponding DDL statement
        System.out.println("Creating new column named FOO as varchar(20) for the EMPLOYEES table:");
        DBSQLScript script = new DBSQLScript();
        db.getDriver().getDDLScript(DBCmdType.CREATE, C_FOO, script);
        script.run(db.getDriver(), conn, false);
       
        // Now load a record from that table and set the value for foo
        System.out.println("Changing the value for the FOO field of a particular employee:");
        DBRecord rec = new DBRecord();
        rec.read(db.T_EMPLOYEES, idTestPerson, conn);
        rec.setValue(C_FOO, "Hello World");
        rec.update(conn);
       
        // Now extend the size of the field from 20 to 40 characters
        System.out.println("Extending size of column FOO to 40 characters:");
        C_FOO.setSize(40);
        script.clear();
        db.getDriver().getDDLScript(DBCmdType.ALTER, C_FOO, script);
        script.run(db.getDriver(), conn, false);

        // Now set a longer value for the record
View Full Code Here


        // Enable Column default for the database
        // This is needed for adding required fields to non-empty tables
        db.getDriver().setDDLColumnDefaults(true);

        // First, add a new column to the Table object
        DBTableColumn C_FOO = db.T_EMPLOYEES.addColumn("FOO", DataType.TEXT, 20, DataMode.Nullable);

        // Now create the corresponding DDL statement
        System.out.println("Creating new column named FOO as varchar(20) for the EMPLOYEES table:");
        DBSQLScript script = new DBSQLScript();
        db.getDriver().getDDLScript(DBCmdType.CREATE, C_FOO, script);
        script.run(db.getDriver(), conn, false);
       
        // Now load a record from that table and set the value for foo
        System.out.println("Changing the value for the FOO field of a particular employee:");
        DBRecord rec = new DBRecord();
        rec.read(db.T_EMPLOYEES, idTestPerson, conn);
        rec.setValue(C_FOO, "Hello World");
        rec.update(conn);
       
        // Now extend the size of the field from 20 to 40 characters
        System.out.println("Extending size of column FOO to 40 characters:");
        C_FOO.setSize(40);
        script.clear();
        db.getDriver().getDDLScript(DBCmdType.ALTER, C_FOO, script);
        script.run(db.getDriver(), conn, false);

        // Now set a longer value for the record
View Full Code Here

    input.setValue(getRecord().getValue(col));
    return input;
  }

  private HtmlOutputLabel createOutputLabelForCol() {
    DBTableColumn col = getColumn();
    HtmlOutputLabel label = new HtmlOutputLabel();
    String colName = getLabelString()+":";
    if (col.isRequired()) {
      colName += "*";
    }
    label.setId(this.getId() + LABEL_SUFFIX);
    label.setValue(colName);
    return label;
View Full Code Here

  }

  @Override
  public void updateModel(FacesContext context) {
    DBRecord rec = getRecord();
    DBTableColumn col = getColumn();

    // don't set automatically created cols or readOnly cols
    if (!col.isAutoGenerated() && !isReadOnly()) {
      UIInput inputComponent = (UIInput)getChildren().get(1);
      rec.setValue(col, inputComponent.getValue());
    }
    super.updateModel(context);
  }
View Full Code Here

    {
      return;
    }
   
    DBRecord rec = getRecord();
    DBTableColumn col = (DBTableColumn) rec.getDBColumn(rec
        .getFieldIndex(getAttributes().get("column").toString()));
    try {
      col.checkValue(inputComponent.getValue());
    } catch (Exception e) {
      FacesContext.getCurrentInstance().addMessage(getClientId(), new FacesMessage(e.getLocalizedMessage()));
      this.setValid(false);
    }
    super.validate(context);
View Full Code Here

      }
    }
  }

  private UIInput createInputComponentForCol() {
    DBTableColumn col = getColumn();
    String controlType = col.getControlType();
    // registerControl("text", new TextInputControl());
    // registerControl("select", new SelectInputControl());
    // registerControl("checkbox", new CheckboxInputControl());
    // registerControl("phone", new PhoneInputControl());
    // registerControl("radio", new RadioInputControl());
    // registerControl("textarea", new TextAreaInputControl());
    // registerControl("email", new EMailInputControl());
    // registerControl("hlink", new HLinkInputControl());
    // registerControl("password", new PasswordInputControl());
    UIInput input = null;
    if (controlType.equals("text")) {
      // DATE_TIME
      if (col.getDataType().equals(DataType.DATETIME))
      {
        HtmlInputText inputText = new HtmlInputText();
        inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
        inputText.setLabel(getLabelString());
        input = inputText;       
      }
      // AUTOINC
      else if (col.getDataType().equals(DataType.AUTOINC))
      {
        HtmlInputText inputText = new HtmlInputText();
        inputText.setReadonly(true);
        inputText.setLabel(getLabelString());
        input = inputText;       
      }
     
      // INTEGER
      else if (col.getDataType().equals(DataType.INTEGER))
      {
        HtmlInputText inputText = new HtmlInputText();
        inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
        inputText.setLabel(getLabelString());
        input = inputText;       
      }     
      // DATE
      else if (col.getDataType().equals(DataType.TEXT) || col.getDataType().equals(DataType.DATE)) {
        HtmlInputText inputText = new HtmlInputText();
        inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
        inputText.setLabel(getLabelString());
        input = inputText;
      }
      // TEXT
      else if (col.getDataType().equals(DataType.TEXT) || col.getDataType().equals(DataType.DATE)) {
        HtmlInputText inputText = new HtmlInputText();
        inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
        inputText.setLabel(getLabelString());
        inputText.setMaxlength((int) Math.round(col.getSize()));
        input = inputText;
      }
    }
   
    else if (controlType.equals("textarea")) {
     
      HtmlSelectBooleanCheckbox inputSelectBooleanCheckbox = new HtmlSelectBooleanCheckbox();
      inputSelectBooleanCheckbox.setReadonly(isReadOnly() || col.isAutoGenerated());
      inputSelectBooleanCheckbox.setLabel(getLabelString());
      input = inputSelectBooleanCheckbox;
    } else if (controlType.equals("password")) {
      HtmlSelectBooleanCheckbox inputSelectBooleanCheckbox = new HtmlSelectBooleanCheckbox();
      inputSelectBooleanCheckbox.setReadonly(isReadOnly() || col.isAutoGenerated());
      inputSelectBooleanCheckbox.setLabel(getLabelString());
      input = inputSelectBooleanCheckbox;
    } else if (controlType.equals("select")) {
      HtmlSelectOneMenu inputSelectOneMenu = new HtmlSelectOneMenu();
      inputSelectOneMenu.setReadonly(isReadOnly() || col.isAutoGenerated());
      addSelectItems(inputSelectOneMenu);
      inputSelectOneMenu.setLabel(getLabelString());
      input = inputSelectOneMenu;

    } else if (controlType.equals("checkbox")) {
      HtmlSelectBooleanCheckbox inputSelectBooleanCheckbox = new HtmlSelectBooleanCheckbox();
      inputSelectBooleanCheckbox.setReadonly(isReadOnly() || col.isAutoGenerated());
      inputSelectBooleanCheckbox.setLabel(getLabelString());
      input = inputSelectBooleanCheckbox;
    }
   
    else if (controlType.equals("phone")) {
      HtmlInputText inputText = new HtmlInputText();
      inputText.setReadonly(isReadOnly() || col.isAutoGenerated());
      inputText.setLabel(getLabelString());
      inputText.setMaxlength((int) Math.round(col.getSize()));
      input = inputText;
    }

    // For testing purposes only
    if (input == null) {
      log.error("No matching control found for column "
          + col.getFullName());
      input = new HtmlInputText();
    }

    // JSF2 Validator
    switch (col.getDataType()) {
    case TEXT: {
      input.addValidator(new LengthValidator((int) Math.round(col
          .getSize())));
      break;
    }
    }

    input.setRequired(col.isRequired() && !col.isAutoGenerated());
    input.setId(this.getId() + INPUT_SUFFIX);
    input.setValue(getRecord().getValue(col));
    return input;
  }
View Full Code Here

        {
            DBTable table = seqtabs.next();
            Iterator<DBColumn> cols = table.getColumns().iterator();
            while (cols.hasNext())
            {
                DBTableColumn c = (DBTableColumn) cols.next();
                if (c.getDataType() == DataType.AUTOINC)
                {
                    createSequence(db, c, script);
                }
            }
        }
View Full Code Here

        {
            DBTable table = seqtabs.next();
            Iterator<DBColumn> cols = table.getColumns().iterator();
            while (cols.hasNext())
            {
                DBTableColumn c = (DBTableColumn) cols.next();
                if (c.getDataType() == DataType.AUTOINC)
                {
                    createSequence(db, c, script);
                }
            }
        }
View Full Code Here

        {
            DBTable table = seqtabs.next();
            Iterator<DBColumn> cols = table.getColumns().iterator();
            while (cols.hasNext())
            {
                DBTableColumn c = (DBTableColumn) cols.next();
                if (c.getDataType() == DataType.AUTOINC)
                {
                    createSequence(db, c, script);
                }
            }
        }
View Full Code Here

        {
            DBTable table = seqtabs.next();
            Iterator<DBColumn> cols = table.getColumns().iterator();
            while (cols.hasNext())
            {
                DBTableColumn c = (DBTableColumn) cols.next();
                if (c.getDataType() == DataType.AUTOINC)
                {
                    createSequence(db, c, script);
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.empire.db.DBTableColumn

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.