Home » Archived » BIRT » How To Set the dbURL, dbUser & dbPassword dynamically
How To Set the dbURL, dbUser & dbPassword dynamically [message #169421] |
Mon, 12 June 2006 17:37  |
Eclipse User |
|
|
|
Folks,
As you all know, the dbUrl, dbUserID & dbPassword information are
hard-coded inside the .rptdesign files. Since that's not usually
acceptable, here is how you remedy that:
----------BASIC EXECUTION CODE---------------------------
private void getHTMLReport(IMarkupWriter pWriter, Object[] pParameters)
{
ReportEngine engine = ReportingUtil.getEngine();
// Run reports, etc.
try
{
IReportRunnable design = getReportSpecification( engine,
(String)pParameters[ 0 ] );
// Create task to run the report and render the report
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
// renderContext.setImageDirectory("image");
HashMap<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEX T,
renderContext);
task.setAppContext(contextMap);
HashMap<String, Object> parameters = new HashMap<String, Object>();
setOutgoingParameters( parameters, pParameters );
//----THIS METHOD SETS THE DB PARMS DYNAMICALLY (SEE BELOW)-----
populateDatabaseConnectionParameters( design );
task.setParameterValues(parameters);
// create output stream
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
// Set rendering options - such as file or stream output,
// output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputStream(out);
options.setOutputFormat("html");
task.setRenderOption(options);
// UTF-8
task.run();
pWriter.printRaw( out.toString( "UTF-8" ) );
//printReport(pWriter, engine, report);
}
catch (Exception e1)
{
e1.printStackTrace();
}
// Shut down the engine.
if (engine != null)
engine.destroy();
}
----------------------------------------------------------
----------METHOD TO DYNAMICALLY SET THE DATABASE VALUES---
private void populateDatabaseConnectionParameters( IReportRunnable
pDesign )
{
String dbUrl = ""; //You decide how to get this
String dbUser = ""; //You decide how to get this
String dbPass = ""; //You decide how to get this
DesignElementHandle deh = pDesign.getDesignHandle();
SlotHandle slotHandle = deh.getSlot(
ReportDesignHandle.DATA_SOURCE_SLOT );
Iterator iter = slotHandle.iterator();
try
{
while( iter.hasNext() )
{
Object obj = iter.next();
OdaDataSourceHandle odaSrcHdl = (OdaDataSourceHandle) obj;
Iterator propIter = odaSrcHdl.getPropertyIterator();
while( propIter.hasNext() )
{
PropertyHandle propHdl = (PropertyHandle) propIter.next();
if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
"odaURL" ) )
{
propHdl.setStringValue( dbUrl );
}
else if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
"odaUser" ) )
{
propHdl.setStringValue( dbUser );
}
else if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
"odaPassword" ) )
{
propHdl.setStringValue( dbPassword );
}
}
}
}
catch( Exception e )
{
e.printStackTrace();
}
}
----------------------------------------------------------
|
|
| | |
Re: How To Set the dbURL, dbUser & dbPassword dynamically (Added missing method) [message #169698 is a reply to message #169525] |
Tue, 13 June 2006 09:50   |
Eclipse User |
|
|
|
Mathi,
If you look at the example (which is from a Tapestry application), you
will see it passes in an Object[] array. I will just include the entire
class that does this and will annotate it with ALL CAPS. The real point of
this is that you pass in a different .rptdesign file for each different
report. Depending on which report was passed, you populate a different
pattern of parameters. Please advise if you have any further questions.
Ty.
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SlotHandle;
import com.meco.api.configuration.ConfigurationService;
import com.meco.api.configuration.ConfigurationServiceAccessor;
import com.meco.web.reporting.ReportCriteria;
import com.meco.web.reporting.ReportingUtil;
public abstract class ReportRenderer extends AbstractComponent
{
protected void renderComponent(IMarkupWriter pWriter, IRequestCycle
pCycle)
{
pWriter.begin("p");
getHTMLReport(pWriter, pCycle.getListenerParameters());
pWriter.end("p");
}
THESE ARE THE INPUT
PARAMETERS.
private void getHTMLReport(IMarkupWriter pWriter, Object[] pParameters)
{
ReportEngine engine = ReportingUtil.getEngine();
// Run reports, etc.
try
{ //THE ZEROETH PARM IS
// THE .rptdesign FILE.
IReportRunnable design =
getReportSpecification( engine, (String)pParameters[ 0
] );
// Create task to run the report and render the report
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
// Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
// renderContext.setImageDirectory("image");
HashMap<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEX T,
renderContext);
task.setAppContext(contextMap);
HashMap<String, Object> parameters = new HashMap<String, Object>();
//IN THIS METHOD, I SETUP MY THERE WHERE CLAUSE THAT I WILL BE
// PASSING INTO THE ENGINE.
setOutgoingParameters( parameters, pParameters );
// HERE I AM GIVING THE PARAMETERS TO THE TASK. FOR EACH OF THESE
// REPORTS, YOU WILL PASS IN DIFFERENT VALUES, SUCH AS THE .rptdesign
// FILE.
task.setParameterValues(parameters);
populateDatabaseConnectionParameters( design );
// create output stream
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
// Set rendering options - such as file or stream output,
// output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputStream(out);
options.setOutputFormat("html");
task.setRenderOption(options);
// UTF-8
task.run();
pWriter.printRaw( out.toString( "UTF-8" ) );
//printReport(pWriter, engine, report);
}
catch (Exception e1)
{
e1.printStackTrace();
}
// Shut down the engine.
if (engine != null)
engine.destroy();
}
private IReportRunnable getReportSpecification( ReportEngine pEngine,
String pFileName ) throws Exception
{
InputStream stream =
ReportRenderer.class.getClassLoader().getResourceAsStream( pFileName );
IReportRunnable design = pEngine.openReportDesign( stream );
return design;
}
/** Because each report has its own set of particulars that must be set,
this method just redirects to the particular methods that are designed for
that report.*/
private void setOutgoingParameters( HashMap<String,
Object>pOutgoingParameters, Object[] pIncomingParameters )
{
// First, determine which report this is.
String reportParm = (String) pIncomingParameters[ 0 ];
if( reportParm == null )
{
return;
}
int reportNumber = -1;
// THERE ARE MANY .rptdesign FILES LISTED HERE. THIS CODE
// JUST ATTEMPTS TO FIND THE RIGHT ONE IN THE ARRAY
String[] reportPaths = ReportCriteria.cReportPaths;
for( int i = 0; i < reportPaths.length; i++ )
{
if( reportParm.equals( reportPaths[ i ] ) )
{
reportNumber = i;
break;
}
}
// DEPENDING ON WHICH REPORT WAS FOUND, WE POPULATE THE PARMS.
switch( reportNumber )
{
case -1:
break;
case 0:
populateParameters0( pOutgoingParameters, pIncomingParameters );
break;
case 1:
populateParameters1( pOutgoingParameters, pIncomingParameters );
break;
case 2:
populateParameters2( pOutgoingParameters, pIncomingParameters );
break;
case 3:
populateParameters3( pOutgoingParameters, pIncomingParameters );
break;
case 4:
populateParameters4( pOutgoingParameters, pIncomingParameters );
break;
case 5:
populateParameters5( pOutgoingParameters, pIncomingParameters );
break;
case 6:
populateParameters6( pOutgoingParameters, pIncomingParameters );
break;
case 7:
populateParameters7( pOutgoingParameters, pIncomingParameters );
break;
case 8:
populateParameters8( pOutgoingParameters, pIncomingParameters );
break;
case 9:
populateParameters9( pOutgoingParameters, pIncomingParameters );
break;
case 10:
populateParameters10( pOutgoingParameters, pIncomingParameters );
break;
case 11:
populateParameters11( pOutgoingParameters, pIncomingParameters );
break;
}
}
/** This is Report 0 */
public void populateParameters0( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11 ],
pIn[ 12 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report1 */
public void populateParameters1( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report2 */
public void populateParameters2( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report3 */
public void populateParameters3( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11 ],
pIn[ 12 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report4 */
public void populateParameters4( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateStartAndEndDiagnosisCode( pOut, pIn[ 13],
pIn[ 14 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is Report5 */
public void populateParameters5( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateStartAndEndDiagnosisCode( pOut, pIn[ 13],
pIn[ 14 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report6 */
public void populateParameters6( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateStartAndEndProcedureCode( pOut, pIn[ 13],
pIn[ 14 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report7 */
public void populateParameters7( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateStartAndEndProcedureCode( pOut, pIn[ 13],
pIn[ 14 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report8 */
public void populateParameters8( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateStartAndEndProcedureCode( pOut, pIn[ 13],
pIn[ 14 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report9 */
public void populateParameters9( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateStartAndEndDiagnosisCode( pOut, pIn[ 13],
pIn[ 14 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report10 */
public void populateParameters10( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateStartAndEndProcedureCode( pOut, pIn[ 13],
pIn[ 14 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
/** This is the Report11 */
public void populateParameters11( HashMap<String, Object> pOut, Object[]
pIn )
{
StringBuffer where = new StringBuffer( " 1 " );
where.append( populateStartAndEndClaimIID( pOut, pIn[ 1 ],
pIn[ 2 ] ) );
where.append( populateStartAndEndSystemEntryDate( pOut, pIn[ 3 ],
pIn[ 4 ] ) );
where.append( populateStartAndEndServiceStartDate( pOut, pIn[ 5 ],
pIn[ 6 ] ) );
where.append( populateStartAndEndBatchEID( pOut, pIn[ 7 ],
pIn[ 8 ] ) );
where.append( populateStartAndEndPractitionerEID( pOut, pIn[ 9 ],
pIn[ 10 ] ) );
where.append( populateStartAndEndMedicalRecordNumber( pOut, pIn[ 11],
pIn[ 12 ] ) );
where.append( populateFlags( pOut, pIn[ 17 ],
pIn[ 18 ], pIn[ 19 ], pIn[ 20 ] ) );
where.append( populateEnvironment( pOut, pIn[ 21 ],
pIn[ 22 ] ) );
where.append( populateAdditionalData( pOut, pIn[ 23 ],
pIn[ 24 ], pIn[ 25 ] ) );
pOut.put( "WHERE_CLAUSE", where.toString() );
}
private String populateStartAndEndClaimIID( HashMap<String, Object>
pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
String start = (String) pStart;
String end = (String) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( " AND ( " );
where.append( "\n" );
where.append( " (CLAIM1.CLAIM_IID = " + start + ")" );
where.append( "\n" );
where.append( " OR " );
where.append( "\n" );
where.append( " (CLAIM1.SUBMITTED_CLAIM_IID = " + start +
")" );
where.append( "\n" );
where.append( " )" );
where.append( "\n" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (" );
where.append( "\n" );
where.append( " (CLAIM1.CLAIM_IID >= " + start + ") AND
(CLAIM1.CLAIM_IID <= " + end + ") " );
where.append( "\n" );
where.append( " OR " );
where.append( "\n" );
where.append( " (CLAIM1.SUBMITTED_CLAIM_IID >= " + start + ")
AND (CLAIM1.SUBMITTED_CLAIM_IID <= " + end + ") " );
where.append( "\n" );
where.append( " )" );
}
return where.toString();
}
private String populateStartAndEndSystemEntryDate( HashMap<String,
Object> pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
Date start = (Date) pStart;
Date end = (Date) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( "\n" );
where.append( " AND (CLAIM1.SYSTEM_ENTRY_DATE = '" +
start.toString() + "' )" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (CLAIM1.SYSTEM_ENTRY_DATE >= '" +
start.toString() + "' ) AND (CLAIM1.SYSTEM_ENTRY_DATE <= '" +
end.toString() + "' ) " );
}
return where.toString();
}
private String populateStartAndEndServiceStartDate( HashMap<String,
Object> pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
Date start = (Date) pStart;
Date end = (Date) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( "\n" );
where.append( " AND (CLAIM_LINE.SERVICE_START_DATE = '" +
start.toString() + "' )" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (CLAIM_LINE.SERVICE_START_DATE >= '" +
start.toString() + "' ) AND (CLAIM_LINE.SERVICE_START_DATE <= '" +
end.toString() + "' ) " );
}
return where.toString();
}
private String populateStartAndEndBatchEID( HashMap<String, Object>
pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
String start = (String) pStart;
String end = (String) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( "\n" );
where.append( " AND (CLAIM1.BATCH_EID = '" + start + "')" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (CLAIM1.BATCH_EID >= '" + start + "') AND
(CLAIM1.BATCH_EID <= '" + end + "') " );
}
return where.toString();
}
private String populateStartAndEndPractitionerEID( HashMap<String,
Object> pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
String start = (String) pStart;
String end = (String) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( "\n" );
where.append( " AND (PRACTITIONER.PRACTITIONER_EID = '" + start +
"')" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (PRACTITIONER.PRACTITIONER_EID >= '" + start +
"') AND (PRACTITIONER.PRACTITIONER_EID <= '" + end + "') " );
}
return where.toString();
}
private String populateStartAndEndMedicalRecordNumber( HashMap<String,
Object> pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
String start = (String) pStart;
String end = (String) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( "\n" );
where.append( " AND (PATIENT.MEDICAL_RECORD_NUMBER = '" + start +
"')" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (PATIENT.MEDICAL_RECORD_NUMBER >= '" + start +
"') AND (PATIENT.MEDICAL_RECORD_NUMBER <= '" + end + "') " );
}
return where.toString();
}
private String populateStartAndEndDiagnosisCode( HashMap<String, Object>
pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
String start = (String) pStart;
String end = (String) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( "\n" );
where.append( " AND (CLAIM_LINE_DIAGNOSIS.DIAGNOSIS_CODE = '" +
start + "')" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (CLAIM_LINE_DIAGNOSIS.DIAGNOSIS_CODE >= '" +
start + "') AND (CLAIM_LINE_DIAGNOSIS.DIAGNOSIS_CODE <= '" + end + "') " );
}
return where.toString();
}
private String populateStartAndEndProcedureCode( HashMap<String, Object>
pOut, Object pStart, Object pEnd )
{
StringBuffer where = new StringBuffer();
String start = (String) pStart;
String end = (String) pEnd;
if( start == null && end == null )
{
}
else if( start != null && end == null )
{
where.append( "\n" );
where.append( " AND (CLAIM_LINE.ADJUSTED_PROCEDURE_CODE = '" + start
+ "')" );
}
else if( start != null && end != null )
{
where.append( "\n" );
where.append( " AND (CLAIM_LINE.ADJUSTED_PROCEDURE_CODE >= '" +
start + "') AND (CLAIM_LINE.ADJUSTED_PROCEDURE_CODE <= '" + end + "') " );
}
return where.toString();
}
private String populateFlags( HashMap<String, Object> pOut, Object
pProfile, Object pDeny, Object pReview, Object pInterim )
{
StringBuffer where = new StringBuffer();
String p = (String) pProfile;
String d = (String) pDeny;
String r = (String) pReview;
int pp = p.indexOf( "true" );
int dd = d.indexOf( "true" );
int rr = r.indexOf( "true" );
boolean needOR = false;
if( pp > -1 || dd > -1 || rr > -1 )
{
where.append( "\n" );
where.append( " AND " );
where.append( "\n" );
where.append( " (" );
where.append( "\n" );
where.append( " 1 = 0 " );
where.append( "\n" );
where.append( " OR " );
where.append( "\n" );
if( pp > -1 )
{
where.append( " (CLAIM_LINE_EDIT.ACTION = 'P') " );
where.append( "\n" );
needOR = true;
}
if( dd > -1 )
{
if( needOR )
{
where.append( " OR " );
where.append( "\n" );
needOR = false;
}
where.append( " (CLAIM_LINE_EDIT.ACTION = 'R') " );
where.append( "\n" );
needOR = true;
}
if( rr > -1 )
{
if( needOR )
{
where.append( " OR " );
where.append( "\n" );
needOR = false;
}
where.append( " (CLAIM_LINE_EDIT.ACTION = 'D') " );
where.append( "\n" );
}
where.append( " )" );
where.append( "\n" );
}
return where.toString();
}
private String populateEnvironment( HashMap<String, Object> pOut, Object
pLive, Object pTest )
{
StringBuffer where = new StringBuffer();
String l = (String) pLive;
String t = (String) pTest;
int ll = l.indexOf( "true" );
int tt = t.indexOf( "true" );
if( ll > -1 || tt > -1 )
{
where.append( "AND " );
where.append( "\n" );
where.append( "(" );
where.append( " 1 = 0 " );
where.append( " OR " );
if( ll > -1 )
{
where.append( " (CLAIM1.CONTEXT = 1) " );
where.append( "\n" );
}
if( tt > -1 )
{
where.append( " (CLAIM1.CONTEXT = 0) " );
where.append( "\n" );
}
where.append( ")" );
where.append( "\n" );
}
return where.toString();
}
private String populateAdditionalData( HashMap<String, Object> pOut,
Object pAccounts, Object pPlans, Object pFlags )
{
StringBuffer where = new StringBuffer();
return where.toString();
}
private void populateDatabaseConnectionParameters( IReportRunnable
pDesign )
{
ConfigurationService cs = ConfigurationServiceAccessor.getService();
String dbUrl = cs.getValue( "/framework/reporting",
"reporting.db.url", "" );
String dbUser = cs.getValue( "/framework/reporting",
"reporting.db.userid", "" );
String dbPassword = cs.getValue( "/framework/reporting",
"reporting.db.password", "" );
DesignElementHandle deh = pDesign.getDesignHandle();
SlotHandle slotHandle = deh.getSlot(
ReportDesignHandle.DATA_SOURCE_SLOT );
Iterator iter = slotHandle.iterator();
try
{
while( iter.hasNext() )
{
Object obj = iter.next();
OdaDataSourceHandle odaSrcHdl = (OdaDataSourceHandle) obj;
Iterator propIter = odaSrcHdl.getPropertyIterator();
while( propIter.hasNext() )
{
PropertyHandle propHdl = (PropertyHandle) propIter.next();
if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
"odaURL" ) )
{
propHdl.setStringValue( dbUrl );
}
else if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
"odaUser" ) )
{
propHdl.setStringValue( dbUser );
}
else if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
"odaPassword" ) )
{
propHdl.setStringValue( dbPassword );
}
}
}
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
|
|
| |
Re: How To Set the dbURL, dbUser & dbPassword dynamically (Added missing method) [message #169889 is a reply to message #169792] |
Tue, 13 June 2006 17:43  |
Eclipse User |
|
|
|
Eric,
Unless you're using Tapestry, I would rip out the Tapestry-related
parts of that. The Tapestry portions are not really necessary. I believe
I'm on Tapestry 4.0 but really, I would take that stuff out. For the
purpose of getting BIRT to accept the passed-in dbUrl, dbUserID and
dbPassword, you just need to implement the:
populateDatabaseConnectionParameters( design );
method while passing in IReportRunnable design
If you are building your BIRT without an IReportRunnable then I don't
know what to tell you since that's the only way I have built it.
Hope that helps.
Ty
|
|
|
Goto Forum:
Current Time: Sun May 11 09:15:54 EDT 2025
Powered by FUDForum. Page generated in 0.07507 seconds
|