From: erik Date: Fri, 9 Apr 2010 21:53:46 +0000 (+0000) Subject: schema generation for hibernate mysql as a starting point before X-Git-Tag: wamblee-utils-0.2@603~24 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=cc962c22c40063c42987be77e0095e176dbe7e7b;p=utils schema generation for hibernate mysql as a starting point before starting with jpa --- diff --git a/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java b/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java index 2dcefee7..f55fc293 100644 --- a/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java +++ b/trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java @@ -19,6 +19,10 @@ package org.wamblee.security.authorization.hibernate; import java.sql.SQLException; import org.apache.log4j.Logger; +import org.hibernate.cfg.Configuration; +import org.hibernate.dialect.MySQL5Dialect; +import org.hibernate.dialect.MySQL5InnoDBDialect; +import org.hibernate.tool.hbm2ddl.SchemaExport; import org.springframework.orm.hibernate3.HibernateTemplate; import org.wamblee.general.BeanKernel; import org.wamblee.security.authorization.AuthorizationService; @@ -69,17 +73,17 @@ public class PersistentAuthorizationServiceTest extends _container = new DefaultContainer("top"); DatabaseComponentFactory.addDatabaseConfig(_container); _container.addComponent(new DatasourceComponent("datasource")); - ClassConfiguration useraccessorConfig = new ClassConfiguration(TestUserAccessor.class); + ClassConfiguration useraccessorConfig = new ClassConfiguration( + TestUserAccessor.class); useraccessorConfig.getObjectConfig().getSetterConfig().initAllSetters(); _container.addComponent("userAccessor", useraccessorConfig); _container.addComponent(new AuthorizationComponent("authorization", true)); - - ClassConfiguration dbtesterConfig = new ClassConfiguration(DatabaseTesterComponent.class); + ClassConfiguration dbtesterConfig = new ClassConfiguration( + DatabaseTesterComponent.class); dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters(); - _container - .addComponent("databaseTester", dbtesterConfig); + _container.addComponent("databaseTester", dbtesterConfig); ObjectConfiguration config = new ObjectConfiguration( PersistentAuthorizationServiceTest.class); @@ -106,7 +110,7 @@ public class PersistentAuthorizationServiceTest extends public void setHibernateTemplate(HibernateTemplate aHibernateTemplate) { _hibernateTemplate = aHibernateTemplate; } - + public void setAuthorizationService( AuthorizationService aAuthorizationService) { _authorizationService = aAuthorizationService; @@ -115,7 +119,9 @@ public class PersistentAuthorizationServiceTest extends /* * (non-Javadoc) * - * @see org.wamblee.security.authorization.AuthorizationServiceTest#createService() + * @see + * org.wamblee.security.authorization.AuthorizationServiceTest#createService + * () */ @Override protected AuthorizationService createService() { @@ -127,23 +133,38 @@ public class PersistentAuthorizationServiceTest extends /* * (non-Javadoc) * - * @see org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount(int) + * @see + * org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount + * (int) */ @Override protected void checkRuleCount(int aCount) { try { assertEquals(1, _databaseTester.getTableSize(SERVICE_TABLE)); assertEquals(aCount, _databaseTester.getTableSize(RULES_TABLE)); - assertEquals(aCount, _databaseTester.getTableSize(SERVICE_RULES_TABLE)); + assertEquals(aCount, _databaseTester + .getTableSize(SERVICE_RULES_TABLE)); assertEquals(aCount, _databaseTester.getTableSize(USERCOND_TABLE)); assertEquals(aCount, _databaseTester.getTableSize(PATHCOND_TABLE)); - assertEquals(aCount, _databaseTester.getTableSize(OPERATIONCOND_TABLE)); + assertEquals(aCount, _databaseTester + .getTableSize(OPERATIONCOND_TABLE)); } catch (SQLException e) { throw new RuntimeException(e); } } + public void testSchemaExport() { + Configuration config = new Configuration(); + for (String mappingFile: new AuthorizationMappingFiles()) { + config.addResource(mappingFile); + } + config.setProperty("hibernate.dialect", MySQL5InnoDBDialect.class.getName()); + SchemaExport exporter = new SchemaExport(config); + exporter.setOutputFile("target/mysql5.schema.sql"); + exporter.create(true,false); + } + public void testPerformance() { PersistentAuthorizationService service = (PersistentAuthorizationService) getService();