Jump to content

data source based on login


scphantm

Recommended Posts

 the way my system works is i need to have a report that can run against about 100 or so identical databases.  when the user logs in, jasperserver has to associate a specific data source to that user and when a report is run use that data source thats specific to the user for their reports.  that way i can have one instance of jasperserver running several hundred user accounts.

 

is that possible?

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

im researching the custom datasource code thats distributed with the server. if i use the hibernate example, how exactly could i pass the name of the role that the user is a member of to the HibernateDataSourceService class? it looks like if i accomplish that then i can simply define all my databases in the application context file of my datasource and have the roles in jasperserver match. if i can somehow pass the data source the role name, i should have it right?
Link to comment
Share on other sites

im trying to get the custom datasource examples to deploy. when i restart the server i get class version errors on the new class files. what version of the JVM is this built with? im using jvm 6 for everything so i would imagine it should work
Link to comment
Share on other sites

To achieve the solution you have to modify jasperreport.jar file.

In each Report pass a parameter it should contain the information related to connection.

example:JNDI_NAME

JRJdbcQueryExecuter.java modify this class(you can find this file in jasperreport.jar/ net/sf/jasperreports/engine/query)

 

Here is the code needs to be modified.

 

  public JRJdbcQueryExecuter(JRDataset dataset, Map  parameters)

     {

         super(dataset, parameters);

        

         connection = (Connection ) getParameterValue(JRParameter.REPORT_CONNECTION);

        

         /*Custom Code Start*/

         if(connection==null){       

         JRFillParameter JNDI_NAME = getParameter("JNDI_NAME");(get the parameter whatever you’re passing from report)

         Class clazz = JNDI_NAME.getValueClass();

         Object JNDI_NAME_Value = JNDI_NAME.getValue();

         

        Context ctx = null;

        DataSource ds=null;

        try{

                        initial = new InitialContext();

                        Context envContext  = (Context)initial.lookup("java:/comp/env");       

                        if(JNDI_NAME_Value!=null )

                        ds = (DataSource)envContext.lookup(JNDI_NAME_Value.toString());           

                        connection=ds.getConnection();       

                        System.out.println("Connection Object----------------------"+connection);

        }

       

        /*Custom Code End*/

        catch(Exception e){

                e.printStackTrace();       

        }

        finally{

            try{

                    if(ctx != null){

                            ctx.close();

                    }

            }

            catch(Exception e) {

                e.printStackTrace();

            }

        }

 

         }

 

Replace this class file in jasperreports.jar and copy this jar in jasperserver-pro/WEB-INF/lib dir.

 

Finally while creating the report in jasper server Please select data source none option.

 

Venkat.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...