ORMappingConfig is now provided by the datasource component.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 15 May 2008 10:17:53 +0000 (10:17 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 15 May 2008 10:17:53 +0000 (10:17 +0000)
ExternalDatasourceComponent reads config from property file.
Next step is that it requires config from a separate
Properties object which is provided by either a property component,
or a DatabaseComponent (e.g. Derby).

trunk/security/src/main/java/org/wamblee/security/encryption/Md5HexMessageDigester.java
trunk/security/src/main/java/org/wamblee/usermgt/hibernate/AuthorizationComponent.java
trunk/security/src/main/java/org/wamblee/usermgt/hibernate/UserAdministrationComponent.java
trunk/security/src/test/java/org/wamblee/usermgt/hibernate/ExternalDatasourceComponent.java
trunk/security/src/test/resources/properties/test.org.wamblee.security.database.properties

index 180a9a3a3d00d5102bd8065b5dfd522e30baf370..161b652e1ddc81cbc3a6e31728e0f3f9d11addf7 100644 (file)
@@ -45,7 +45,7 @@ public class Md5HexMessageDigester implements MessageDigester {
         try {
             MessageDigest digest = MessageDigest.getInstance("MD5");
             byte[] result = digest.digest(aValue.getBytes());
-            char[] charResult = new Hex().encodeHex(result);
+            char[] charResult = Hex.encodeHex(result);
             return new String(charResult);
         } catch (NoSuchAlgorithmException e) {
             throw new IllegalArgumentException("MD5 not supported????");
index 0093dc8dca46affdc31abe31e6d92c0270272e18..339a0f1a03e396b19c756e9e9cb3d54f3580f05e 100644 (file)
@@ -31,6 +31,7 @@ import org.wamblee.system.core.DefaultRequiredInterface;
 import org.wamblee.system.core.ProvidedInterface;
 import org.wamblee.system.core.Scope;
 import org.wamblee.system.spring.component.HibernateComponent;
+import org.wamblee.system.spring.component.ORMappingConfig;
 import org.wamblee.usermgt.UserAccessor;
 import org.wamblee.usermgt.UserAdministration;
 import org.wamblee.usermgt.UserGroupRepositoryComponent;
@@ -59,6 +60,7 @@ public class AuthorizationComponent extends DefaultContainer {
         addRequiredInterface(new DefaultRequiredInterface("datasource", DataSource.class));
         addRequiredInterface(new DefaultRequiredInterface("userAccessor",
                 UserAccessor.class));
+        addRequiredInterface(new DefaultRequiredInterface("ormconfig", ORMappingConfig.class));
 
         if (aExposeInternals) {
             addProvidedInterface(TRANSACTION_MGR);
index 6ac0ee946655f56822d59febf968909a7384a092..dd0fb98e487bd1bb60725eb5deecc2d24cbd7fa6 100644 (file)
@@ -29,6 +29,7 @@ import org.wamblee.system.core.DefaultRequiredInterface;
 import org.wamblee.system.core.ProvidedInterface;
 import org.wamblee.system.core.Scope;
 import org.wamblee.system.spring.component.HibernateComponent;
+import org.wamblee.system.spring.component.ORMappingConfig;
 import org.wamblee.usermgt.UserAdministration;
 import org.wamblee.usermgt.UserGroupRepositoryComponent;
 
@@ -60,6 +61,7 @@ public class UserAdministrationComponent extends DefaultContainer {
 
         addRequiredInterface(new DefaultRequiredInterface("datasource",
                 DataSource.class));
+        addRequiredInterface(new DefaultRequiredInterface("ormconfig", ORMappingConfig.class));
 
         if (aExposeInternals) {
             addProvidedInterface(TRANSACTION_MGR);
index 673aaceb6d5114f23ef4303fa7520b9224a1f936..55a2537c613d69c91305ad29dbe535f8187a5dd9 100644 (file)
@@ -23,35 +23,66 @@ import java.util.TreeMap;
 import javax.sql.DataSource;
 
 import org.springframework.core.io.ClassPathResource;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.wamblee.system.core.AbstractComponent;
 import org.wamblee.system.core.DefaultProvidedInterface;
 import org.wamblee.system.core.ProvidedInterface;
 import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.Scope;
 import org.wamblee.system.spring.SpringComponent;
+import org.wamblee.system.spring.component.ORMappingConfig;
+import org.wamblee.system.spring.component.ORMappingConfig.DatabaseType;
 
-public class ExternalDatasourceComponent extends SpringComponent {
+public class ExternalDatasourceComponent extends AbstractComponent<DataSource> {
 
     private static final String DATABASE_PROPERTIES = "properties/test.org.wamblee.security.database.properties";
-    private static final String DATASOURCE_SPRING_CONFIG = "spring/test.org.wamblee.security.datasource.xml";
+   
+    private static ProvidedInterface DATASOURCE =  new DefaultProvidedInterface("datasource",
+            DataSource.class);
+    private static ProvidedInterface ORM_CONFIG = new DefaultProvidedInterface("ormconfig",
+            ORMappingConfig.class);
 
+    private Properties _dbProps;
+   
     public ExternalDatasourceComponent(String aName) throws IOException {
-        super(
-                aName,
-                new String[] { DATASOURCE_SPRING_CONFIG },
-                createProvidedMap(), new TreeMap<RequiredInterface, String>());
-        Properties props = new Properties(); 
-        props.load(new ClassPathResource(DATABASE_PROPERTIES).getInputStream());
-     
-        for (Object key: props.keySet()) { 
-            System.out.println("Key " + key + " value " + props.getProperty((String)key));
-        }
-        addProperties(props);
+        this(aName, loadProperties());
     }
 
-    private static Map<String, ProvidedInterface> createProvidedMap() {
-        Map<String, ProvidedInterface> provided = new TreeMap<String, ProvidedInterface>();
-        provided.put("dataSource", new DefaultProvidedInterface("datasource",
-                DataSource.class));
-        return provided;
+    private static Properties loadProperties() throws IOException {
+        Properties dbProps = new Properties();
+        dbProps.load(new ClassPathResource(DATABASE_PROPERTIES)
+                .getInputStream());
+        return dbProps;
     }
+    
+    public ExternalDatasourceComponent(String aName, Properties aProps) throws IOException {
+        super(aName);
+        _dbProps = aProps;
+        
+        addProvidedInterface(DATASOURCE);
+        addProvidedInterface(ORM_CONFIG);
+    }
+
 
+    @Override
+    protected DataSource doStart(Scope aScope) {
+        DriverManagerDataSource ds = new DriverManagerDataSource(
+                _dbProps.getProperty("database.driver"),
+                _dbProps.getProperty("database.url"), 
+                _dbProps.getProperty("database.username"),
+                _dbProps.getProperty("database.password"));
+       addInterface(DATASOURCE, ds, aScope);
+       DatabaseType type = DatabaseType.valueOf(_dbProps.getProperty("database.type"));
+       
+       ORMappingConfig config = new ORMappingConfig(true, type);
+       
+       addInterface(ORM_CONFIG, config, aScope);
+       
+       return ds; 
+    }
+
+    @Override
+    protected void doStop(DataSource aRuntime) {
+       // Empty.
+    }
 }
index 4c2ddd98d35a5bb0eb9e18d1834efbc960173952..bff2ee479d506f716905aaa2256f14de35dd8162 100644 (file)
@@ -2,6 +2,9 @@
 
 # Database properties for test runs in a J2SE environment. 
 
+# See ORMappingConfig.DatabaseType for allowed values
+database.type=MYSQL_INNO_DB
+
 database.driver=com.mysql.jdbc.Driver
 database.url=jdbc:mysql://localhost:3306/test
 database.username=erik