本文整理汇总了Java中org.hibernate.StatelessSession.insert方法的典型用法代码示例。如果您正苦于以下问题:Java StatelessSession.insert方法的具体用法?Java StatelessSession.insert怎么用?Java StatelessSession.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.StatelessSession
的用法示例。
在下文中一共展示了StatelessSession.insert方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHistory
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void createHistory(EntityPersister persister, Object entity,
ModificationType type) {
if (entity instanceof DomainObject<?>) {
DomainObject<?> obj = (DomainObject<?>) entity;
if (obj.hasHistory()) {
final DomainHistoryObject<?> hist = HistoryObjectFactory.create(
obj, type, DataServiceBean.getCurrentHistoryUser());
final StatelessSession session = persister.getFactory()
.openStatelessSession();
Transaction tx = session.beginTransaction();
session.insert(hist);
tx.commit();
session.close();
if (logger.isDebugLoggingEnabled()) {
logger.logDebug(String.format("%s %s[%s, v=%s]", type,
obj.getClass().getSimpleName(), obj.getKey(),
hist.getObjVersion()));
}
}
}
}
示例2: createHistory
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void createHistory(EntityPersister persister, Object entity,
ModificationType type) {
if (entity instanceof DomainObject<?>) {
DomainObject<?> obj = (DomainObject<?>) entity;
if (obj.hasHistory()) {
final DomainHistoryObject<?> hist = HistoryObjectFactory
.create(obj, type,
DataServiceBean.getCurrentHistoryUser());
final StatelessSession session = persister.getFactory()
.openStatelessSession();
Transaction tx = session.beginTransaction();
session.insert(hist);
tx.commit();
session.close();
if (logger.isDebugLoggingEnabled()) {
logger.logDebug(String.format("%s %s[%s, v=%s]", type, obj
.getClass().getSimpleName(), Long.valueOf(obj
.getKey()), Long.valueOf(hist.getObjVersion())));
}
}
}
}
示例3: 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();
}
示例4: gerar
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
@Path("/gerarTransacoes")
public void gerar() throws IOException {
StatelessSession session = sessionFactory.openStatelessSession();
Random random = new Random();
Transaction transaction = session.beginTransaction();
for (int i = 0; i < 1000000; i++) {
System.out.println("Adicionando transacao " + i);
Transacao transacao = new Transacao();
transacao.setTipoDeTransacao(Tipo.values()[random.nextInt(2)]);
transacao.setData(new GregorianCalendar(random.nextInt(6) + 2006,
random.nextInt(12), random.nextInt(29)));
transacao.setValor(new BigDecimal(random.nextDouble() * 10000));
session.insert(transacao);
}
transaction.commit();
}
示例5: main
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public static void main(String[] args) {
final SessionFactory sessionFactory = JavaHibernateUtil.getSessionFactory();
final StatelessSession session = sessionFactory.openStatelessSession();
final Transaction transaction = session.getTransaction();
transaction.begin();
final User user = new User();
user.setUsername("Stateless Session creation");
session.insert(user);
transaction.commit();
// session.close();
sessionFactory.close();
}
示例6: testStatelessBPCreate
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
@Test
public void testStatelessBPCreate() {
try {
setTestAdminContext();
final StatelessSession session = SessionFactoryController.getInstance().getSessionFactory()
.openStatelessSession();
session.beginTransaction();
for (int i = 0; i < CNT; i++) {
BusinessPartner bp = OBProvider.getInstance().get(BusinessPartner.class);
// Generating random strings for testing
UUID name = UUID.randomUUID();
UUID key = UUID.randomUUID();
bp.setName(name.toString());
bp.setSearchKey(key.toString());
bp.setBusinessPartnerCategory(createReferencedObject(Category.class, TEST_BP_CATEGORY_ID));
// note the following things are currently done in the OBInterceptor
// it is quite easy to add a util method which can do this in a generic
// way for any business object
bp.setOrganization(createReferencedObject(Organization.class, TEST_ORG_ID));
bp.setClient(createReferencedObject(Client.class, TEST_CLIENT_ID));
bp.setCreatedBy(createReferencedObject(User.class, "100"));
bp.setCreationDate(new Date());
bp.setUpdatedBy(createReferencedObject(User.class, "100"));
bp.setUpdated(new Date());
session.insert(BusinessPartner.ENTITY_NAME, bp);
// session.refresh(BusinessPartner.ENTITY_NAME, bp);
Assert.assertTrue(bp.getId() != null);
}
session.getTransaction().commit();
} catch (Exception e) {
throw new OBException(e);
}
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: executeWrite
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
private void executeWrite(StatelessSession session, BulkItem bulkItem) {
Object entry = bulkItem.getItem();
if (logger.isTraceEnabled()) {
logger.trace("[Optimistic WRITE] Write Entry [" + entry + "]");
}
session.insert(entry);
}
示例10: testHqlBulk
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void testHqlBulk() {
StatelessSession ss = getSessions().openStatelessSession();
Transaction tx = ss.beginTransaction();
Document doc = new Document("blah blah blah", "Blahs");
ss.insert(doc);
Paper paper = new Paper();
paper.setColor( "White" );
ss.insert(paper);
tx.commit();
tx = ss.beginTransaction();
int count = ss.createQuery( "update Document set name = :newName where name = :oldName" )
.setString( "newName", "Foos" )
.setString( "oldName", "Blahs" )
.executeUpdate();
assertEquals( "hql-update on stateless session", 1, count );
count = ss.createQuery( "update Paper set color = :newColor" )
.setString( "newColor", "Goldenrod" )
.executeUpdate();
assertEquals( "hql-update on stateless session", 1, count );
tx.commit();
tx = ss.beginTransaction();
count = ss.createQuery( "delete Document" ).executeUpdate();
assertEquals( "hql-delete on stateless session", 1, count );
count = ss.createQuery( "delete Paper" ).executeUpdate();
assertEquals( "hql-delete on stateless session", 1, count );
tx.commit();
ss.close();
}
示例11: testInitId
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void testInitId() {
StatelessSession ss = getSessions().openStatelessSession();
Transaction tx = ss.beginTransaction();
Paper paper = new Paper();
paper.setColor( "White" );
ss.insert(paper);
assertNotNull( paper.getId() );
tx.commit();
tx = ss.beginTransaction();
ss.delete( ss.get( Paper.class, paper.getId() ) );
tx.commit();
ss.close();
}
示例12: saveInventory
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void saveInventory() throws HibernateException, IOException{
File inventoryFile = new File("ghcnm.inv");
BufferedReader br = new BufferedReader(new FileReader(inventoryFile));
String line;
org.hibernate.Session session =
(org.hibernate.Session)GeoInventory.em().getDelegate();
StatelessSession stateless = session.getSessionFactory().openStatelessSession();
try {
stateless.connection().setAutoCommit(false);
} catch (SQLException e) {
e.printStackTrace();
}
org.hibernate.Transaction tx = stateless.beginTransaction();
int counter=0;
while ((line = br.readLine()) != null) {
counter++;
GeoInventory inv = new GeoInventory(line);
stateless.insert(inv);
if(counter%1000==0){
tx.commit();
tx = stateless.beginTransaction();
Logger.info("Data Saved: %s", counter);
}
}
tx.commit();
br.close();
stateless.close();
session.clear();
Logger.info("Geoloc Inventory save complete!");
}
示例13: 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();
}
示例14: saveData
import org.hibernate.StatelessSession; //导入方法依赖的package包/类
public void saveData() throws HibernateException, IOException{
File temperatureFile = new File("ghcnm.dat");
BufferedReader br2 = new BufferedReader(new FileReader(temperatureFile));
int counter = 0;
String line;
org.hibernate.Session session =
(org.hibernate.Session)GeoTempData.em().getDelegate();
StatelessSession stateless = session.getSessionFactory().openStatelessSession();
try {
stateless.connection().setAutoCommit(false);
} catch (SQLException e) {
e.printStackTrace();
}
org.hibernate.Transaction tx = stateless.beginTransaction();
counter=0;
int skipCounter = 1;
while ((line = br2.readLine()) != null) {
counter++;
GeoTempData data = new GeoTempData(line);
if(data.temp1!=-99.99
&&data.temp2!=-99.99
&&data.temp3!=-99.99
&&data.temp4!=-99.99
&&data.temp5!=-99.99
&&data.temp6!=-99.99
&&data.temp7!=-99.99
&&data.temp8!=-99.99
&&data.temp9!=-99.99
&&data.temp10!=-99.99
&&data.temp11!=-99.99
&&data.temp12!=-99.99
)
{
stateless.insert(data);
}else
skipCounter++;
if(counter%1000==0){
tx.commit();
tx = stateless.beginTransaction();
Logger.info("Data Saved: %s", counter);
}
}
br2.close();
stateless.close();
session.clear();
GeoTempData.em().flush();
GeoTempData.em().clear();
Logger.info("Geoloc Data save complete! skipCount=%s",skipCounter);
}