Package com.cosmo.orm.annotations

Examples of com.cosmo.orm.annotations.CormObjectField


    * @throws InvalidMappingException
    */
   public void addGroup(Class<?> ormClass) throws InvalidMappingException
   {
      CormObject ct;
      CormObjectField cfg;
      FormFieldset group;

      // Comprueba que sea un objeto CORM
      ct = ormClass.getAnnotation(CormObject.class);
      if (ct == null)
      {
         throw new InvalidMappingException("No CormObject annotation detected on POJO class.");
      }

      // Obtiene las propiedades de la clase y las mapea al formulario
      this.name = ct.formName();

      // Obtiene la lista de campos y los mapea a un grupo
      group = new FormFieldset("");
      group.setTitle(ct.title());
      group.setDescription(ct.description());
      for (Method method : ormClass.getMethods())
      {
         cfg = method.getAnnotation(CormObjectField.class);

         if (cfg != null && !cfg.isAutogenerated())
         {
            if (cfg.fieldClass() == FormFieldText.class)
            {
               group.addField(new FormFieldText(cfg.dbTableColumn(), cfg.label()));
            }
            else if (cfg.fieldClass() == FormFieldTextArea.class)
            {
               group.addField(new FormFieldTextArea(cfg.dbTableColumn(), cfg.label()));
            }
            else if (cfg.fieldClass() == FormFieldInteger.class)
            {
               group.addField(new FormFieldInteger(cfg.dbTableColumn(), cfg.label()));
            }
            else if (cfg.fieldClass() == FormFieldNumber.class)
            {
               group.addField(new FormFieldNumber(cfg.dbTableColumn(), cfg.label()));
            }
            else if (cfg.fieldClass() == FormFieldDate.class)
            {
               group.addField(new FormFieldDate(cfg.dbTableColumn(), cfg.label()));
            }
            else if (cfg.fieldClass() == FormFieldBoolean.class)
            {
               group.addField(new FormFieldBoolean(cfg.dbTableColumn(), cfg.label()));
            }
            else if (cfg.fieldClass() == FormFieldList.class)
            {
               group.addField(new FormFieldList(cfg.dbTableColumn(), cfg.label(), getWorkspace().getProperties().getDataProperties().getDataList(cfg.list())));
            }
            else if (cfg.fieldClass() == FormFieldCaptcha.class)
            {
               group.addField(new FormFieldCaptcha(cfg.dbTableColumn(), cfg.label()));
            }
         }
      }
      this.addGroup(group);

View Full Code Here


    * @throws IllegalArgumentException
    */
   public void addGroup(Object data) throws InvalidMappingException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
   {
      CormObject ct;
      CormObjectField cfg;
      FormFieldset group;

      // Comprueba si el objeto proporcionado es un objeto CORM v�lido
      if (!OrmFactory.isValidCormObject(data.getClass()))
      {
         throw new InvalidMappingException(data.getClass() + " is not a CORM object.");
      }

      // Obtiene las propiedades de la clase y las mapea al formulario
      ct = data.getClass().getAnnotation(CormObject.class);
      this.name = ct.formName();

      // Obtiene la lista de campos y los mapea a un grupo
      group = new FormFieldset("");
      group.setTitle(ct.title());
      group.setDescription(ct.description());
      for (Method method : data.getClass().getMethods())
      {
         cfg = method.getAnnotation(CormObjectField.class);

         if (cfg != null && !cfg.isAutogenerated())
         {
            if (cfg.fieldClass() == FormFieldText.class)
            {
               FormFieldText fld = new FormFieldText(cfg.dbTableColumn(), cfg.label());
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
            else if (cfg.fieldClass() == FormFieldTextArea.class)
            {
               FormFieldTextArea fld = new FormFieldTextArea(cfg.dbTableColumn(), cfg.label());
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
            else if (cfg.fieldClass() == FormFieldInteger.class)
            {
               FormFieldInteger fld = new FormFieldInteger(cfg.dbTableColumn(), cfg.label());
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
            else if (cfg.fieldClass() == FormFieldNumber.class)
            {
               FormFieldNumber fld = new FormFieldNumber(cfg.dbTableColumn(), cfg.label());
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
            else if (cfg.fieldClass() == FormFieldList.class)
            {
               FormFieldList fld = new FormFieldList(cfg.dbTableColumn(), cfg.label());
               fld.setList(getWorkspace().getProperties().getDataProperties().getDataList(cfg.list()));
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
            else if (cfg.fieldClass() == FormFieldBoolean.class)
            {
               FormFieldBoolean fld = new FormFieldBoolean(cfg.dbTableColumn(), cfg.label());
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
            else if (cfg.fieldClass() == FormFieldDate.class)
            {
               FormFieldDate fld = new FormFieldDate(cfg.dbTableColumn(), cfg.label());
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
            else if (cfg.fieldClass() == FormFieldCaptcha.class)
            {
               FormFieldCaptcha fld = new FormFieldCaptcha(cfg.dbTableColumn(), cfg.label());
               fld.setValue(method.invoke(data));
               group.addField(fld);
            }
         }
      }
View Full Code Here

    * @param ormClass Clase CORM que contiene la definición de la misma (anotaciones).
    */
   private void setGridMetaData(Class<?> ormClass, boolean showAllColumns)
   {
      int idx = 0;
      CormObjectField cfg;

      this.rowIds = new ArrayList<Integer>();

      for (Method method : ormClass.getMethods())
      {
         if (method.isAnnotationPresent(CormObjectField.class))
         {
            cfg = method.getAnnotation(CormObjectField.class);

            if (showAllColumns || (!showAllColumns && cfg.showInObjectListGrid()))
            {
               cfg = method.getAnnotation(CormObjectField.class);
               this.gridData.setColumnField(idx, cfg.dbTableColumn());
               this.gridData.setColumnPrimaryKey(idx, cfg.isPrimaryKey());
               idx++;
            }
         }
      }
   }
View Full Code Here

    *
    * @return Devuelve {@code true} si la clase dispone de propiedades ordenadas o {@code false} en cualquier otro caso.
    */
   public static boolean haveSortedFields(Class<?> ormClass)
   {
      CormObjectField cfg;

      for (Method method : ormClass.getMethods())
      {
         cfg = method.getAnnotation(CormObjectField.class);

         if (cfg != null)
         {
            if (cfg.sort() != FieldSortType.None)
            {
               return true;
            }
         }
      }
View Full Code Here

    */
   public ResultSet select(Class<?> ormClass, boolean showAllColumns) throws InvalidMappingException, SQLException, DataException, Exception
   {
      boolean first;
      StringBuilder sql = new StringBuilder();
      CormObjectField cf;
      ResultSet rs;

      // Comprueba si el objeto proporcionado es un objeto CORM v�lido
      if (!OrmFactory.isValidCormObject(ormClass))
      {
         throw new InvalidMappingException(ormClass.getName() + " is not a CORM object.");
      }

      // Configura la cl�usula SELECT
      sql.append(SQL_SELECT);
      sql.append(" ");

      first = true;
      for (Method method : ormClass.getMethods())
      {
         cf = method.getAnnotation(CormObjectField.class);
         if (cf != null)
         {
            if ((showAllColumns) || (!showAllColumns && cf.showInObjectListGrid()))
            {
               sql.append((first ? "" : ", "));
               sql.append(cf.dbTableColumn() + " As \"" + cf.label() + "\"");
               first = false;
            }
         }
      }
      sql.append(" ");

      // Configura la cl�usula FROM
      sql.append(SQL_FROM);
      sql.append(" ");
      sql.append(OrmFactory.getDbTableName(ormClass));
      sql.append(" ");

      // Configura la cl�usula ORDER BY
      if (OrmFactory.haveSortedFields(ormClass))
      {
         sql.append(SQL_ORDERBY);
         sql.append(" ");

         // Obtiene la lista de campos
         first = true;
         for (Method method : ormClass.getMethods())
         {
            cf = method.getAnnotation(CormObjectField.class);
            if (cf != null)
            {
               if (cf.sort() == FieldSortType.Ascending)
               {
                  sql.append((first ? "" : ", "));
                  sql.append(cf.dbTableColumn() + " ");
                  sql.append(SQL_ORDERBY_ASC);

                  first = false;
               }
               else if (cf.sort() == FieldSortType.Descending)
               {
                  sql.append((first ? "" : ", "));
                  sql.append(cf.dbTableColumn() + " ");
                  sql.append(SQL_ORDERBY_DESC);

                  first = false;
               }
            }
View Full Code Here

    */
   public Object get(Object data) throws InvalidMappingException, SQLException, DataException, Exception
   {
      boolean first;
      StringBuilder sql = new StringBuilder();
      CormObjectField cf;
      CormFieldSetter cfs;
      ResultSet rs;

      // Comprueba si el objeto proporcionado es un objeto CORM v�lido
      if (!OrmFactory.isValidCormObject(data.getClass()))
      {
         throw new InvalidMappingException(data.getClass() + " is not a CORM object.");
      }

      // Configura la cl�usula SELECT
      sql.append(SQL_SELECT);
      sql.append(" ");

      first = true;
      for (Method method : data.getClass().getMethods())
      {
         cf = method.getAnnotation(CormObjectField.class);
         if (cf != null)
         {
            sql.append((first ? "" : ", "));
            sql.append(cf.dbTableColumn());

            first = false;
         }
      }
      sql.append(" ");
View Full Code Here

    */
   public void insert(Object data) throws InvalidMappingException, SQLException, DataException, Exception
   {
      boolean first;
      StringBuilder sql = new StringBuilder();
      CormObjectField cf;

      // Comprueba si el objeto proporcionado es un objeto CORM v�lido
      if (!OrmFactory.isValidCormObject(data.getClass()))
      {
         throw new InvalidMappingException(data.getClass().getName() + " is not a CORM object.");
      }

      // Genera la cl�usula INSERT
      sql.append(SQL_INSERT);
      sql.append(" ");
      sql.append(OrmFactory.getDbTableName(data.getClass()));
      sql.append(" (");

      first = true;
      for (Method method : data.getClass().getMethods())
      {
         cf = method.getAnnotation(CormObjectField.class);

         if (cf != null && !cf.readOnly() && !cf.isAutogenerated())
         {
            sql.append((first ? "" : ", "));
            sql.append(cf.dbTableColumn());
            first = false;
         }
      }

      sql.append(") ");

      // Genera la cl�usula VALUES
      sql.append(SQL_INSERT_VALUES);
      sql.append(" (");

      first = true;
      for (Method method : data.getClass().getMethods())
      {
         cf = method.getAnnotation(CormObjectField.class);

         if (cf != null && !cf.readOnly() && !cf.isAutogenerated())
         {
            sql.append((first ? "" : ", "));
            sql.append(getFormatedValue(method, data));

            first = false;
View Full Code Here

    */
   public void update(Object data) throws InvalidMappingException, SQLException, DataException, Exception
   {
      boolean first;
      StringBuilder sql = new StringBuilder();
      CormObjectField cfg;

      // Comprueba si el objeto proporcionado es un objeto CORM v�lido
      if (!OrmFactory.isValidCormObject(data.getClass()))
      {
         throw new InvalidMappingException(data.getClass().getName() + " is not a CORM object.");
      }

      // Genera la cl�usula INSERT
      sql.append(SQL_UPDATE);
      sql.append(" ");
      sql.append(OrmFactory.getDbTableName(data.getClass()));
      sql.append(" ");

      // Genera la cl�usula SET
      sql.append(SQL_SET);
      sql.append(" ");

      first = true;
      for (Method method : data.getClass().getMethods())
      {
         cfg = method.getAnnotation(CormObjectField.class);

         if (cfg != null)
         {
            if (!cfg.isPrimaryKey())
            {
               sql.append((first ? "" : ", "));
               sql.append(method.getAnnotation(CormObjectField.class).dbTableColumn());
               sql.append(" = ");
               sql.append(getFormatedValue(method, data));
View Full Code Here

TOP

Related Classes of com.cosmo.orm.annotations.CormObjectField

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.