List of usage examples for org.hibernate Session persist
void persist(Object object);
From source file:OpenRate.customerinterface.webservices.AliasFacade.java
License:Open Source License
public void updateAlias(Session session, Alias alias, int NewEndDate) { alias.setEndDate(NewEndDate);//from www .ja va2 s .c om alias.setModT(Calendar.getInstance().getTimeInMillis()); session.saveOrUpdate(alias); session.persist(alias); }
From source file:OpenRate.customerinterface.webservices.ERAFacade.java
License:Open Source License
public void saveERA(Session session, ERA eRA) { eRA.setModT(Calendar.getInstance().getTimeInMillis()); session.save(eRA); session.persist(eRA); }
From source file:OpenRate.customerinterface.webservices.ERAFacade.java
License:Open Source License
public void updateERA(Session session, ERA eRA, String ERAName, String ERAValue) { eRA.setERAKey(ERAName);/*from w ww. j a v a 2s. c o m*/ eRA.setERAValue(ERAValue); eRA.setModT(Calendar.getInstance().getTimeInMillis()); session.saveOrUpdate(eRA); session.persist(eRA); }
From source file:OpenRate.customerinterface.webservices.ProductFacade.java
License:Open Source License
public void saveProduct(Session session, Product product) { product.setModT(Calendar.getInstance().getTimeInMillis()); session.save(product);/*w ww . ja v a2 s .co m*/ session.persist(product); }
From source file:OpenRate.customerinterface.webservices.ProductFacade.java
License:Open Source License
public void updateProduct(Session session, Product product, int endDate) { product.setEndDate(endDate);//w w w. j a v a 2 s . c o m product.setModT(Calendar.getInstance().getTimeInMillis()); session.saveOrUpdate(product); session.persist(product); }
From source file:org.apache.camel.component.hibernate.HibernateProducer.java
License:Apache License
public void process(Exchange exchange) { final Object values = expression.evaluate(exchange, Object.class); if (values != null) { template.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Iterator iter = ObjectConverter.iterator(values); while (iter.hasNext()) { Object value = iter.next(); session.persist(value); }/*from www . j a v a2 s. c om*/ if (endpoint.isFlushOnSend()) { session.flush(); } return null; } }); } exchange.setProperty("CamelHibernateValue", values); }
From source file:org.apacheextras.camel.component.hibernate.HibernateProducer.java
License:Open Source License
@Override public void process(Exchange exchange) { final Object values = expression.evaluate(exchange, Object.class); if (values != null) { template.execute(new TransactionCallback<Object>() { public Object doInTransaction(Session session) { Iterator iter = ObjectConverter.iterator(values); while (iter.hasNext()) { Object value = iter.next(); session.persist(value); }/*from ww w .j a v a 2 s . c om*/ if (endpoint.isFlushOnSend()) { session.flush(); } return null; } }); } exchange.setProperty("CamelHibernateValue", values); }
From source file:org.apereo.portal.events.handlers.db.JpaPortalEventStore.java
License:Apache License
@Override @RawEventsTransactional//from w w w .j av a 2s .c o m public boolean aggregatePortalEvents(DateTime startTime, DateTime endTime, int maxEvents, Function<PortalEvent, Boolean> handler) { final Session session = this.getEntityManager().unwrap(Session.class); session.setFlushMode(FlushMode.COMMIT); final org.hibernate.Query query = session.createQuery(this.selectUnaggregatedQuery); query.setParameter(this.startTimeParameter.getName(), startTime); query.setParameter(this.endTimeParameter.getName(), endTime); if (maxEvents > 0) { query.setMaxResults(maxEvents); } int resultCount = 0; for (final ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY); results.next();) { final PersistentPortalEvent persistentPortalEvent = (PersistentPortalEvent) results.get(0); final PortalEvent portalEvent; try { portalEvent = this.toPortalEvent(persistentPortalEvent.getEventData(), persistentPortalEvent.getEventType()); } catch (RuntimeException e) { this.logger.warn("Failed to convert PersistentPortalEvent to PortalEvent: " + persistentPortalEvent, e); //Mark the event as error and store the mark to prevent trying to reprocess the broken event data persistentPortalEvent.setErrorAggregating(true); session.persist(persistentPortalEvent); continue; } try { final Boolean eventHandled = handler.apply(portalEvent); if (!eventHandled) { this.logger.debug("Aggregation stop requested before processing event {}", portalEvent); return false; } //Mark the event as aggregated and store the mark persistentPortalEvent.setAggregated(true); session.persist(persistentPortalEvent); //periodic flush and clear of session to manage memory demands if (++resultCount % this.flushPeriod == 0) { this.logger.debug("Aggregated {} events, flush and clear {} EntityManager.", resultCount, PERSISTENCE_UNIT_NAME); session.flush(); session.clear(); } } catch (Exception e) { this.logger.warn("Failed to aggregate portal event: " + persistentPortalEvent, e); //mark the event as erred and move on. This will not be picked up by processing again persistentPortalEvent.setErrorAggregating(true); session.persist(persistentPortalEvent); } } return true; }
From source file:org.babyfish.hibernate.fetch.DistinctLimitHQLTest.java
License:Open Source License
@SuppressWarnings("deprecation") @BeforeClass//w w w .ja va 2 s. c o m public static void initSessionFactory() { sessionFactory = new Configuration().configure(RESOURCE).addProperties(getOracleProperites()) .addAnnotatedClass(Department.class).addAnnotatedClass(Employee.class) .addAnnotatedClass(AnnualLeave.class).buildSessionFactory(); Session session = sessionFactory.openSession(); try { Transaction tx = session.beginTransaction(); try { Department market = new Department(); Department development = new Department(); Department sales = new Department(); Department hr = new Department(); Employee jim = new Employee(); Employee kate = new Employee(); Employee tom = new Employee(); Employee linda = new Employee(); Employee sam = new Employee(); Employee alice = new Employee(); Employee adam = new Employee(); Employee sharon = new Employee(); market.setName("market"); development.setName("development"); sales.setName("sales"); hr.setName("hr"); jim.setName(new Name("jim", "cotton")); kate.setName(new Name("kate", "hill")); tom.setName(new Name("tom", "george")); linda.setName(new Name("linda", "sharp")); sam.setName(new Name("Sam", "Carter")); alice.setName(new Name("alice", "london")); adam.setName(new Name("adam", "brook")); sharon.setName(new Name("sharon", "fox")); market.getEmployees().add(jim); market.getEmployees().add(kate); development.getEmployees().add(tom); development.getEmployees().add(linda); sales.getEmployees().add(sam); sales.getEmployees().add(alice); hr.getEmployees().add(adam); hr.getEmployees().add(sharon); session.persist(market); session.persist(development); session.persist(sales); session.persist(hr); session.persist(jim); session.persist(kate); session.persist(tom); session.persist(linda); session.persist(sam); session.persist(alice); session.persist(adam); session.persist(sharon); } catch (RuntimeException ex) { tx.rollback(); throw ex; } catch (Error err) { tx.rollback(); throw err; } tx.commit(); } finally { session.close(); } }
From source file:org.blanco.gae.blog.BlogServlet.java
License:Open Source License
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //Parse the input form Entry entry = new Entry(); entry.setAuthor(req.getParameter("author")); entry.setEntry(req.getParameter("entry")); entry.setDate(new Date(System.currentTimeMillis())); //store the entry Session session = (Session) ctx.getBean("session"); session.persist(entry); session.flush();/*www.java 2 s . c o m*/ session.close(); req.setAttribute("entry", entry); //forward to presentation req.getRequestDispatcher("entry_created.jsp").forward(req, resp); }