Example usage for org.hibernate Session load

List of usage examples for org.hibernate Session load

Introduction

In this page you can find the example usage for org.hibernate Session load.

Prototype

void load(Object object, Serializable id);

Source Link

Document

Read the persistent state associated with the given identifier into the given transient instance.

Usage

From source file:com.izv.modelo.ModeloInmueble.java

public static void delete(String id) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from   w w w .ja v  a 2s  . c om

    Inmueble inm = (Inmueble) session.load(Inmueble.class, Integer.parseInt(id));
    session.delete(inm);

    session.getTransaction().commit();
    session.flush();
    session.close();
}

From source file:com.jdon.persistence.hibernate.HibernateTemplate.java

License:Apache License

public void load(final Object entity, final Serializable id) throws Exception {
    doHibernate(new HibernateCallback() {
        public Object execute(Session session) throws HibernateException {
            session.load(entity, id);
            return null;
        }//from   w  w  w. j a va2  s  .  c o  m
    });
}

From source file:com.jklas.search.templates.hibernate.HibernatePluginTemplate.java

License:Open Source License

public Collection<?> hydrateAll(Session session, Collection<? extends ObjectResult> results) {

    ArrayList<Object> returnValues = new ArrayList<Object>(results.size());

    for (ObjectResult objectResult : results) {
        Object loaded = session.load(objectResult.getKey().getClazz(), objectResult.getKey().getId());
        returnValues.add(loaded);//  w  w w .j a v  a  2 s. c  o m
    }

    return returnValues;
}

From source file:com.jklas.search.templates.hibernate.HibernatePluginTemplate.java

License:Open Source License

public <T> Collection<T> hydrateAll(Session session, Collection<? extends ObjectResult> results,
        Class<T> desiredClass) {

    ArrayList<T> returnValues = new ArrayList<T>(results.size());

    for (ObjectResult objectResult : results) {
        Object loaded = session.load(objectResult.getKey().getClazz(), objectResult.getKey().getId());

        if (!desiredClass.isAssignableFrom(loaded.getClass()))
            continue;
        else {//from   w ww .  java 2 s  . co  m
            @SuppressWarnings("unchecked")
            T t = (T) loaded;
            returnValues.add(t);
        }
    }

    return returnValues;
}

From source file:com.kg.testjsfa8h4.dao.Form1Dao.java

public void deleteForm1(int idForm1) {
    Transaction trns = null;//  w  ww  . j  a v  a  2 s  . c om
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Form1 form1 = (Form1) session.load(Form1.class, new Integer(idForm1));
        session.delete(form1);
        session.getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.kg.testjsfa8h4.dao.Form1Dao.java

public void updateForm1(int idForm1, Form1 form1) {
    Transaction trns = null;//  w  w w .ja va 2 s.co  m
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        Form1 oldForm1 = (Form1) session.load(Form1.class, new Integer(idForm1));
        oldForm1.setAddress(form1.getAddress());
        oldForm1.setCertificateDate(form1.getCertificateDate());
        oldForm1.setCertificateNumber(form1.getCertificateNumber());
        oldForm1.setFax(form1.getFax());
        oldForm1.setFioHead(form1.getFioHead());
        oldForm1.setIdEmployesList(form1.getIdEmployesList());
        oldForm1.setIdFiles(form1.getIdFiles());
        oldForm1.setLegalForm(form1.getLegalForm());
        oldForm1.setOwnType(form1.getOwnType());
        oldForm1.setLicenseDate(form1.getLicenseDate());
        oldForm1.setLicenseNumber(form1.getLicenseNumber());
        oldForm1.setOrgName(form1.getOrgName());
        oldForm1.setPhone(form1.getPhone());
        oldForm1.setWebPage(form1.getWebPage());
        session.update(oldForm1);
        trns.commit();
    } catch (Exception e) {
        e.printStackTrace();
        if (trns != null) {
            trns.rollback();
        }
    } finally {
        session.flush();
        session.close();
    }
}

From source file:com.knowbout.epg.processor.ScheduleParser.java

License:Apache License

private void createSchedule(ChannelSchedule channel, List<NetworkLineup> lineups, boolean localHeadend) {
    Session session = HibernateUtil.currentSession();
    Program program = (Program) session.load(Program.class, channel.getProgramId());
    //Update program rating and runtime. Overloading this information
    Network network = Network.findByCallSign(channel.getStation().getCallSign());
    String tvRating = null;/*  www .  j  a  v a 2s. c o m*/
    int duration = 0;
    Collection<ScheduleAiring> airings;
    if (localHeadend) {
        airings = new ArrayList<ScheduleAiring>();
        airings.addAll(channel.getPacificAirings().values());
        airings.addAll(channel.getSingleStationAirings());
    } else {
        airings = channel.getValidAirings();
    }
    for (ScheduleAiring airing : airings) {
        String rawData = airing.getInputText();
        Schedule schedule = parseSchedule(airing, program, rawData);
        schedule.setNetwork(network);
        HashMap<Date, Schedule> dates = new HashMap<Date, Schedule>();
        for (NetworkLineup lineup : lineups) {
            Date airTime = null;
            //We only modify the time if there are multiple stations (TLC and TLCP)   if
            //It is like ESPN which only has a single feed, east and west coast get the same
            //exact content at the same time (GMT based), just at different local time because of the timezone
            if (channel.getStation().isOnMultipleHeadends()) {
                if (channel.getStation().isAffilateStation()) {
                    airTime = lineup.applyAffiliationDelay(schedule.getAirTime());
                } else {
                    airTime = lineup.applyDelay(schedule.getAirTime());
                }
            }
            Schedule existingSchedule = dates.get(airTime);
            if (existingSchedule != null) {
                NetworkSchedule ns = new NetworkSchedule(existingSchedule, lineup,
                        existingSchedule.getAirTime());
                ns.insert();
            } else {
                if (tvRating == null) {
                    tvRating = schedule.getTvRating();
                    duration = schedule.getDuration();
                }
                existingSchedule = insertSchedule(channel, schedule, lineup);
                if (existingSchedule != null) {
                    existingSchedule.insert();
                    NetworkSchedule ns = new NetworkSchedule(existingSchedule, lineup,
                            existingSchedule.getAirTime());
                    ns.insert();
                    dates.put(airTime, existingSchedule);
                }
            }
        }
    }
    //Since the program does not have this information on it, add it to the override the movie
    //specific values with TV values.
    program.setMpaaRating(tvRating);
    program.setRunTime(duration);
}

From source file:com.krawler.customFieldMaster.fieldManager.java

License:Open Source License

public String currencyRender(String currency, Session session, HttpServletRequest request)
        throws SessionExpiredException {
    if (!StringUtil.isNullOrEmpty(currency)) {
        KWLCurrency cur = (KWLCurrency) session.load(KWLCurrency.class, AuthHandler.getCurrencyID(request));
        String symbol = cur.getHtmlcode();
        char temp = (char) Integer.parseInt(symbol, 16);
        symbol = Character.toString(temp);
        float v = 0;
        DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
        if (currency.equals("")) {
            return symbol;
        }/*ww w .ja  v  a  2s  .com*/
        v = Float.parseFloat(currency);
        String fmt = decimalFormat.format(v);
        fmt = symbol + " " + fmt;
        return fmt;
    } else {
        return "";
    }
}

From source file:com.krawler.customFieldMaster.fieldManager.java

License:Open Source License

public String preferenceDate(Session session, HttpServletRequest request, Date date, int timeflag)
        throws SessionExpiredException {
    KWLDateFormat dateFormat = (KWLDateFormat) session.load(KWLDateFormat.class,
            AuthHandler.getDateFormatID(request));
    String prefDate = "";
    if (timeflag == 0) {// 0 - No time only Date
        int spPoint = dateFormat.getJavaSeperatorPosition();
        prefDate = dateFormat.getJavaForm().substring(0, spPoint);
    } else // DateTime
    {/*from ww w .  j a  va2s  .c  o  m*/
        prefDate = dateFormat.getJavaForm();
    }
    String result = "";
    if (date != null) {
        result = AuthHandler.getPrefDateFormatter(request, prefDate).format(date);
    } else {
        return result;
    }
    return result;
}

From source file:com.krawler.esp.handlers.APICallHandler.java

License:Open Source License

public static JSONObject callApp(String appURL, JSONObject jData, String companyid, String action) {
    JSONObject resObj = new JSONObject();
    boolean result = false;
    Session session = null;
    Transaction tx = null;// w  ww.ja v a  2s .  c  o  m
    try {
        session = HibernateUtil.getCurrentSession();
        tx = session.beginTransaction();
        PreparedStatement pstmt = null;
        String uid = UUID.randomUUID().toString();
        Apiresponse apires = new Apiresponse();
        apires.setApiid(uid);
        apires.setCompanyid((Company) session.get(Company.class, companyid));
        apires.setApirequest("action=" + action + "&data=" + jData.toString());
        apires.setStatus(0);
        session.save(apires);

        String res = "{}";
        InputStream iStream = null;
        try {
            String strSandbox = appURL + apistr;
            URL u = new URL(strSandbox);
            URLConnection uc = u.openConnection();
            uc.setDoOutput(true);
            uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            java.io.PrintWriter pw = new java.io.PrintWriter(uc.getOutputStream());
            pw.println("action=" + action + "&data=" + jData.toString());
            pw.close();
            iStream = uc.getInputStream();
            java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(iStream));
            res = in.readLine();
            in.close();
            iStream.close();
        } catch (IOException iex) {
            Logger.getLogger(APICallHandler.class.getName()).log(Level.SEVERE, "IO Exception In API Call", iex);
        } finally {
            if (iStream != null) {
                try {
                    iStream.close();
                } catch (Exception e) {
                }
            }
        }
        resObj = new JSONObject(res);

        if (!resObj.isNull("success") && resObj.getBoolean("success")) {
            result = true;

        } else {
            result = false;
        }

        apires = (Apiresponse) session.load(Apiresponse.class, uid);
        apires.setApiresponse(res);
        apires.setStatus(1);
        session.save(apires);
        tx.commit();
    } catch (JSONException ex) {
        if (tx != null) {
            tx.rollback();
        }
        Logger.getLogger(APICallHandler.class.getName()).log(Level.SEVERE, "JSON Exception In API Call", ex);
        result = false;

    } catch (Exception ex) {
        if (tx != null) {
            tx.rollback();
        }
        Logger.getLogger(APICallHandler.class.getName()).log(Level.SEVERE, "Exception In API Call", ex);
        result = false;
    } finally {
        HibernateUtil.closeSession(session);
    }
    return resObj;
}