我正在使用POJO
数据源,我使用所有业务逻辑创建Dataset
。我正在尝试从Database
获取所有数据,并希望设置特定字段。就像我有hourlyRate
然后根据员工从数据库中通过调用服务方法获取hourlyRate
。我打电话的所有地方getService()
。获得空值。
但它抛出:
org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot execute the statement.
org.eclipse.datatools.connectivity.oda.OdaException ;
java.lang.reflect.InvocationTargetException
at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.newException(ExceptionHandler.java:52)
at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.throwException(ExceptionHandler.java:108)
at org.eclipse.birt.data.engine.odaconsumer.ExceptionHandler.throwException(ExceptionHandler.java:84)
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.execute(PreparedStatement.java:586)
at org.eclipse.birt.data.engine.executor.DataSourceQuery.execute(DataSourceQuery.java:972)
at org.eclipse.birt.data.engine.impl.PreparedOdaDSQuery$OdaDSQueryExecutor.executeOdiQuery(PreparedOdaDSQuery.java:503)
at org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1208)
at org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:233)
at org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:178)
at org.eclipse.birt.report.engine.api.impl.ExtractionResults.nextResultIterator(ExtractionResults.java:157)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetPreviewer.preview(DataSetPreviewer.java:69)
at org.eclipse.birt.report.designer.data.ui.dataset.ResultSetPreviewPage$5.run(ResultSetPreviewPage.java:366)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.datatools.connectivity.oda.OdaException ;
java.lang.reflect.InvocationTargetException
at org.eclipse.birt.data.oda.pojo.impl.internal.PojoDataSetFromCustomClass.open(PojoDataSetFromCustomClass.java:194)
at org.eclipse.birt.data.oda.pojo.impl.Query.executeQuery(Query.java:126)
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaQuery.doExecuteQuery(OdaQuery.java:480)
at org.eclipse.datatools.connectivity.oda.consumer.helper.OdaQuery.executeQuery(OdaQuery.java:444)
at org.eclipse.birt.data.engine.odaconsumer.PreparedStatement.execute(PreparedStatement.java:575)
... 9 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.birt.data.oda.pojo.impl.internal.PojoDataSetFromCustomClass.open(PojoDataSetFromCustomClass.java:180)
... 13 more
BirtInvoiceDataSet类:
public class BirtInvoiceDataSet {
private IEmployeeService employee;
public BirtInvoiceDataSet() {
BirtInvoiceJavaObject birtInvoice = new BirtInvoiceJavaObject();
}
@ManagedProperty("#{employeeService}")
private IEmployeeService employeeService;
@ManagedProperty("#{timeSheetService}")
private ITimeSheetService timeSheetService;
@ManagedProperty("#{timeSheetDetailsService}")
private ITimeSheetDetailsService timeSheetDetailsService;
@ManagedProperty("#{invoiceService}")
private IInvoiceService invoiceService;
@ManagedProperty("#{projectService}")
private IProjectService projectService;
@ManagedProperty("#{projectEmployeeService}")
private IProjectEmployeeService projectEmployeeService;
@ManagedProperty("#{companyService}")
ICompanyService companyService;
public List<BirtInvoiceJavaObject> getInvoice() {
List<BirtInvoiceJavaObject> invoice = new ArrayList<BirtInvoiceJavaObject>();
try {
System.out.println("getting Dto list");
//Here I am getting null pointer exception
List<EmployeeDTO> employeeDtoList = this.getEmployeeService()
.getAllEmployees();
System.out.println("done" + "emplooyeyey" + employeeDtoList);
if (employeeDtoList == null) {
throw new MyException(ExceptionCodes.EMPLOYEE_NULL);
}
Iterator<EmployeeDTO> employeeIterator =
employeeDtoList.iterator();
while (employeeIterator.hasNext()) {
EmployeeDTO employee = employeeIterator.next();
String employeeName = employee.getEmployeeName();
ProjectEmployeeDTO emp = null;
//Dont know how to get data I have tried a lot. All jar files are available in /WEB-INF/lib folder.
//Here I am getting null pointer exception
emp = getProjectEmployeeService().getProjectIdByEmployeeId(
employee.getEmployeeId());
if (emp == null) {
continue;
}
if (employee.getIsEmployeeActive() == (byte) 0) {
continue;
}
if (emp.getProjectDTO().getProjectId() == 0)
continue;
System.out.println("Project Id"
+ emp.getProjectDTO().getProjectId());
ProjectDTO projectDto = this.getProjectService()
.getProjectById(emp.getProjectDTO()
.getProjectId());object.setEmployeeName(employeeName);
object.setHours(hour);
object.setPayment(temp.getTime());
invoice.add(objet);
Iterator<BirtInvoiceJavaObject> iterator;
public void open(Object appContext, Map<String, Object> dataSetParamValues) {
List<BirtInvoiceJavaObject> invoice1 = getInvoice();
iterator = invoice1.iterator();
}
public Object next() {
while (iterator.hasNext()) {
return iterator.next();
}
return null;
}
public void close() {
iterator = null;
}
这是我的BirtInvoiceJavaObject
pojo类
public class BirtInvoiceJavaObject implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String employeeName;
private Double total;
private Integer registrationNumber;
private Date payment;
private Integer hours;
private Integer rate;
public Date getPayment() {
return payment;
}
public void setPayment(Date payment) {
this.payment = payment;
}
public Integer getHours() {
return hours;
}
public void setHours(Integer hours) {
this.hours = hours;
}
public Integer getRegistrationNumber() {
return registrationNumber;
}
}
这是我的spring-bean.xml
<bean id="birt" class="com.agranee.timesheet.birt.BirtInvoiceDataSet">
<property name="employeeService" ref="employeeService" />
<property name="timeSheetService" ref="timeSheetService" />
<property name="timeSheetDetailsService" ref="timeSheetDetailsService" />
<property name="invoiceService" ref="invoiceService" />
<property name="projectService" ref="projectService"/>
<property name="projectEmployeeService" ref="projectEmployeeService"/>
</bean>
<bean id="projectEmployeeService" class="com.agranee.timesheet.service.ProjectEmployeeServiceImpl">
<property name="projectEmployeeDao" ref="projectEmployeeDao" />
</bean>
<bean id="projectEmployeeDao" class="com.agranee.timesheet.dao.ProjectEmployeeDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projectService" class="com.agranee.timesheet.service.ProjectServiceImpl">
<property name="projectDao" ref="projectDao" />
</bean>
<!-- User DAO Declaration -->
<bean id="projectDao" class="com.agranee.timesheet.dao.ProjectDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- User DAO Declaration -->
<!-- User Service Declaration -->
<!-- User Service Declaration -->
<bean id="companyService" class="com.agranee.timesheet.service.CompanyServiceImpl">
<property name="companyDao" ref="companyDao" />
</bean>
<!--User DAO Declaration -->
<bean id="companyDao" class="com.agranee.timesheet.dao.CompanyDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
使用过的工具: