本文整理汇总了Java中org.hibernate.StatelessSession.update方法的典型用法代码示例。如果您正苦于以下问题:Java StatelessSession.update方法的具体用法?Java StatelessSession.update怎么用?Java StatelessSession.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.StatelessSession
的用法示例。
在下文中一共展示了StatelessSession.update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRefresh
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void testRefresh() {
StatelessSession ss = getSessions().openStatelessSession();
Transaction tx = ss.beginTransaction();
Paper paper = new Paper();
paper.setColor( "whtie" );
ss.insert( paper );
tx.commit();
ss.close();
ss = getSessions().openStatelessSession();
tx = ss.beginTransaction();
Paper p2 = ( Paper ) ss.get( Paper.class, paper.getId() );
p2.setColor( "White" );
ss.update( p2 );
tx.commit();
ss.close();
ss = getSessions().openStatelessSession();
tx = ss.beginTransaction();
assertEquals( "whtie", paper.getColor() );
ss.refresh( paper );
assertEquals( "White", paper.getColor() );
ss.delete( paper );
tx.commit();
ss.close();
}
示例2: aumentarStatelessSession
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
@Path("/stateless")
public void aumentarStatelessSession(){
long antes = System.currentTimeMillis();
StatelessSession statelessSession = factory.openStatelessSession();
ScrollableResults results = statelessSession.createCriteria(Transacao.class).setFetchSize(QTD_REGISTROS).scroll();
Transaction transaction = statelessSession.beginTransaction();
while(results.next()) {
Transacao transacao = (Transacao) results.get()[0];
transacao.setValor(transacao.getValor().multiply(new BigDecimal("1.1")));
statelessSession.update(transacao);
}
transaction.commit();
long tempo = System.currentTimeMillis()-antes;
System.out.printf("Tempo gasto %dms%n", tempo);
result.include("mensagem", "Atualizacao realizada com sucesso (" + tempo + "ms)");
result.forwardTo(IndexController.class).index();
}
示例3: executeWriteIfExists
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void executeWriteIfExists(StatelessSession session, BulkItem bulkItem) {
Object entry = bulkItem.getItem();
if (exists(bulkItem, session)) {
if (logger.isTraceEnabled()) {
logger.trace("[Exists WRITE] Update Entry [" + entry + "]");
}
session.update(entry);
} else {
if (logger.isTraceEnabled()) {
logger.trace("[Exists WRITE] Insert Entry [" + entry + "]");
}
session.insert(entry);
}
}
示例4: executeUpdateIfExists
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void executeUpdateIfExists(StatelessSession session, BulkItem bulkItem) {
Object entry = bulkItem.getItem();
if (exists(bulkItem, session)) {
if (logger.isTraceEnabled()) {
logger.trace("[Exists UPDATE] Update Entry [" + entry + "]");
}
session.update(entry);
} else {
if (logger.isTraceEnabled()) {
logger.trace("[Exists UPDATE] Insert Entry [" + entry + "]");
}
session.insert(entry);
}
}
示例5: executeUpdate
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void executeUpdate(StatelessSession session, BulkItem bulkItem) {
Object entry = bulkItem.getItem();
if (logger.isTraceEnabled()) {
logger.trace("[Optimistic UPDATE] Update Entry [" + entry + "]");
}
session.update(entry);
}
示例6: testCreateUpdateReadDelete
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void testCreateUpdateReadDelete() {
StatelessSession ss = getSessions().openStatelessSession();
Transaction tx = ss.beginTransaction();
Document doc = new Document("blah blah blah", "Blahs");
ss.insert(doc);
assertNotNull( doc.getName() );
Date initVersion = doc.getLastModified();
assertNotNull( initVersion );
tx.commit();
tx = ss.beginTransaction();
doc.setText("blah blah blah .... blah");
ss.update(doc);
assertNotNull( doc.getLastModified() );
assertNotSame( doc.getLastModified(), initVersion );
tx.commit();
tx = ss.beginTransaction();
doc.setText("blah blah blah .... blah blay");
ss.update(doc);
tx.commit();
Document doc2 = (Document) ss.get(Document.class.getName(), "Blahs");
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
doc2 = (Document) ss.createQuery("from Document where text is not null").uniqueResult();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
ScrollableResults sr = ss.createQuery("from Document where text is not null")
.scroll(ScrollMode.FORWARD_ONLY);
sr.next();
doc2 = (Document) sr.get(0);
sr.close();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
doc2 = (Document) ss.createSQLQuery("select * from Document")
.addEntity(Document.class)
.uniqueResult();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
doc2 = (Document) ss.createCriteria(Document.class).uniqueResult();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
sr = ss.createCriteria(Document.class).scroll(ScrollMode.FORWARD_ONLY);
sr.next();
doc2 = (Document) sr.get(0);
sr.close();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
tx = ss.beginTransaction();
ss.delete(doc);
tx.commit();
ss.close();
}
示例7: onPreUpdate
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
@SuppressWarnings("resource")
@Override
public boolean onPreUpdate(final PreUpdateEvent event)
{
if (log.isDebugEnabled())
{
log.debug("Received pre-update event");
}
final EntityPersister entityPersister = event.getPersister();
final EntityMode entityMode = entityPersister.guessEntityMode(event.getEntity());
final Connection connection = getConnection(entityPersister);
final StatelessSession session = entityPersister
.getFactory()
.openStatelessSession(connection);
session.beginTransaction();
final Serializable entityId = entityPersister.getIdentifier(event.getEntity(),
(SessionImplementor)session);
final Object existingEntity = session.get(event.getEntity().getClass(), entityId);
if (log.isDebugEnabled())
{
log.debug("Loaded existing entity " + existingEntity);
}
boolean updatedExistingEntity = false;
for (int i = 0; i < entityPersister.getPropertyNames().length; i++)
{
final Object oldPropValue = entityPersister.getPropertyValue(existingEntity,
i, entityMode);
if (oldPropValue == null)
{
if (log.isDebugEnabled())
{
log.debug("Found a property in the existing "
+ "entity that was null, checking new entity");
}
final Object newPropValue = entityPersister.getPropertyValue(
event.getEntity(), i, entityMode);
if (!(newPropValue instanceof Collection<?>) && newPropValue != null)
{
if (log.isDebugEnabled())
{
log.debug("The new entity contains a non-null "
+ "value, updating existing entity");
}
entityPersister.setPropertyValue(existingEntity, i, newPropValue,
entityMode);
updatedExistingEntity = true;
}
}
}
if (updatedExistingEntity)
{
entityPersister.getFactory().getCurrentSession().cancelQuery();
session.update(existingEntity);
}
session.getTransaction().commit();
session.close();
return updatedExistingEntity;
}