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.registrySystem.java

License:Open Source License

public List<Tbluser> getQueryResult(String sQuery) {

    List<Tbluser> myList = null;
    try {//from  w w w. j  a  v a2s. c  om
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();

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

        dbServices.commit();

    } catch (Exception e) {
        dbServices.rollback();
    }
    return myList;
}

From source file:com.waveerp.registrySystem.java

License:Open Source License

public List<Tblregistry> execQuery(String sQuery) {
    List<Tblregistry> myList = null;
    try {/*from  w w  w . ja  va2s  .c  om*/
        dbServices.begin();
        Session session = dbServices.getDataServiceManager().getSession();

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

        dbServices.commit();

    } catch (Exception e) {
        dbServices.rollback();
    }
    return myList;
}

From source file:com.waveerp.registrySystem.java

License:Open Source License

public String getUserId() {
    List<Tblregistry> myList = null;
    Iterator<Tblregistry> iterator = null;
    String result = null;/*  w  w w.  j  a va 2s . co m*/

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tblregistry where varname = 'USERID';";

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

        dbServices.commit();

        iterator = myList.iterator();

        while (iterator.hasNext()) {
            Tblregistry user = (Tblregistry) iterator.next();
            String userid = (String) user.getVarvalue();
            result = userid;
        }
        return result;
    } catch (Exception e) {
        dbServices.rollback();
        return "FAIL";
    }
}

From source file:com.waveerp.registrySystem.java

License:Open Source License

/**
 * This code is used for reading and writing to the virtual counter of
 * each application that is connected to Wave ERP.
*///from   w  w  w  .  ja v a 2  s .co  m

public String readCounter(String pPrefix, String pKey, String pAppId, String pEntity) {

    List<Tblregistry> myList = null;
    Iterator<Tblregistry> iterator = null;

    String result = (String) "";
    String noChar = (String) "";
    String prefix = (String) "";
    String sequence = (String) "";

    int x = 1;
    int y;
    int z = 0;

    try {

        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tblregistry where entity = '" + pEntity + "' and appid = '" + pAppId
                + "' and varname like '" + pPrefix + pKey + "%';";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tblregistry.class);
        myList = query.list();
        dbServices.commit();

        iterator = myList.iterator();

        while (iterator.hasNext()) {

            Tblregistry registry = (Tblregistry) iterator.next();
            String varvalue = (String) registry.getVarvalue();
            String varname = (String) registry.getVarname();

            if (varvalue.compareTo("BLANK") == 0) {

                varvalue = "";

            } else {

                if (varname.compareTo(pPrefix + pKey + "PREFIX") == 0) {

                    prefix = varvalue;

                } else if (varname.compareTo(pPrefix + pKey + "NOCHAR") == 0) {

                    y = Integer.parseInt(varvalue);
                    z = y;
                    varvalue = "";

                    for (x = 1; x <= y; x++) {
                        varvalue = varvalue + "0";
                    }

                    noChar = varvalue;

                } else if (varname.compareTo(pPrefix + pKey + "SEQUENCE") == 0) {

                    if (varvalue.length() > z) {

                        return "Maximum Ticket series already reached";

                    } else {

                        result = result.substring(0, result.length() - varvalue.length());
                        z = Integer.parseInt(varvalue) + 1;
                        varvalue = Integer.toString(z);

                        sequence = varvalue;

                    }
                }
            }

            result = prefix + noChar + sequence;
        }

    } catch (Exception e) {
        dbServices.rollback();
        result = "FAIL";
    }

    //if (result == ""){
    //    result = "0";
    //}

    return result;
}

From source file:com.waveerp.registrySystem.java

License:Open Source License

public boolean saveCounter(String pPrefix, String pAppId, String pKey, String pEntity) {
    List<Tblregistry> myList = null;
    Iterator<Tblregistry> iterator = null;

    int weHaveSeq = 0;
    int weHaveNoChar = 0;
    int weHaveNoPrefix = 0;

    int y;/*from   ww w .  j a  va2  s. c  o  m*/

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tblregistry where entity = '" + pEntity + "' and appid = '" + pAppId
                + "' and varname like '" + pPrefix + pKey + "%';";

        SQLQuery query = session.createSQLQuery(sQuery);
        query.addEntity(Tblregistry.class);
        myList = query.list();
        dbServices.commit();

        iterator = myList.iterator();
        while (iterator.hasNext()) {

            Tblregistry registry = (Tblregistry) iterator.next();
            String varvalue = (String) registry.getVarvalue();
            String varname = (String) registry.getVarname();

            if (varname.compareTo(pPrefix + pKey + "PREFIX") == 0) {
                weHaveNoPrefix = 1;
            }

            if (varname.compareTo(pPrefix + pKey + "NOCHAR") == 0) {
                weHaveNoChar = 1;
            }

            if (varname.compareTo(pPrefix + pKey + "SEQUENCE") == 0) {
                sQuery = "update Tblregistry set varvalue = '" + varvalue + "' + 1 where varname = '" + pPrefix
                        + pKey + "SEQUENCE' and entity = '" + pEntity + "';";
                execNonQuery(sQuery);

                weHaveSeq = 1; // Wa have a match

            }

        }

        // Added by Jammi Dee 06/02/2012
        // If we have no match, create an entry
        if (weHaveNoPrefix == 0) {

            // Default number of characters = 6
            sQuery = "insert into Tblregistry(entity , appid, userid, varname, varvalue, regdate)"
                    + " values ('" + pEntity + "','" + pAppId + "','" + "NA" + "','" + pPrefix + pKey + "PREFIX"
                    + "','" + "" + "', NOW());";
            execNonQuery(sQuery);

        }

        if (weHaveNoChar == 0) {

            // Default number of characters = 6
            sQuery = "insert into Tblregistry(entity , appid, userid, varname, varvalue, regdate)"
                    + " values ('" + pEntity + "','" + pAppId + "','" + "NA" + "','" + pPrefix + pKey + "NOCHAR"
                    + "','" + "8" + "', NOW());";
            execNonQuery(sQuery);

        }

        if (weHaveSeq == 0) {

            // Default Counter starts at 1
            sQuery = "insert into Tblregistry(entity , appid, userid, varname, varvalue, regdate)"
                    + " values ('" + pEntity + "','" + pAppId + "','" + "NA" + "','" + pPrefix + pKey
                    + "SEQUENCE" + "','" + "1" + "', NOW());";
            execNonQuery(sQuery);

        }

    } catch (Exception e) {
        dbServices.rollback();
        return false;
    }

    return true;

}

From source file:com.waveerp.sysConnProfileFunc.java

License:Open Source License

public String updateConnProfile(String pJuid, String pDescription, String pDbEngine, String pDbUrl,
        String pDbDriver, String pDbUsername, String pDbPassword, String pStatus

) {/*from ww  w . j a  v  a2 s . c o m*/

    List<Tblconnprofile> myList = null;
    Iterator<Tblconnprofile> iterator = null;
    Tblconnprofile item = null;

    try {
        dbServices.begin();

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

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

        dbServices.commit();

        iterator = myList.iterator();

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

            item = (Tblconnprofile) iterator.next();

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

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

        //Do nothing for NULL

    } else {

        //Do the update now.  
        try {

            //item.setEntityid(       pEntityId );
            //item.setConnid(         pConnId );
            item.setDescription(pDescription);
            item.setDbengine(pDbEngine);
            item.setDburl(pDbUrl);
            item.setDbdriver(pDbDriver);
            item.setDbusername(pDbUsername);
            item.setDbpassword(pDbPassword);
            item.setSstatus(pStatus);

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

        } catch (Exception e) {

            return e.getMessage();

        }

    }

    return "OK";
}

From source file:com.waveerp.sysConnProfileFunc.java

License:Open Source License

public String getConnProfileValue(String pConn, String pField) {

    List<Tblconnprofile> myList = null;
    Iterator<Tblconnprofile> iterator = null;
    Tblconnprofile item = null;//  ww  w  . ja v a2s  .  c o m

    String strResult = "ERROR";

    try {
        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tblconnprofile where connid = '" + pConn + "' ;";

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

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

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

            item = (Tblconnprofile) iterator.next();

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

                strResult = (String) item.getDescription();

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

                strResult = (String) item.getDbengine();

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

                strResult = (String) item.getDburl();

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

                strResult = (String) item.getDbdriver();

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

                strResult = (String) item.getDbusername();

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

                strResult = (String) item.getDbpassword();

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

                strResult = (String) item.getSstatus();

            }

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    return strResult;

}

From source file:com.waveerp.systemBinary.java

License:Open Source License

public String saveAttachment(String pTicketId, String pUserid, String pEntity) {

    List<Tbltempattachment> myList = null;
    Iterator<Tbltempattachment> iterator = null;
    String result = null;/*from ww w.  j  a  v  a 2  s.  co  m*/
    String fna;
    try {

        dbServices.begin();

        Session session = dbServices.getDataServiceManager().getSession();
        String sQuery = "select * from Tbltempattachment where userid = '" + pUserid + "' and entityid = '"
                + pEntity + "';";

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

        dbServices.commit();

        iterator = myList.iterator();

        while (iterator.hasNext()) {

            Tbltempattachment attachment = (Tbltempattachment) iterator.next();

            String entity = (String) attachment.getEntityid();
            String userid = (String) attachment.getUserid();
            String filename = (String) attachment.getFilename();
            String filext = (String) attachment.getFilext();

            result = InsertAttachmentToMySql(userid, entity, pTicketId, filename, filext);
            execNonQuery("delete from tbltempattachment where " + "userid = '" + userid + "' and entityid = '"
                    + entity + "'" + " and filename = '" + filename + "';");

            fileUrl = null;
            fileUrl = this.getClass().getResource("systemBinary.class");
            fna = fileUrl.getPath();
            fna = fna.substring(0, fna.indexOf("WEB-INF"));

            fna = fna + "customdata/uploads/" + filename;
            fna = URLDecoder.decode(fna);

            File f1 = new File(fna);
            f1.delete();

        }
        return result;
    } catch (Exception e) {
        dbServices.rollback();
        return "FAIL";
    }

}

From source file:com.waveerp.systemLicense.java

License:Open Source License

public String checkEntityLicense() {

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

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

    String strConUsers = rs.readRegistryDefault("NA", "NA", "NA", "NOENTITIES",
            "1KfiXRM0OT4QBENjKVTyJo3yRnLjki3s");
    if (strConUsers.equals("")) {

        strConUsers = "1KfiXRM0OT4QBENjKVTyJo3yRnLjki3s";

    }/* w  ww  .  j  a  v  a  2s  .  c  o m*/
    if (strConUsers == null) {

        strConUsers = "1KfiXRM0OT4QBENjKVTyJo3yRnLjki3s";

    }

    String strDecrypt = "";
    strDecrypt = de.decrypt(strConUsers);
    String[] para = strDecrypt.split("\\|");
    String strConUserLicTo = para[0];
    String strConUser = para[1]; //para[0] = license to, para[1] = number of concurrent

    String strLicTo = rs.readRegistryDefault("NA", "NA", "NA", "LICENSETO", "CloudGate Lives");

    String strEnc = "";
    String result = "OK";

    if (strLicTo.equals(strConUserLicTo)) {

        result = para[1];

    } else {

        result = "5";

    }

    String strResult = "OK";
    int iCount = 0;
    int iLic = Integer.parseInt(result);

    //Load Entity Table
    List<Tblentity> myList = null;
    Iterator<Tblentity> iterator = null;
    Tblentity sess = null;

    try {

        dbServices.begin();

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

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

        myList = query.list();

        dbServices.commit();

        iterator = myList.iterator();

        while (iterator.hasNext()) {

            sess = (Tblentity) iterator.next();
            iCount++;

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    if (iCount < iLic) {
        result = "OK";
    } else {
        return "MAXENTITY";
    }

    return "OK";

}

From source file:com.waveerp.systemLicense.java

License:Open Source License

public String checkUserLicense() {

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

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

    String strConUsers = rs.readRegistryDefault("NA", "NA", "NA", "NOUSERS",
            "1KfiXRM0OT4QBENjKVTyJo3yRnLjki3s");
    if (strConUsers.equals("")) {

        strConUsers = "1KfiXRM0OT4QBENjKVTyJo3yRnLjki3s";

    }//  w  w  w  .j  av a2s.  com
    if (strConUsers == null) {

        strConUsers = "1KfiXRM0OT4QBENjKVTyJo3yRnLjki3s";

    }

    String strDecrypt = "";
    strDecrypt = de.decrypt(strConUsers);
    String[] para = strDecrypt.split("\\|");
    String strConUserLicTo = para[0];
    String strConUser = para[1]; //para[0] = license to, para[1] = number of concurrent

    String strLicTo = rs.readRegistryDefault("NA", "NA", "NA", "LICENSETO", "CloudGate Lives");

    String strEnc = "";
    String result = "OK";

    if (strLicTo.equals(strConUserLicTo)) {

        result = para[1];

    } else {

        result = "5";

    }

    String strResult = "OK";
    int iCount = 0;
    int iLic = Integer.parseInt(result);

    //Load Entity Table
    List<Tbluser> myList = null;
    Iterator<Tbluser> iterator = null;
    Tbluser sess = null;

    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();

        while (iterator.hasNext()) {

            sess = (Tbluser) iterator.next();
            iCount++;

        }

    } catch (Exception e) {

        dbServices.rollback();
        return "FAIL";

    }

    if (iCount < iLic) {
        result = "OK";
    } else {
        return "MAXUSER";
    }

    return "OK";

}