Package api

Source Code of api.PalabraSemantica

/**
*
*/
package api;

import org.orm.PersistentException;
import org.orm.PersistentTransaction;

/**
* @author varav
*
*/
public class PalabraSemantica {
  /**
   * Add Word
   * @param word
   * @param valor
   * @return
   */
  public int add(String word, int valor){
    int respuestas = 0;
   
    /*
     * Validar que vengan los parametros
     */
    if(word.length()>0 && valor!=0){
     
      try {
        orm.Tmp_palabrasemantica ormPalabrasemanticases = orm.Tmp_palabrasemanticaDAO.loadTmp_palabrasemanticaByQuery("ps_palabra='"+word+"'", null);

        /*
         * Validar que registro no exista en la base de datos
         */
        if (ormPalabrasemanticases==null) {
          /*
           * Agrego
           */
          PersistentTransaction t = orm.MercadoPublico2PersistentManager.instance().getSession().beginTransaction();
          try {
            orm.Tmp_palabrasemantica lormPalabrasemanticas = orm.Tmp_palabrasemanticaDAO.createTmp_palabrasemantica();
            lormPalabrasemanticas.setPs_palabra(word);
            lormPalabrasemanticas.setPs_valor(valor);
            // Initialize the properties of the persistent object here
            orm.Tmp_palabrasemanticaDAO.save(lormPalabrasemanticas);
            t.commit();

            respuestas = 1;
          }
          catch (Exception e) {
            t.rollback();
            /*
             * -3 if exist error in ORM tier
             */

            respuestas = -3;
          }
        } else {
          /*
           * -2 existe el registro
           */
          respuestas = -2;
        }
      } catch (PersistentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
     
     
    }
    else {
      /*
       * -1 faltan parametro obligatorio
       */
      respuestas = -1;
    }
   
    return respuestas;
  }

  /**
   * Show Word
   * @param word
   * @param valor
   * @return
   */
  public orm.Tmp_palabrasemantica[] load(String word){
   
    String wordsearch = null;
    /*
     * Validar que vengan los parametros
     */
    if(word != null ){
      wordsearch = "ps_palabra='"+word+"'";
    }
   
     
      try {
        orm.Tmp_palabrasemantica[] ormPalabrasemanticases = ormPalabrasemanticases = orm.Tmp_palabrasemanticaDAO.listTmp_palabrasemanticaByQuery(wordsearch, null);
        return   ormPalabrasemanticases;
      } catch (PersistentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
     
     
   
   
   
    return null;
  }
}
TOP

Related Classes of api.PalabraSemantica

TOP
Copyright © 2018 www.massapi.com. 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.