cancel
Showing results for 
Search instead for 
Did you mean: 

Access to dbconnection to execute arbritrary query

tcheekva
Champ in-the-making
Champ in-the-making
Is there a way to either access the internal db connection object in a script task or Java task, so that I can run an arbitrary query?  I am embedding Activiti using plain java

         ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
               .createStandaloneProcessEngineConfiguration()
               .setJdbcUrl((String) params.get("url"))
               .setJdbcDriver((String) params.get("driver"))
               .setJdbcUsername((String) params.get("user"))
               .setJdbcPassword((String) params.get("pword"))
               .setMailServerHost((String) params.get("emailhost"))
               .setMailServerPort(Integer.parseInt((String) params.get("emailport")))
               .setMailServerUsername((String) params.get("emailuser"))
               .setMailServerPassword((String) params.get("emailpass"))
               .setMailServerDefaultFrom((String) params.get("emaildefaultfrom"))
               .setJobExecutorActivate(true)
               .setProcessEngineName((String) params.get("dbname"));

         // add our customform types to the engine
         List<AbstractFormType> customFormTypes = new ArrayList<AbstractFormType>();
         customFormTypes.add(new FileFormType());
         customFormTypes.add(new TextAreaFormType());
         customFormTypes.add(new RadioFormType(null));
         ((ProcessEngineConfigurationImpl) processEngineConfiguration).setCustomFormTypes(customFormTypes);
         
         ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

         //now we can add our custom handlers for user/groups
         Map<Class< ? >, SessionFactory> sessionFactories =
               ((ProcessEngineConfigurationImpl) processEngineConfiguration).getSessionFactories();
         sessionFactories.put(UserEntityManager.class, new CustomUserEntityManagerFactory());         
         sessionFactories.put(GroupEntityManager.class, new CustomGroupEntityManagerFactory());
         
         ProcessEngines.registerProcessEngine(processEngine);


everything is working fine so far, but I need to run some queries in a script or java task and I would prefer to do this with out making new database connections.  Script task would be preferred as I would not need to have java class files during deployment.

Thanks
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
You can try using the Context.getCommandContext() to obtain a org.activiti.engine.impl.interceptor.CommandContext. This allows you to get hold of the DBSqlSession and getSQLSession() on this. The SQLSession exposes a getConnection() method which returns the current session used in the process that is executing the script/service task.

tcheekva
Champ in-the-making
Champ in-the-making
This is working fine in a task, thanks.  I also need access from within a new form type (AbstractFormType).  creating a dynamic selection from a database table.  The Context above is returning null.  Is there a way to do this from a FormType? I was also trying thru a processEngine but how do I know which engine I am running in?

frederikherema1
Star Contributor
Star Contributor
When getting form-properties, there is no process context active YET. You'll have to make you're type smart enough (e.g.. wire reference to processEngine in Spring) to know what engine to use to get hold of a SQLConnection.

frederikherema1
Star Contributor
Star Contributor
When getting form-properties, there is no process context active YET. You'll have to make you're type smart enough (e.g.. wire reference to processEngine in Spring) to know what engine to use to get hold of a SQLConnection.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.