]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
NOJIRA added annotation for id in xsd, use mvn -Pddl process-test-classes to generate
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Tue, 17 Nov 2009 18:44:02 +0000 (18:44 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Tue, 17 Nov 2009 18:44:02 +0000 (18:44 +0000)
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

services/account/jaxb/pom.xml
services/account/jaxb/src/main/resources/accounts_common.xsd
services/account/jaxb/src/main/resources/db/mysql/account.sql [new file with mode: 0644]
services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java

index 98f96b17569e1ecb4ee9b5c5e9a24a7c5f8e2918..f4e8dff2e3bcb9bae63548924988e756089bb19a 100644 (file)
     <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>
index fab3f5876f0df8e8664180dd97d438aa2fb0f4f3..c93750bac91dd2ac4fd4bd19d2ec3125ff4aeba0 100644 (file)
@@ -33,7 +33,6 @@
     <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>
 
diff --git a/services/account/jaxb/src/main/resources/db/mysql/account.sql b/services/account/jaxb/src/main/resources/db/mysql/account.sql
new file mode 100644 (file)
index 0000000..4e9d9e6
--- /dev/null
@@ -0,0 +1,8 @@
+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);
index 4a7a08ecffe5aeddc0241281d02cb8f884908468..31ddfaa0523cd83ada59730c2a3e495033408f1a 100644 (file)
@@ -32,6 +32,7 @@ public class AccountTest {
     private final Logger logger = LoggerFactory.getLogger(AccountTest.class);
     private EntityManagerFactory emf;
     private EntityManager em;
+    private String id;
 
     @BeforeMethod
     public void init() {
@@ -54,14 +55,14 @@ public class AccountTest {
     @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();
@@ -95,14 +96,15 @@ public class AccountTest {
     @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() +
@@ -114,21 +116,22 @@ public class AccountTest {
     @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);
         }
     }