Example usage for org.hibernate SQLQuery addEntity

List of usage examples for org.hibernate SQLQuery addEntity

Introduction

In this page you can find the example usage for org.hibernate SQLQuery addEntity.

Prototype

SQLQuery<T> addEntity(Class entityType);

Source Link

Document

Declare a "root" entity, without specifying an alias.

Usage

From source file:com.waveerp.TableTblOrgRestday.java

License:Open Source License

public String getTableValue(String pOrgId, String pField) {

    List<Tblorgrestday> myList = null;
    Iterator<Tblorgrestday> iterator = null;
    Tblorgrestday item = null;/*w ww.j  a  v  a  2  s . c o m*/

    String strResult = "ERROR";

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tblorgrestday where orgid = '" + pOrgId + "' ;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tblorgrestday.class);

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        /**
         * At this point, only one record should be retrieved
        */
        while (iterator.hasNext()) {

            item = (Tblorgrestday) iterator.next();

            if (pField.compareTo("ENTITYID") == 0) {

                strResult = (String) item.getEntityid();

            } else if (pField.compareTo("DESCRIPTION") == 0) {

                strResult = (String) item.getDescription();

            } else if (pField.compareTo("PID") == 0) {

                strResult = (String) item.getPid();

            } else if (pField.compareTo("DSUN") == 0) {

                strResult = (String) item.getDsun();

            } else if (pField.compareTo("DMON") == 0) {

                strResult = (String) item.getDmon();

            } else if (pField.compareTo("DTUES") == 0) {

                strResult = (String) item.getDtues();

            } else if (pField.compareTo("DWED") == 0) {

                strResult = (String) item.getDwed();

            } else if (pField.compareTo("DTHU") == 0) {

                strResult = (String) item.getDthu();

            } else if (pField.compareTo("DFRI") == 0) {

                strResult = (String) item.getDfri();

            } else if (pField.compareTo("DSAT") == 0) {

                strResult = (String) item.getDsat();

            } else if (pField.compareTo("JUID") == 0) {

                strResult = (String) item.getJuid();

            } else if (pField.compareTo("STATUS") == 0) {

                strResult = (String) item.getSstatus();

            } else {

                strResult = "NULL";

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    return strResult;

}

From source file:com.waveerp.TableTblPerson.java

License:Open Source License

public String getTableValue(String pPartyId, String pField) {

    List<Tblperson> myList = null;
    Iterator<Tblperson> iterator = null;
    Tblperson item = null;//from   www .j a  v a 2 s.co  m

    String strResult = "ERROR";

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tblperson where partyid = '" + pPartyId + "' ;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tblperson.class);

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        /**
         * At this point, only one record should be retrieved
        */
        while (iterator.hasNext()) {

            item = (Tblperson) iterator.next();

            if (pField.compareTo("ENTITYID") == 0) {

                strResult = (String) item.getEntityid();

            } else if (pField.compareTo("TITLE") == 0) {

                strResult = (String) item.getTitle();

            } else if (pField.compareTo("FIRSTNAME") == 0) {

                strResult = (String) item.getFirstname();

            } else if (pField.compareTo("MIDDLENAME") == 0) {

                strResult = (String) item.getMiddlename();

            } else if (pField.compareTo("LASTNAME") == 0) {

                strResult = (String) item.getLastname();

            } else if (pField.compareTo("SUFFIX") == 0) {

                strResult = (String) item.getSuffix();

            } else if (pField.compareTo("ADDR01") == 0) {

                strResult = (String) item.getAddr01();

            } else if (pField.compareTo("ADDR02") == 0) {

                strResult = (String) item.getAddr02();

            } else if (pField.compareTo("CITY") == 0) {

                strResult = (String) item.getCity();

            } else if (pField.compareTo("EMPSTATE") == 0) {

                strResult = (String) item.getEmpstate();

            } else if (pField.compareTo("ZIPCODE") == 0) {

                strResult = (String) item.getZipcode();

            } else if (pField.compareTo("COUNTRY") == 0) {

                strResult = (String) item.getCountry();

            } else if (pField.compareTo("EMAIL") == 0) {

                strResult = (String) item.getEmail();

            } else if (pField.compareTo("COUNTRYCODEHOME") == 0) {

                strResult = (String) item.getCountrycodehome();

            } else if (pField.compareTo("AREACODEHOME") == 0) {

                strResult = (String) item.getAreacodehome();

            } else if (pField.compareTo("PHONEHOME") == 0) {

                strResult = (String) item.getPhonehome();

            } else if (pField.compareTo("EXTENSIONHOME") == 0) {

                strResult = (String) item.getExtensionhome();

            } else if (pField.compareTo("COUNTRYCODEWORK") == 0) {

                strResult = (String) item.getCountrycodework();

            } else if (pField.compareTo("AREACODEWORK") == 0) {

                strResult = (String) item.getAreacodework();

            } else if (pField.compareTo("PHONEWORK") == 0) {

                strResult = (String) item.getPhonework();

            } else if (pField.compareTo("EXTENSIONWORK") == 0) {

                strResult = (String) item.getExtensionwork();

            } else if (pField.compareTo("COUNTRYCODEFAX") == 0) {

                strResult = (String) item.getCountrycodefax();

            } else if (pField.compareTo("AREACODEFAX") == 0) {

                strResult = (String) item.getAreacodefax();

            } else if (pField.compareTo("PHONEFAX") == 0) {

                strResult = (String) item.getPhonefax();

            } else if (pField.compareTo("EXTENSIONFAX") == 0) {

                strResult = (String) item.getExtensionfax();

            } else if (pField.compareTo("COUNTRYCODEMOBILE") == 0) {

                strResult = (String) item.getCountrycodemobile();

            } else if (pField.compareTo("AREACODEMOBILE") == 0) {

                strResult = (String) item.getAreacodemobile();

            } else if (pField.compareTo("PHONEMOBILE") == 0) {

                strResult = (String) item.getPhonemobile();

            } else if (pField.compareTo("EXTENSIONMOBILE") == 0) {

                strResult = (String) item.getExtensionmobile();

            } else if (pField.compareTo("ROLETYPE") == 0) {

                strResult = (String) item.getRoletype();

            } else if (pField.compareTo("USERJUID") == 0) {

                strResult = (String) item.getUserjuid();

            } else if (pField.compareTo("JUID") == 0) {

                strResult = (String) item.getJuid();

            } else if (pField.compareTo("STATUS") == 0) {

                strResult = (String) item.getSstatus();

            } else {

                strResult = "NULL";

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    return strResult;

}

From source file:com.waveerp.TableTblUser.java

License:Open Source License

public String updateUserPassword(String pUserId, String pOldPassword, String pNewPassword) {

    //Execute the SQL script using this object
    execGenericNonQuery enq = new execGenericNonQuery();
    //For the SQL Escape
    systemTextUtils stu = new systemTextUtils();

    // Call the registry management system                    
    registrySystem rs = new registrySystem();

    // Call the encryption management system
    desEncryption de = new desEncryption();
    de.Encrypter("", "");

    // Return the key to be encoded
    String strEnc = de.encrypt(pNewPassword);

    String isValid = "NO";
    String strMsg = "Password has been updated.";

    List<Tbluser> myList = null;
    Iterator<Tbluser> iterator = null;
    Tbluser item = null;/*from   w ww  . j  av a  2 s. c  o m*/

    try {

        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tbluser where userid = '" + pUserId + "';";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tbluser.class);
        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        // At this stage, a single record should be retrieve
        // else we have issue with uniqueness
        while (iterator.hasNext()) {

            item = (Tbluser) iterator.next();

            String pass = (String) item.getPassword();
            String passe = (String) item.getPasswdenc();
            passe = de.decrypt(passe);

            if (passe.compareTo(pOldPassword) == 0) {

                isValid = "YES";

            } else if (pass.compareTo(pOldPassword) == 0) {

                isValid = "YES";

            } else {

                isValid = "NO";

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    // Update the object
    if (item != null) {

        item.setPassword("LOCKED!");
        item.setPasswdenc(strEnc);

    }

    //Update the back-end database with the changes
    try {

        if (isValid.compareTo("YES") == 0) {

            dbServices.begin();
            dbServices.update(item);
            dbServices.commit();

            String sQL = "";
            sQL = sQL + "update Tbluser set ";
            sQL = sQL + "password = '" + stu.mySQLEscape("LOCKED!") + "', ";
            sQL = sQL + "passwdenc = '" + stu.mySQLEscape(strEnc) + "' ";

            sQL = sQL + "where userid = '" + stu.mySQLEscape(pUserId) + "' ;";

            enq.execNonQuery(sQL);

        } else {

            strMsg = "Old password does not match!";

        }

    } catch (Exception e) {

        return e.getMessage();
        //strMsg = "Function error!";

    }

    return strMsg;

}

From source file:com.waveerp.TableTblUser.java

License:Open Source License

public String encryptUserPasswordAll() {

    //Execute the SQL script using this object
    execGenericNonQuery enq = new execGenericNonQuery();
    //For the SQL Escape
    systemTextUtils stu = new systemTextUtils();

    // Call the encryption management system
    desEncryption de = new desEncryption();
    de.Encrypter("", "");

    String strMsg = "Passwords had been updated.";

    List<Tbluser> myList = null;
    Iterator<Tbluser> iterator = null;
    Tbluser item = null;/*w w  w  . j  av  a2 s  .co m*/

    try {

        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tbluser;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tbluser.class);
        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        // Loop and generate an encrypted password
        while (iterator.hasNext()) {

            item = (Tbluser) iterator.next();

            String pass = (String) item.getPassword();
            String strUserid = (String) item.getUserid();

            //Create encryption only on unlocked items.
            if (pass.compareTo("LOCKED!") != 0) {

                //Generate the encrypted password
                String strEnc = de.encrypt(pass);
                //Save the encrypted password to 
                item.setPasswdenc(strEnc);
                item.setPassword("LOCKED!");

                //Update the database record
                dbServices.begin();
                dbServices.update(item);
                dbServices.commit();

                String sQL = "";
                sQL = sQL + "update Tbluser set ";
                sQL = sQL + "password = '" + stu.mySQLEscape("LOCKED!") + "', ";
                sQL = sQL + "passwdenc = '" + stu.mySQLEscape(strEnc) + "' ";

                sQL = sQL + "where userid = '" + stu.mySQLEscape(strUserid) + "' ;";

                enq.execNonQuery(sQL);

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    return strMsg;

}

From source file:com.waveerp.TableTblUser.java

License:Open Source License

public String decryptUserPasswordAll() {

    //Execute the SQL script using this object
    execGenericNonQuery enq = new execGenericNonQuery();
    //For the SQL Escape
    systemTextUtils stu = new systemTextUtils();

    // Call the encryption management system
    desEncryption de = new desEncryption();
    de.Encrypter("", "");

    String strMsg = "Passwords had been updated.";

    List<Tbluser> myList = null;
    Iterator<Tbluser> iterator = null;
    Tbluser item = null;/* w w  w  . j a va2 s .  co m*/

    try {

        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tbluser;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tbluser.class);
        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        // Loop and generate an encrypted password
        while (iterator.hasNext()) {

            item = (Tbluser) iterator.next();

            String strUserid = (String) item.getUserid();
            String passe = (String) item.getPasswdenc();

            //Generate the encrypted password
            String strDec = de.decrypt(passe);
            //Save the encrypted password to 
            item.setPassword(strDec);

            //Update the database record
            dbServices.begin();
            dbServices.update(item);
            dbServices.commit();

            String sQL = "";
            sQL = sQL + "update Tbluser set ";
            sQL = sQL + "password = '" + stu.mySQLEscape(strDec) + "' ";

            sQL = sQL + "where userid = '" + stu.mySQLEscape(strUserid) + "' ;";

            enq.execNonQuery(sQL);

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    return strMsg;

}

From source file:com.waveerp.TableTblUser.java

License:Open Source License

public String getTableValue(String pUserId, String pField) {

    // Call the encryption management system
    desEncryption de = new desEncryption();
    de.Encrypter("", "");

    List<Tbluser> myList = null;
    Iterator<Tbluser> iterator = null;
    Tbluser item = null;/*w w w. j  a  v a2s .c om*/

    String strResult = "ERROR";

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tbluser where userid = '" + pUserId + "' ;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tbluser.class);

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        /**
         * At this point, only one record should be retrieved
        */
        while (iterator.hasNext()) {

            item = (Tbluser) iterator.next();

            if (pField.compareTo("ENTITYID") == 0) {

                strResult = (String) item.getEntityid();

            } else if (pField.compareTo("USERNAME") == 0) {

                strResult = (String) item.getUsername();

            } else if (pField.compareTo("FIRSTNAME") == 0) {

                strResult = (String) item.getFirstname();

            } else if (pField.compareTo("MIDDLENAME") == 0) {

                strResult = (String) item.getMiddlename();

            } else if (pField.compareTo("LASTNAME") == 0) {

                strResult = (String) item.getLastname();

            } else if (pField.compareTo("STATUS") == 0) {

                strResult = (String) item.getSstatus();

            } else if (pField.compareTo("EMAIL") == 0) {

                strResult = (String) item.getEmail();

            } else if (pField.compareTo("PARENTPERSON") == 0) {

                strResult = (String) item.getParentPerson();

            } else if (pField.compareTo("PASSWORD") == 0) {

                strResult = (String) item.getPassword();

            } else if (pField.compareTo("PASSWDENC") == 0) {

                strResult = (String) item.getPasswdenc();
                //Generate the encrypted password
                String strDec = de.decrypt(strResult);
                strResult = strDec;

            } else {

                strResult = "NULL";

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    if (item == null) {

        return "FAIL";

    }

    return strResult;

}

From source file:com.waveerp.TableTblUser.java

License:Open Source License

public String getTableValueByEmail(String pEmail, String pField) {

    // Call the encryption management system
    desEncryption de = new desEncryption();
    de.Encrypter("", "");

    List<Tbluser> myList = null;
    Iterator<Tbluser> iterator = null;
    Tbluser item = null;/*from   ww  w .j  av  a2 s.  c om*/

    String strResult = "ERROR";

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tbluser where email = '" + pEmail + "' ;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tbluser.class);

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        /**
         * At this point, only one record should be retrieved
        */
        while (iterator.hasNext()) {

            item = (Tbluser) iterator.next();

            if (pField.compareTo("ENTITYID") == 0) {

                strResult = (String) item.getEntityid();

            } else if (pField.compareTo("USERNAME") == 0) {

                strResult = (String) item.getUsername();

            } else if (pField.compareTo("FIRSTNAME") == 0) {

                strResult = (String) item.getFirstname();

            } else if (pField.compareTo("MIDDLENAME") == 0) {

                strResult = (String) item.getMiddlename();

            } else if (pField.compareTo("LASTNAME") == 0) {

                strResult = (String) item.getLastname();

            } else if (pField.compareTo("STATUS") == 0) {

                strResult = (String) item.getSstatus();

            } else if (pField.compareTo("EMAIL") == 0) {

                strResult = (String) item.getEmail();

            } else if (pField.compareTo("PARENTPERSON") == 0) {

                strResult = (String) item.getParentPerson();

            } else if (pField.compareTo("PASSWORD") == 0) {

                strResult = (String) item.getPassword();

            } else if (pField.compareTo("PASSWDENC") == 0) {

                strResult = (String) item.getPasswdenc();
                //Generate the encrypted password
                String strDec = de.decrypt(strResult);
                strResult = strDec;

            } else {

                strResult = "NULL";

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    if (item == null) {

        return "FAIL";

    }

    return strResult;

}

From source file:com.waveerp.TableTblUser.java

License:Open Source License

public String findEmail(String pEntity, String pEmail) {

    List<Tbluser> myList = null;
    Iterator<Tbluser> iterator = null;
    Tbluser item = null;// www  . j av  a2s. c om

    String strResult = "ERROR";

    try {

        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tbluser where entityid = '" + pEntity + "' and email ='" + pEmail
                + "' ;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tbluser.class);

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        /**
         * At this point, only one record should be retrieved
        */
        while (iterator.hasNext()) {

            item = (Tbluser) iterator.next();

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    if (item == null) {

        return "FAIL";

    }

    return "OK";

}

From source file:com.waveerp.TableWtmBundyList.java

License:Open Source License

public String getTableValue(String pDevice, String pField) {

    List<Wtmbundylist> myList = null;
    Iterator<Wtmbundylist> iterator = null;
    Wtmbundylist item = null;//from w  w w  .j  a va 2s. c om

    String strResult = "ERROR";

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Wtmbundylist where deviceid = '" + pDevice + "' ;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Wtmbundylist.class);

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        /**
         * At this point, only one record should be retrieved
        */
        while (iterator.hasNext()) {

            item = (Wtmbundylist) iterator.next();

            if (pField.compareTo("USEINOUT") == 0) {

                strResult = (String) item.getUseinout();

            } else if (pField.compareTo("DESCRIPTION") == 0) {

                strResult = (String) item.getDescription();

            } else if (pField.compareTo("LOCID") == 0) {

                strResult = (String) item.getLocid();

            } else if (pField.compareTo("JUID") == 0) {

                strResult = (String) item.getJuid();

            } else if (pField.compareTo("STATUS") == 0) {

                strResult = (String) item.getSstatus();

            } else {

                strResult = "NULL";

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    return strResult;

}

From source file:com.waveerp.TableWtmTimeDataRaw.java

License:Open Source License

public String getTableValue(String pJuid, String pField) {

    List<Wtmtimedataraw> myList = null;
    Iterator<Wtmtimedataraw> iterator = null;
    Wtmtimedataraw item = null;/*www. jav a  2  s  .co m*/

    String strResult = "ERROR";

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Wtmtimedataraw where juid = '" + pJuid + "' ;";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Wtmtimedataraw.class);

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        /**
         * At this point, only one record should be retrieved
        */
        while (iterator.hasNext()) {

            item = (Wtmtimedataraw) iterator.next();

            if (pField.compareTo("DEVICEID") == 0) {

                strResult = (String) item.getDeviceid();

            } else if (pField.compareTo("BADGE") == 0) {

                strResult = (String) item.getBadge();

            } else if (pField.compareTo("AXING") == 0) {

                strResult = (String) item.getAxing();

            } else if (pField.compareTo("DATASRC") == 0) {

                strResult = (String) item.getDatasrc();

            } else if (pField.compareTo("DATASTAT") == 0) {

                strResult = (String) item.getDatastat();

            } else if (pField.compareTo("USEINOUT") == 0) {

                strResult = (String) item.getUseinout();

            } else if (pField.compareTo("MAPLOCID") == 0) {

                strResult = (String) item.getMaplocid();

            } else if (pField.compareTo("MAPENTITY") == 0) {

                strResult = (String) item.getMapentity();

            } else if (pField.compareTo("MAPSITEID") == 0) {

                strResult = (String) item.getMapsiteid();

            } else if (pField.compareTo("MAPUSERID") == 0) {

                strResult = (String) item.getMapuserid();

            } else if (pField.compareTo("MAPEMPID") == 0) {

                strResult = (String) item.getMapempid();

            } else if (pField.compareTo("MAPFNAME") == 0) {

                strResult = (String) item.getMapfname();

            } else if (pField.compareTo("MAPMNAME") == 0) {

                strResult = (String) item.getMapmname();

            } else if (pField.compareTo("MAPLNAME") == 0) {

                strResult = (String) item.getMaplname();

            } else if (pField.compareTo("MAPDIV") == 0) {

                strResult = (String) item.getMapdiv();

            } else if (pField.compareTo("MAPDEPT") == 0) {

                strResult = (String) item.getMapdept();

            } else if (pField.compareTo("MAPSECT") == 0) {

                strResult = (String) item.getMapsect();

            } else {

                strResult = "NULL";

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    return strResult;

}