ddl, account.sql is copied after generation to src/main/resources/db/mysql using
maven-ant-run plugin. changed AccountTest to use JPQ update and delete statements instead
of find, update/delete, persist sequence
test: account.jaxb mvn test
M jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java
M jaxb/src/main/resources/accounts_common.xsd
A jaxb/src/main/resources/db/mysql/account.sql
M jaxb/pom.xml
<artifactId>org.collectionspace.services.account.jaxb</artifactId>
<version>1.0</version>
<name>services.account.jaxb</name>
-
+ <properties>
+ <sql.file>account.sql</sql.file>
+ <sql.dir>src/main/resources/db/mysql</sql.dir>
+ </properties>
<dependencies>
<!-- keep slf4j dependencies on the top -->
<dependency>
<id>ddl</id>
<build>
<plugins>
- <!--plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
</component>
</components>
<componentProperties>
- <outputfilename>${basedir}/src/main/resources/db/mysql/account.sql</outputfilename>
+ <outputfilename>${sql.file}</outputfilename>
<implementation>jpaconfiguration</implementation>
<drop>true</drop>
<create>true</create>
<version>5.0.5</version>
</dependency>
</dependencies>
- </plugin-->
+ </plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
- <id>process-classes</id>
- <phase>process-test-resources</phase>
+ <phase>process-test-classes</phase>
<configuration>
<tasks>
- <property name="export" value="false"/>
- <property name="test_classpath" refid="maven.test.classpath"/>
- <property name="compile_classpath" refid="maven.compile.classpath"/>
- <property name="runtime_classpath" refid="maven.runtime.classpath"/>
- <property name="plugin_classpath" refid="maven.plugin.classpath"/>
- <taskdef name="hibernatetool"
- classname="org.hibernate.tool.ant.HibernateToolTask"/>
- <hibernatetool destdir="{basedir}/src/main/resources/db/mysql">
- <hbm2ddl drop="true"
- create="true"
- export="${export}"
- outputfilename="${basedir}/src/main/resources/db/mysql/account.sql"
- delimiter=";" format="true"/>
- <configuration configurationfile="${basedir}/src/test/resources/hibernate.cfg.xml"/>
- </hibernatetool>
+ <copy file="target/hibernate3/sql/${sql.file}" tofile="${sql.dir}/${sql.file}"/>
</tasks>
</configuration>
<goals>
</goals>
</execution>
</executions>
- <dependencies>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-tools</artifactId>
- <version>3.2.3.GA</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate</artifactId>
- <version>3.4.0.GA</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>3.4.0.GA</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.5.2</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.5.2</version>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1</version>
- </dependency>
- </dependencies>
</plugin>
</plugins>
<xs:element name="accounts_common">
<xs:complexType>
<xs:sequence>
- <xs:element name="csid" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="anchorName" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="firstName" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="lastName" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="phone" type="xs:string"/>
</xs:sequence>
+ <xs:attribute name="csid" type="xs:string">
+ <xs:annotation>
+ <xs:appinfo>
+ <hj:id />
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:attribute>
</xs:complexType>
</xs:element>
--- /dev/null
+alter table ACCOUNTLISTITEM drop foreign key FKBD8755BE37E86A94;
+drop table if exists ACCOUNTLISTITEM;
+drop table if exists ACCOUNTSCOMMON;
+drop table if exists ACCOUNTSCOMMONLIST;
+create table ACCOUNTLISTITEM (HJID bigint not null auto_increment, ANCHORNAME varchar(255), CSID varchar(255), EMAIL varchar(255), FIRSTNAME varchar(255), LASTNAME varchar(255), MI varchar(255), URI varchar(255), ACCOUNTLISTITEM_ACCOUNTSCOMM_0 bigint, primary key (HJID));
+create table ACCOUNTSCOMMON (CSID varchar(255) not null, ANCHORNAME varchar(255), EMAIL varchar(255), FIRSTNAME varchar(255), LASTNAME varchar(255), MI varchar(255), PHONE varchar(255), primary key (CSID));
+create table ACCOUNTSCOMMONLIST (HJID bigint not null auto_increment, primary key (HJID));
+alter table ACCOUNTLISTITEM add index FKBD8755BE37E86A94 (ACCOUNTLISTITEM_ACCOUNTSCOMM_0), add constraint FKBD8755BE37E86A94 foreign key (ACCOUNTLISTITEM_ACCOUNTSCOMM_0) references ACCOUNTSCOMMONLIST (HJID);
private final Logger logger = LoggerFactory.getLogger(AccountTest.class);
private EntityManagerFactory emf;
private EntityManager em;
+ private String id;
@BeforeMethod
public void init() {
@SuppressWarnings("unchecked")
@Test(dataProvider = "testName", dataProviderClass = AccountTest.class)
public void create(String testName) throws Exception {
- // Begin transaction
- em.getTransaction().begin();
AccountsCommon account = new AccountsCommon();
account.setAnchorName("sanjay");
account.setFirstName("Sanjay");
account.setLastName("Dalal");
account.setEmail("sanjay.dalal@berkeley.edu");
- account.setCsid(UUID.randomUUID().toString());
+ id = UUID.randomUUID().toString();
+ account.setCsid(id);
+ em.getTransaction().begin();
em.persist(account);
// Commit the transaction
em.getTransaction().commit();
@Test(dataProvider = "testName", dataProviderClass = AccountTest.class,
dependsOnMethods = {"read"})
public void update(String testName) throws Exception {
- // Begin transaction
+ Query q = em.createQuery("update org.collectionspace.services.account.AccountsCommon set email= :email where csid=:csid");
+ q.setParameter("email", "sanjay@berkeley.edu");
+ q.setParameter("csid", id);
em.getTransaction().begin();
- AccountsCommon account = findAccount("sanjay");
- Assert.assertNotNull(account);
- account.setEmail("sanjay@berkeley.edu");
- em.persist(account);
+ int no = q.executeUpdate();
// Commit the transaction
em.getTransaction().commit();
+ Assert.assertEquals(no, 1);
+ AccountsCommon account = findAccount("sanjay");
if (logger.isDebugEnabled()) {
logger.debug("updated account " +
" first name=" + account.getFirstName() +
@Test(dataProvider = "testName", dataProviderClass = AccountTest.class,
dependsOnMethods = {"update"})
public void delete(String testName) throws Exception {
+ Query q = em.createQuery("delete from org.collectionspace.services.account.AccountsCommon where csid=:csid");
+ q.setParameter("csid", id);
// Begin transaction
em.getTransaction().begin();
- AccountsCommon account = findAccount("sanjay");
- Assert.assertNotNull(account);
+ int no = q.executeUpdate();
+ ;
if (logger.isDebugEnabled()) {
logger.debug("deleting account " +
- " first name=" + account.getFirstName() +
- " email=" + account.getEmail());
+ " csid=" + id);
}
- em.remove(account);
// Commit the transaction
em.getTransaction().commit();
+ Assert.assertEquals(no, 1);
if (logger.isDebugEnabled()) {
logger.debug("deleted account " +
- " first name=" + account.getFirstName());
+ " csid=" + id);
}
}