Accessing and modifying openoffice base databases from Java

I made a little tool that makes it real easy to access and modify openoffice databases from Java, without having to open oo-base.

Here's a code snippet from the unit test:

OpenOfficeBaseJPA instance = new OpenOfficeBaseJPA(new File("testdb/TestDatabase.odb"));
EntityManager em = instance.createEntityManager();
Integer rowcount = (Integer) em.createNativeQuery(
"select count(*) from \"PUBLIC\".\"TestTable\"")
.getSingleResult();
em.getTransaction().begin();
em.createNativeQuery(
"insert into \"PUBLIC\".\"TestTable\" (\"TestField\") values ('Testvalue')")
.executeUpdate();
em.getTransaction().commit();

Integer rowcount2 = (Integer) em.createNativeQuery(
"select count(*) from \"PUBLIC\".\"TestTable\"")
  .getSingleResult();
assertTrue(rowcount+1==rowcount2);
em.close();

instance.saveChanges();
Thread.sleep(10);
instance = new OpenOfficeBaseJPA(new File("testdb/TestDatabase.odb"));
em = instance.createEntityManager();
Integer rowcount3 = (Integer) em.createNativeQuery(
"select count(*) from \"PUBLIC\".\"TestTable\"")
.getSingleResult();
assertEquals(rowcount2,rowcount3);

Here's the SVN repository:
https://petrus.svn.sourceforge.net/svnroot/petrus/tools/OpenOfficeBaseJPA/

Comments

Popular posts from this blog

My VNC based development environment with Visual Studio Code running on Ubuntu

Create PDF's in Angular / Typescript

Intercepting and adjusting SQL generated by Eclipselink JPA