[jboss-svn-commits] JBL Code SVN: r5666 - in labs/jbossrules/trunk/legacy: . drools-repository/eclipse-svn-plugin/org.nexb.easyeclipse.drools.deployer drools-repository/src/main/java/org/drools/repository/db drools-repository/src/test/resources

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 9 16:48:00 EDT 2006


Author: michael.neale at jboss.com
Date: 2006-08-09 16:47:55 -0400 (Wed, 09 Aug 2006)
New Revision: 5666

Added:
   labs/jbossrules/trunk/legacy/drools-repository/
Removed:
   labs/jbossrules/trunk/legacy/drools-repository/eclipse-svn-plugin/org.nexb.easyeclipse.drools.deployer/bin/
Modified:
   labs/jbossrules/trunk/legacy/drools-repository/src/main/java/org/drools/repository/db/StoreInterceptor.java
   labs/jbossrules/trunk/legacy/drools-repository/src/test/resources/drools-repository-db.cfg.xml
Log:
moved from main directory

Copied: labs/jbossrules/trunk/legacy/drools-repository (from rev 5636, labs/jbossrules/trunk/drools-repository)

Modified: labs/jbossrules/trunk/legacy/drools-repository/src/main/java/org/drools/repository/db/StoreInterceptor.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/db/StoreInterceptor.java	2006-08-09 13:55:57 UTC (rev 5636)
+++ labs/jbossrules/trunk/legacy/drools-repository/src/main/java/org/drools/repository/db/StoreInterceptor.java	2006-08-09 20:47:55 UTC (rev 5666)
@@ -1,212 +1,212 @@
-package org.drools.repository.db;
-
-import java.io.Serializable;
-import java.security.Principal;
-import java.sql.Connection;
-import java.util.Date;
-
-import org.drools.repository.Asset;
-import org.drools.repository.security.ACLEnforcer;
-import org.drools.repository.security.ACLResource;
-import org.drools.repository.security.AssetPermission;
-import org.hibernate.EmptyInterceptor;
-import org.hibernate.LockMode;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.type.Type;
-
-/**
- * This event listener processes database events using an interceptor. 
- * 
- * When an asset is updated that requires a history record, a history record will be created by 
- * loading and then copying the old copy of the data. 
- * (using an seperate session that is not related to the current session, but sharing the same connection).
- * 
- * Note that it will also save audit information about whom saved the data.
- * 
- * ACLs are also enforced here.
- * 
- * @author <a href="mailto:michael.neale at gmail.com"> Michael Neale</a>
- */
-public class StoreInterceptor extends EmptyInterceptor {
-
-    private static final long serialVersionUID = -5634072610999632779L;
-    
-    //use a threadlocal to get the currentConnection, 
-    //as we may not always use currentSession semantics.
-    private static ThreadLocal currentConnection = new ThreadLocal();
-
-    //we also need the current user if it has been set.
-    private static ThreadLocal currentUser = new ThreadLocal();
-    
-    //for enforcing ACLs
-    private static ThreadLocal currentACLEnforcer = new ThreadLocal();
-    
-    /**
-     * Create historical records, and log events.
-     */
-    public boolean onFlushDirty(Object entity,
-                                Serializable id,
-                                Object[] currentState,
-                                Object[] previousState,
-                                String[] propertyNames,
-                                Type[] types) {
-        
-        checkACLAllowed( entity, id, "You are not authorized to save this asset.",
-                         AssetPermission.WRITE );
-        checkACLDenied( entity, id, "You have been denied authority to save this asset.", 
-                         AssetPermission.DENY_WRITE);
-        
-        if ( entity instanceof ISaveHistory ) {
-            handleSaveHistory( entity );
-        }
-        return handleUserSaveInfo( entity,
-                                   currentState,
-                                   propertyNames );        
-    }
-
-    public boolean onLoad(Object entity,
-                          Serializable id,
-                          Object[] state,
-                          String[] propertyNames,
-                          Type[] types)
-                    {
-        checkACLAllowed(entity, id, "You are not authorized to load this asset.", 
-                        AssetPermission.READ);
-        checkACLDenied(entity, id, "You have been blocked from loading this asset.", 
-                       AssetPermission.DENY_READ);
-        return false;
-    }
-    
-
-    /** record who and when */
-    public boolean onSave(Object entity,
-                          Serializable id,
-                          Object[] currentState,
-                          String[] propertyNames,
-                          Type[] types) {
-        
-        return handleUserSaveInfo( entity,
-                                   currentState,
-                                   propertyNames );
-        
-    }    
-    
-    public void onDelete(Object entity,
-                         Serializable id,
-                         Object[] arg2,
-                         String[] arg3,
-                         Type[] arg4) {
-        checkACLAllowed(entity, id, "You are not authorized to delete this asset.", 
-                        AssetPermission.DELETE);
-        checkACLDenied(entity, id, "You have been disallowed from deleting this asset.", 
-                       AssetPermission.DENY_DELETE);
-    }
-    
-    
-    
-    /**
-     * Check that the ACL allows the user the appropriate permission.
-     */
-    private void checkACLAllowed(Object entity,
-                          Serializable assetId, String failMessage, int permission) {
-        if (! (entity instanceof ACLResource)) return;
-        ACLEnforcer enforcer = (ACLEnforcer) currentACLEnforcer.get();
-        if (enforcer != null) {
-            //TODO: make it more flexible in what the "ID" is - may be rulename for instance??
-            enforcer.checkAllowed(entity, assetId, permission, failMessage);
-        }
-    }
-    
-    /**
-     * Check for explicitly denied ACL entries.
-     */
-    private void checkACLDenied(Object entity,
-                          Serializable assetId, String failMessage, int permission) {
-        if (! (entity instanceof ACLResource)) return;
-        ACLEnforcer enforcer = (ACLEnforcer) currentACLEnforcer.get();
-        if (enforcer != null) {
-            enforcer.checkDenied(entity, assetId, permission, failMessage);
-        }
-    }
-    
-    
-
-    /**
-     * This will load up the old copy, and save it as a history record
-     * (with a different identity).
-     * Filters stop the history records from popping up in unwanted places .
-     */
-    private void handleSaveHistory(Object entity) {
-        ISaveHistory versionable = (ISaveHistory) entity;
-        
-        Session session = getSessionFactory().openSession( (Connection) currentConnection.get() );
-        ISaveHistory prev = (ISaveHistory) session.load( entity.getClass(),
-                                                         versionable.getId(),
-                                                         LockMode.NONE );
-        ISaveHistory copy = (ISaveHistory) prev.copy();
-        copy.setHistoricalId( versionable.getId() );
-        copy.setHistoricalRecord( true );
-        
-        session.save( copy );
-        
-        session.flush();                        
-        session.close();
-    }
-    
-    /**
-     * Used to set the current session so the interceptor can access it.
-     * The idea is to share the same connection that any current transactions 
-     * are using.
-     */
-    public static void setCurrentConnection(Connection conn) {
-        currentConnection.set(conn);
-    }
-    
-    /**
-     * Set the current user for auditing purposes.
-     * This is backed by a threadlocal.
-     */
-    public static void setCurrentUser(Principal user) {
-        currentUser.set(user);
-    }
-
-    /** Set the ACL enforcer to enforce access rules for the current user */
-    public static void setCurrentACLEnforcer(ACLEnforcer enforcer) {
-        currentACLEnforcer.set(enforcer);
-    }
-
-    private SessionFactory getSessionFactory() {
-        return HibernateUtil.getSessionFactory();
-    }
-
-
-
-    /** Log who saved, what, when */
-    private boolean handleUserSaveInfo(Object entity,
-                                       Object[] currentState,
-                                       String[] propertyNames) {
-        if (entity instanceof Asset) {
-            Principal user = (Principal) currentUser.get();
-            boolean changed = false;
-                
-                for ( int i=0; i < propertyNames.length; i++ ) {
-                    if ( "lastSavedDate".equals( propertyNames[i] ) ) {
-                        currentState[i] = new Date();
-                        changed = true;
-                    } else if (user != null && "lastSavedByUser".equals( propertyNames[i]) ) {
-                        currentState[i] = user.getName();
-                        changed = true;
-                    }
-                }
-            return changed;
-        } else {
-            return false;
-        }
-        
-    }
-
-
-
-    
-}
+package org.drools.repository.db;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.sql.Connection;
+import java.util.Date;
+
+import org.drools.repository.Asset;
+import org.drools.repository.security.ACLEnforcer;
+import org.drools.repository.security.ACLResource;
+import org.drools.repository.security.AssetPermission;
+import org.hibernate.EmptyInterceptor;
+import org.hibernate.LockMode;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.type.Type;
+
+/**
+ * This event listener processes database events using an interceptor. 
+ * 
+ * When an asset is updated that requires a history record, a history record will be created by 
+ * loading and then copying the old copy of the data. 
+ * (using an seperate session that is not related to the current session, but sharing the same connection).
+ * 
+ * Note that it will also save audit information about whom saved the data.
+ * 
+ * ACLs are also enforced here.
+ * 
+ * @author <a href="mailto:michael.neale at gmail.com"> Michael Neale</a>
+ */
+public class StoreInterceptor extends EmptyInterceptor {
+
+    private static final long serialVersionUID = -5634072610999632779L;
+    
+    //use a threadlocal to get the currentConnection, 
+    //as we may not always use currentSession semantics.
+    private static ThreadLocal currentConnection = new ThreadLocal();
+
+    //we also need the current user if it has been set.
+    private static ThreadLocal currentUser = new ThreadLocal();
+    
+    //for enforcing ACLs
+    private static ThreadLocal currentACLEnforcer = new ThreadLocal();
+    
+    /**
+     * Create historical records, and log events.
+     */
+    public boolean onFlushDirty(Object entity,
+                                Serializable id,
+                                Object[] currentState,
+                                Object[] previousState,
+                                String[] propertyNames,
+                                Type[] types) {
+        
+        checkACLAllowed( entity, id, "You are not authorized to save this asset.",
+                         AssetPermission.WRITE );
+        checkACLDenied( entity, id, "You have been denied authority to save this asset.", 
+                         AssetPermission.DENY_WRITE);
+        
+        if ( entity instanceof ISaveHistory ) {
+            handleSaveHistory( entity );
+        }
+        return handleUserSaveInfo( entity,
+                                   currentState,
+                                   propertyNames );        
+    }
+
+    public boolean onLoad(Object entity,
+                          Serializable id,
+                          Object[] state,
+                          String[] propertyNames,
+                          Type[] types)
+                    {
+        checkACLAllowed(entity, id, "You are not authorized to load this asset.", 
+                        AssetPermission.READ);
+        checkACLDenied(entity, id, "You have been blocked from loading this asset.", 
+                       AssetPermission.DENY_READ);
+        return false;
+    }
+    
+
+    /** record who and when */
+    public boolean onSave(Object entity,
+                          Serializable id,
+                          Object[] currentState,
+                          String[] propertyNames,
+                          Type[] types) {
+        
+        return handleUserSaveInfo( entity,
+                                   currentState,
+                                   propertyNames );
+        
+    }    
+    
+    public void onDelete(Object entity,
+                         Serializable id,
+                         Object[] arg2,
+                         String[] arg3,
+                         Type[] arg4) {
+        checkACLAllowed(entity, id, "You are not authorized to delete this asset.", 
+                        AssetPermission.DELETE);
+        checkACLDenied(entity, id, "You have been disallowed from deleting this asset.", 
+                       AssetPermission.DENY_DELETE);
+    }
+    
+    
+    
+    /**
+     * Check that the ACL allows the user the appropriate permission.
+     */
+    private void checkACLAllowed(Object entity,
+                          Serializable assetId, String failMessage, int permission) {
+        if (! (entity instanceof ACLResource)) return;
+        ACLEnforcer enforcer = (ACLEnforcer) currentACLEnforcer.get();
+        if (enforcer != null) {
+            //TODO: make it more flexible in what the "ID" is - may be rulename for instance??
+            enforcer.checkAllowed(entity, assetId, permission, failMessage);
+        }
+    }
+    
+    /**
+     * Check for explicitly denied ACL entries.
+     */
+    private void checkACLDenied(Object entity,
+                          Serializable assetId, String failMessage, int permission) {
+        if (! (entity instanceof ACLResource)) return;
+        ACLEnforcer enforcer = (ACLEnforcer) currentACLEnforcer.get();
+        if (enforcer != null) {
+            enforcer.checkDenied(entity, assetId, permission, failMessage);
+        }
+    }
+    
+    
+
+    /**
+     * This will load up the old copy, and save it as a history record
+     * (with a different identity).
+     * Filters stop the history records from popping up in unwanted places .
+     */
+    private void handleSaveHistory(Object entity) {
+        ISaveHistory versionable = (ISaveHistory) entity;
+        
+        Session session = getSessionFactory().openSession( (Connection) currentConnection.get() );
+        ISaveHistory prev = (ISaveHistory) session.load( entity.getClass(),
+                                                         versionable.getId(),
+                                                         LockMode.NONE );
+        ISaveHistory copy = (ISaveHistory) prev.copy();
+        copy.setHistoricalId( versionable.getId() );
+        copy.setHistoricalRecord( true );
+        
+        session.save( copy );
+        
+        session.flush();                        
+        session.close();
+    }
+    
+    /**
+     * Used to set the current session so the interceptor can access it.
+     * The idea is to share the same connection that any current transactions 
+     * are using.
+     */
+    public static void setCurrentConnection(Connection conn) {
+        currentConnection.set(conn);
+    }
+    
+    /**
+     * Set the current user for auditing purposes.
+     * This is backed by a threadlocal.
+     */
+    public static void setCurrentUser(Principal user) {
+        currentUser.set(user);
+    }
+
+    /** Set the ACL enforcer to enforce access rules for the current user */
+    public static void setCurrentACLEnforcer(ACLEnforcer enforcer) {
+        currentACLEnforcer.set(enforcer);
+    }
+
+    private SessionFactory getSessionFactory() {
+        return HibernateUtil.getSessionFactory();
+    }
+
+
+
+    /** Log who saved, what, when */
+    private boolean handleUserSaveInfo(Object entity,
+                                       Object[] currentState,
+                                       String[] propertyNames) {
+        if (entity instanceof Asset) {
+            Principal user = (Principal) currentUser.get();
+            boolean changed = false;
+                
+                for ( int i=0; i < propertyNames.length; i++ ) {
+                    if ( "lastSavedDate".equals( propertyNames[i] ) ) {
+                        currentState[i] = new Date();
+                        changed = true;
+                    } else if (user != null && "lastSavedByUser".equals( propertyNames[i]) ) {
+                        currentState[i] = user.getName();
+                        changed = true;
+                    }
+                }
+            return changed;
+        } else {
+            return false;
+        }
+        
+    }
+
+
+
+    
+}

Modified: labs/jbossrules/trunk/legacy/drools-repository/src/test/resources/drools-repository-db.cfg.xml
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/resources/drools-repository-db.cfg.xml	2006-08-09 13:55:57 UTC (rev 5636)
+++ labs/jbossrules/trunk/legacy/drools-repository/src/test/resources/drools-repository-db.cfg.xml	2006-08-09 20:47:55 UTC (rev 5666)
@@ -1,51 +1,51 @@
-<?xml version='1.0' encoding='utf-8'?>
-<!DOCTYPE hibernate-configuration PUBLIC
-        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
-        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
-
-<!-- 
-	**** Drools Repository database configuration. ****
-	As you can see from the DTD, this makes use of Hibernate 3 for persistence and querying.
-	
-	This file is configured for HSQLDB in memory operation (not recommended for production).
-
-	******************************************************************************
-	To provide your own configuration, place your own drools-repository-db.cfg.xml
-	in the front of the classpath (at the root).
-	******************************************************************************	
- -->
-
-<hibernate-configuration>
-
-    <session-factory>
-
-        <!-- Database connection settings -->
-        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
-        <property name="connection.url">jdbc:hsqldb:mem:unittest</property>                
-        
-        <property name="connection.username">sa</property>
-        <property name="connection.password"></property>
-
-        <!-- JDBC connection pool (use the built-in) -->
-        <property name="connection.pool_size">1</property>
-
-        <!-- SQL dialect -->
-        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
-
-        <!-- Enable Hibernate's automatic session context management -->
-        <property name="current_session_context_class">thread</property>
-
-        <!-- Disable the second-level cache  -->
-        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
-
-        <!-- Echo all executed SQL to stdout -->
-        <property name="show_sql">false</property>
-
-        <!-- Drop and re-create the database schema on startup -->
-        <property name="hbm2ddl.auto">create</property>
-	
-    </session-factory>
-    
-    
-
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC
+        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<!-- 
+	**** Drools Repository database configuration. ****
+	As you can see from the DTD, this makes use of Hibernate 3 for persistence and querying.
+	
+	This file is configured for HSQLDB in memory operation (not recommended for production).
+
+	******************************************************************************
+	To provide your own configuration, place your own drools-repository-db.cfg.xml
+	in the front of the classpath (at the root).
+	******************************************************************************	
+ -->
+
+<hibernate-configuration>
+
+    <session-factory>
+
+        <!-- Database connection settings -->
+        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
+        <property name="connection.url">jdbc:hsqldb:mem:unittest</property>                
+        
+        <property name="connection.username">sa</property>
+        <property name="connection.password"></property>
+
+        <!-- JDBC connection pool (use the built-in) -->
+        <property name="connection.pool_size">1</property>
+
+        <!-- SQL dialect -->
+        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
+
+        <!-- Enable Hibernate's automatic session context management -->
+        <property name="current_session_context_class">thread</property>
+
+        <!-- Disable the second-level cache  -->
+        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
+
+        <!-- Echo all executed SQL to stdout -->
+        <property name="show_sql">false</property>
+
+        <!-- Drop and re-create the database schema on startup -->
+        <property name="hbm2ddl.auto">create</property>
+	
+    </session-factory>
+    
+    
+
 </hibernate-configuration>
\ No newline at end of file




More information about the jboss-svn-commits mailing list