Using the DAS Java API is very easy. Below we will describe the steps needed to create a simple job application.
Step 1: Write the Source Code
Copy the code listed below into the a text file named SimpleJob.java.
import java.io.*;
import java.lang.*;
import ecrion.das.*;
import java.net.*;
import java.util.*;
public class SampleJob
{
public static void main(String[] args)
{
try
{
// create parameters for the rendering operation
DASJobParameters rp = new DASJobParameters();
// create a new engine
Engine eng = new Engine();
//Make sure that this path is valid!!!
String jobPath = "C:\\Program Files\\Ecrion\\Data Aggregation Server 2010\\Samples\\Job Samples\\\SimpleJob.dax";
InputStream inputStream = new FileInputStream(jobPath);
//Make sure that this path is valid!!
String databasePath = "C:\\Program Files\\Ecrion\\Data Aggregation Server 2010\\Samples\\Database Samples\\emp.mdb";
String connectionString = new String("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") + databasePath;
//override connection string
rp.JobPropertyVector = new Vector();
rp.JobPropertyVector.add(new JobProperty("con1", "connection-string", connectionString));
// create an output stream
OutputStream outputStream = new FileOutputStream("C:\\jobOut.xml");
// render
eng.Aggregate(inputStream, outputStream, rp);
// remember to close the streams
inputStream.close();
outputStream.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
};
}
}
Step 2: Compile the Code File
First locate our .jar file. It should be in C:\Program Files\Ecrion\Data Aggregation Server 2010\Java under a default installation. We'll assume that this is the case and provide the console commands under this assumption. If you have the .jar under a different path you can adapt the commands to use that location. Also make sure that you have the Java Development Kit installed. To check, search for a directory under C:\Program Files\Java that starts with the string "jdk".
Open a console, navigate using the cd command to the location where you saved your SimpleJob.java file and type the following:
> javac -cp ".;C:\Program Files\Ecrion\Data Aggregation Server 2010\Java\Ecrion.DAS.Java.jar" SimpleJob.java
Step 3: Run the Program
Running the program is done using the java command.
> java -cp ".;C:\Program Files\Ecrion\Data Aggregation Server 2010\Java\Ecrion.DAS.Java.jar" SimpleJob
The last command should have no output. If you have the proper write permissions on your C:\ drive, a file named jobOut.xml should appear at that location.
This concludes our "Simple Job" example. More examples can be found in your Samples folder. Read on below if you want a step by step explanation of the code.
Understanding the Code
First is creating our Engine object:
// create a new engine
Engine eng = new Engine();
Next, we'll need an input job stream. In our example, we will use a FileInputStream constructed from a hard-coded string.
//Make sure that this path is valid!!!
String jobPath = "C:\\Program Files\\Ecrion\\Data Aggregation Server 2010\\Samples\\Job Samples\\SimpleJob.dax";
InputStream inputStream = new FileInputStream(jobPath);
Set some job parameters. Job Parameters are used to overwrite some key resources in your job, like connection-strings, web-service urls etc. The
purpose is to use the same job with various data sources, or to hide some critical aspects of your jobs (like username and password from xml job).
In this sample we will overwrite the connection string from job <das:database-connection> element with the id conn1.
Now we'll create an output stream (we'll use a FileOutputStream in this example) and call the Aggregate() method on our Engine object.
// create an output stream
OutputStream outputStream = new FileOutputStream("C:\\jobOut.xml");
// render
eng.Aggregate(inputStream, outputStream, rp);
Also, remember to close the streams after rendering:
// remember to close the streams
inputStream.close();
outputStream.close();