summaryrefslogtreecommitdiff
path: root/reportbuilder/java/com/sun/star/report/SDBCReportDataFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'reportbuilder/java/com/sun/star/report/SDBCReportDataFactory.java')
-rw-r--r--reportbuilder/java/com/sun/star/report/SDBCReportDataFactory.java558
1 files changed, 353 insertions, 205 deletions
diff --git a/reportbuilder/java/com/sun/star/report/SDBCReportDataFactory.java b/reportbuilder/java/com/sun/star/report/SDBCReportDataFactory.java
index bc248c29bbd9..af396d415338 100644
--- a/reportbuilder/java/com/sun/star/report/SDBCReportDataFactory.java
+++ b/reportbuilder/java/com/sun/star/report/SDBCReportDataFactory.java
@@ -35,6 +35,7 @@ import com.sun.star.beans.XPropertySet;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XIndexAccess;
import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.sdbc.XConnection;
import com.sun.star.container.XNameAccess;
@@ -44,12 +45,14 @@ import com.sun.star.sdb.CommandType;
import com.sun.star.sdb.XCompletedExecution;
import com.sun.star.sdb.XParametersSupplier;
import com.sun.star.sdb.XQueriesSupplier;
+import com.sun.star.sdb.XResultSetAccess;
import com.sun.star.sdb.XSingleSelectQueryComposer;
import com.sun.star.sdb.tools.XConnectionTools;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XParameters;
import com.sun.star.sdbc.XPreparedStatement;
import com.sun.star.uno.Exception;
+import java.util.HashMap;
import java.util.Map;
import com.sun.star.sdbc.XRowSet;
@@ -63,6 +66,8 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -72,6 +77,77 @@ import org.apache.commons.logging.LogFactory;
*/
public class SDBCReportDataFactory implements DataSourceFactory
{
+ private static final String ESCAPEPROCESSING = "EscapeProcessing";
+
+ private class RowSetProperties
+ {
+
+ final Boolean escapeProcessing;
+ final int commandType;
+ final Integer maxRows;
+ final String command;
+ final String filter;
+
+ public RowSetProperties(final Boolean escapeProcessing, final int commandType, final String command, final String filter, final Integer maxRows)
+ {
+ this.escapeProcessing = escapeProcessing;
+ this.commandType = commandType;
+ this.command = command;
+ this.filter = filter;
+ this.maxRows = maxRows;
+ }
+
+
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ final RowSetProperties other = (RowSetProperties) obj;
+ if (this.escapeProcessing != other.escapeProcessing && (this.escapeProcessing == null || !this.escapeProcessing.equals(other.escapeProcessing)))
+ {
+ return false;
+ }
+ if (this.commandType != other.commandType)
+ {
+ return false;
+ }
+ if (this.maxRows != other.maxRows && (this.maxRows == null || !this.maxRows.equals(other.maxRows)))
+ {
+ return false;
+ }
+ if ((this.command == null) ? (other.command != null) : !this.command.equals(other.command))
+ {
+ return false;
+ }
+ if ((this.filter == null) ? (other.filter != null) : !this.filter.equals(other.filter))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int hash = 3;
+ hash = 59 * hash + (this.escapeProcessing != null ? this.escapeProcessing.hashCode() : 0);
+ hash = 59 * hash + this.commandType;
+ hash = 59 * hash + (this.maxRows != null ? this.maxRows.hashCode() : 0);
+ hash = 59 * hash + (this.command != null ? this.command.hashCode() : 0);
+ hash = 59 * hash + (this.filter != null ? this.filter.hashCode() : 0);
+ return hash;
+ }
+ }
+ class ParameterDefinition
+ {
+ int parameterCount = 0;
+ private ArrayList parameterIndex = new ArrayList();
+ }
private static final Log LOGGER = LogFactory.getLog(SDBCReportDataFactory.class);
public static final String COMMAND_TYPE = "command-type";
public static final String ESCAPE_PROCESSING = "escape-processing";
@@ -94,6 +170,9 @@ public class SDBCReportDataFactory implements DataSourceFactory
private static final int HANDLE_QUERY = 4;
private static final int HANDLE_TABLE = 5;
private static final int HANDLE_SQL = 6;
+ private final Map rowSetProperties = new HashMap();
+ private final Map parameterMap = new HashMap();
+ private boolean rowSetCreated = false;
public SDBCReportDataFactory(final XComponentContext cmpCtx, final XConnection connection)
{
@@ -105,19 +184,19 @@ public class SDBCReportDataFactory implements DataSourceFactory
{
try
{
- if ( command == null )
+ if (command == null)
{
return new SDBCReportData(null);
}
int commandType = CommandType.COMMAND;
final String commandTypeValue = (String) parameters.get(COMMAND_TYPE);
- if ( commandTypeValue != null )
+ if (commandTypeValue != null)
{
- if ( commandTypeValue.equals("query") )
+ if ("query".equals(commandTypeValue))
{
commandType = CommandType.QUERY;
}
- else if ( commandTypeValue.equals("table") )
+ else if ("table".equals(commandTypeValue))
{
commandType = CommandType.TABLE;
}
@@ -126,18 +205,22 @@ public class SDBCReportDataFactory implements DataSourceFactory
commandType = CommandType.COMMAND;
}
}
- final XRowSet rowSet = createRowSet(command, commandType, parameters);
- final XPropertySet rowSetProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, rowSet);
+ final Boolean escapeProcessing = (Boolean) parameters.get(ESCAPE_PROCESSING);
+ final String filter = (String) parameters.get(UNO_FILTER);
+ final Integer maxRows = (Integer) parameters.get("MaxRows");
+ RowSetProperties rowSetProps = new RowSetProperties(escapeProcessing, commandType, command, filter, maxRows);
- final XConnectionTools tools = (XConnectionTools) UnoRuntime.queryInterface(XConnectionTools.class, connection);
- fillOrderStatement(command, commandType, parameters, tools, rowSetProp);
+ final Object[] p = createRowSet(rowSetProps,parameters);
+ final XRowSet rowSet = (XRowSet)p[0];
- if ( command.length() != 0 )
+ if (command.length() != 0 )
{
- final int oldParameterCount = fillParameter(parameters, tools, command, commandType, rowSet);
+ final ParameterDefinition paramDef = (ParameterDefinition)p[1];
+ fillParameter(parameters, rowSet,paramDef);
+ rowSetCreated = rowSetCreated && ( maxRows == null || maxRows.intValue() == 0);
final XCompletedExecution execute = (XCompletedExecution) UnoRuntime.queryInterface(XCompletedExecution.class, rowSet);
- if ( execute != null && oldParameterCount > 0 )
+ if (rowSetCreated && execute != null && paramDef.parameterCount > 0)
{
final XInteractionHandler handler = (XInteractionHandler) UnoRuntime.queryInterface(XInteractionHandler.class, m_cmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.sdb.InteractionHandler", m_cmpCtx));
execute.executeWithCompletion(handler);
@@ -147,9 +230,13 @@ public class SDBCReportDataFactory implements DataSourceFactory
rowSet.execute();
}
}
+
+ rowSetCreated = false;
return new SDBCReportData(rowSet);
- } catch ( Exception ex )
+ }
+ catch (Exception ex)
{
+ rowSetCreated = false;
throw new DataSourceException(ex.getMessage(), ex);
}
}
@@ -158,7 +245,7 @@ public class SDBCReportDataFactory implements DataSourceFactory
{
final StringBuffer order = new StringBuffer();
final int count = groupExpressions.size();
- if ( count != 0 )
+ if (count != 0)
{
try
{
@@ -196,10 +283,6 @@ public class SDBCReportDataFactory implements DataSourceFactory
}
}
}
- catch (IndexOutOfBoundsException ex)
- {
- LOGGER.error("ReportProcessing failed", ex);
- }
catch (SQLException ex)
{
LOGGER.error("ReportProcessing failed", ex);
@@ -219,14 +302,15 @@ public class SDBCReportDataFactory implements DataSourceFactory
{
tools.getClass().getMethod("getFieldsByCommandDescriptor", parameter);
return tools.getFieldsByCommandDescriptor(commandType, command, out);
- } catch ( NoSuchMethodException ex )
+ }
+ catch (NoSuchMethodException ex)
{
}
XNameAccess xFields = null;
// some kind of state machine to ease the sharing of code
int eState = FAILED;
- switch ( commandType )
+ switch (commandType)
{
case CommandType.TABLE:
eState = HANDLE_TABLE;
@@ -248,41 +332,41 @@ public class SDBCReportDataFactory implements DataSourceFactory
// go!
while ((DONE != eState) && (FAILED != eState))
{
- switch ( eState )
+ switch (eState)
{
case HANDLE_TABLE:
- {
- // initial state for handling the tables
+ {
+ // initial state for handling the tables
- // get the table objects
- final XTablesSupplier xSupplyTables = (XTablesSupplier) UnoRuntime.queryInterface(XTablesSupplier.class, connection);
- if ( xSupplyTables != null )
- {
- xObjectCollection = xSupplyTables.getTables();
+ // get the table objects
+ final XTablesSupplier xSupplyTables = (XTablesSupplier) UnoRuntime.queryInterface(XTablesSupplier.class, connection);
+ if (xSupplyTables != null)
+ {
+ xObjectCollection = xSupplyTables.getTables();
// if something went wrong 'til here, then this will be handled in the next state
// next state: get the object
}
- eState = RETRIEVE_OBJECT;
- }
- break;
+ eState = RETRIEVE_OBJECT;
+ }
+ break;
case HANDLE_QUERY:
- {
- // initial state for handling the tables
+ {
+ // initial state for handling the tables
- // get the table objects
- final XQueriesSupplier xSupplyQueries = (XQueriesSupplier) UnoRuntime.queryInterface(XQueriesSupplier.class, connection);
- if ( xSupplyQueries != null )
- {
- xObjectCollection = xSupplyQueries.getQueries();
+ // get the table objects
+ final XQueriesSupplier xSupplyQueries = (XQueriesSupplier) UnoRuntime.queryInterface(XQueriesSupplier.class, connection);
+ if (xSupplyQueries != null)
+ {
+ xObjectCollection = xSupplyQueries.getQueries();
// if something went wrong 'til here, then this will be handled in the next state
// next state: get the object
}
- eState = RETRIEVE_OBJECT;
- }
- break;
+ eState = RETRIEVE_OBJECT;
+ }
+ break;
case RETRIEVE_OBJECT:
// here we should have an object (aka query or table) collection, and are going
@@ -291,7 +375,7 @@ public class SDBCReportDataFactory implements DataSourceFactory
// next state: default to FAILED
eState = FAILED;
- if ( xObjectCollection != null && xObjectCollection.hasByName(command) )
+ if (xObjectCollection != null && xObjectCollection.hasByName(command))
{
xSupplyColumns = (XColumnsSupplier) UnoRuntime.queryInterface(XColumnsSupplier.class, xObjectCollection.getByName(command));
@@ -304,7 +388,7 @@ public class SDBCReportDataFactory implements DataSourceFactory
// next state: default to FAILED
eState = FAILED;
- if ( xSupplyColumns != null )
+ if (xSupplyColumns != null)
{
xFields = xSupplyColumns.getColumns();
// that's it
@@ -313,75 +397,78 @@ public class SDBCReportDataFactory implements DataSourceFactory
break;
case HANDLE_SQL:
- {
- String sStatementToExecute = command;
+ {
+ String sStatementToExecute = command;
- // well, the main problem here is to handle statements which contain a parameter
- // If we would simply execute a parametrized statement, then this will fail because
- // we cannot supply any parameter values.
- // Thus, we try to analyze the statement, and to append a WHERE 0=1 filter criterion
- // This should cause every driver to not really execute the statement, but to return
- // an empty result set with the proper structure. We then can use this result set
- // to retrieve the columns.
+ // well, the main problem here is to handle statements which contain a parameter
+ // If we would simply execute a parametrized statement, then this will fail because
+ // we cannot supply any parameter values.
+ // Thus, we try to analyze the statement, and to append a WHERE 0=1 filter criterion
+ // This should cause every driver to not really execute the statement, but to return
+ // an empty result set with the proper structure. We then can use this result set
+ // to retrieve the columns.
- try
- {
- final XMultiServiceFactory xComposerFac = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, connection);
+ try
+ {
+ final XMultiServiceFactory xComposerFac = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, connection);
- if ( xComposerFac != null )
+ if (xComposerFac != null)
+ {
+ final XSingleSelectQueryComposer xComposer = (XSingleSelectQueryComposer) UnoRuntime.queryInterface(XSingleSelectQueryComposer.class, xComposerFac.createInstance("com.sun.star.sdb.SingleSelectQueryComposer"));
+ if (xComposer != null)
{
- final XSingleSelectQueryComposer xComposer = (XSingleSelectQueryComposer) UnoRuntime.queryInterface(XSingleSelectQueryComposer.class, xComposerFac.createInstance("com.sun.star.sdb.SingleSelectQueryComposer"));
- if ( xComposer != null )
- {
- xComposer.setQuery(sStatementToExecute);
+ xComposer.setQuery(sStatementToExecute);
- // Now set the filter to a dummy restriction which will result in an empty
- // result set.
- xComposer.setFilter("0=1");
+ // Now set the filter to a dummy restriction which will result in an empty
+ // result set.
+ xComposer.setFilter("0=1");
- sStatementToExecute = xComposer.getQuery();
- }
+ sStatementToExecute = xComposer.getQuery();
}
- } catch ( com.sun.star.uno.Exception ex )
- {
- // silent this error, this was just a try. If we're here, we did not change sStatementToExecute,
- // so it will still be _rCommand, which then will be executed without being touched
+ }
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ // silent this error, this was just a try. If we're here, we did not change sStatementToExecute,
+ // so it will still be _rCommand, which then will be executed without being touched
}
- // now execute
- final XPreparedStatement xStatement = connection.prepareStatement(sStatementToExecute);
- // transfer ownership of this temporary object to the caller
- out[0] = (XComponent) UnoRuntime.queryInterface(XComponent.class, xStatement);
+ // now execute
+ final XPreparedStatement xStatement = connection.prepareStatement(sStatementToExecute);
+ // transfer ownership of this temporary object to the caller
+ out[0] = (XComponent) UnoRuntime.queryInterface(XComponent.class, xStatement);
- // set the "MaxRows" to 0. This is just in case our attempt to append a 0=1 filter
- // failed - in this case, the MaxRows restriction should at least ensure that there
- // is no data returned (which would be potentially expensive)
- final XPropertySet xStatementProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStatement);
- try
- {
- if ( xStatementProps != null )
- {
- xStatementProps.setPropertyValue("MaxRows", new Integer(0));
- }
- } catch ( com.sun.star.uno.Exception ex )
+ // set the "MaxRows" to 0. This is just in case our attempt to append a 0=1 filter
+ // failed - in this case, the MaxRows restriction should at least ensure that there
+ // is no data returned (which would be potentially expensive)
+ final XPropertySet xStatementProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStatement);
+ try
+ {
+ if (xStatementProps != null)
{
- // oh damn. Not much of a chance to recover, we will no retrieve the complete
- // full blown result set
+ xStatementProps.setPropertyValue("MaxRows", Integer.valueOf(0));
+ }
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ // oh damn. Not much of a chance to recover, we will no retrieve the complete
+ // full blown result set
}
- xSupplyColumns = (XColumnsSupplier) UnoRuntime.queryInterface(XColumnsSupplier.class, xStatement.executeQuery());
- // this should have given us a result set which does not contain any data, but
- // the structural information we need
+ xSupplyColumns = (XColumnsSupplier) UnoRuntime.queryInterface(XColumnsSupplier.class, xStatement.executeQuery());
+ // this should have given us a result set which does not contain any data, but
+ // the structural information we need
- // so the next state is to get the columns
- eState = RETRIEVE_COLUMNS;
- }
- break;
+ // so the next state is to get the columns
+ eState = RETRIEVE_COLUMNS;
+ }
+ break;
default:
eState = FAILED;
}
}
- } catch ( com.sun.star.uno.Exception ex )
+ }
+ catch (com.sun.star.uno.Exception ex)
{
}
return xFields;
@@ -399,15 +486,18 @@ public class SDBCReportDataFactory implements DataSourceFactory
final Object[] param = new Object[2];
param[0] = commandType;
param[1] = command;
- Method call = tools.getClass().getMethod("getComposer", parameter);
+ final Method call = tools.getClass().getMethod("getComposer", parameter);
return (XSingleSelectQueryComposer) call.invoke(tools, param);
- } catch ( NoSuchMethodException ex )
+ }
+ catch (NoSuchMethodException ex)
{
- } catch ( IllegalAccessException ex )
+ }
+ catch (IllegalAccessException ex)
{
// should not happen
// assert False
- } catch ( java.lang.reflect.InvocationTargetException ex )
+ }
+ catch (java.lang.reflect.InvocationTargetException ex)
{
// should not happen
// assert False
@@ -418,172 +508,230 @@ public class SDBCReportDataFactory implements DataSourceFactory
final XSingleSelectQueryComposer out = (XSingleSelectQueryComposer) UnoRuntime.queryInterface(XSingleSelectQueryComposer.class, factory.createInstance("com.sun.star.sdb.SingleSelectQueryAnalyzer"));
final String quote = connection.getMetaData().getIdentifierQuoteString();
String statement = command;
- switch ( commandType )
+ switch (commandType)
{
case CommandType.TABLE:
statement = "SELECT * FROM " + quote + command + quote;
break;
case CommandType.QUERY:
+ {
+ final XQueriesSupplier xSupplyQueries = (XQueriesSupplier) UnoRuntime.queryInterface(XQueriesSupplier.class, connection);
+ final XNameAccess queries = xSupplyQueries.getQueries();
+ if (queries.hasByName(command))
{
- final XQueriesSupplier xSupplyQueries = (XQueriesSupplier) UnoRuntime.queryInterface(XQueriesSupplier.class, connection);
- final XNameAccess queries = xSupplyQueries.getQueries();
- if ( queries.hasByName(command) )
+ final XPropertySet prop = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, queries.getByName(command));
+ final Boolean escape = (Boolean) prop.getPropertyValue(ESCAPEPROCESSING);
+ if (escape.booleanValue())
{
- final XPropertySet prop = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, queries.getByName(command));
- final Boolean escape = (Boolean) prop.getPropertyValue("EscapeProcessing");
- if (escape.booleanValue())
+ statement = (String) prop.getPropertyValue(UNO_COMMAND);
+ final XSingleSelectQueryComposer composer = getComposer(tools, statement, CommandType.COMMAND);
+ if (composer != null)
{
- statement = (String) prop.getPropertyValue(UNO_COMMAND);
- final XSingleSelectQueryComposer composer = getComposer(tools, statement, CommandType.COMMAND);
- if (composer != null)
+ final String order = (String) prop.getPropertyValue(UNO_ORDER);
+ if (order != null && order.length() != 0)
{
- final String order = (String) prop.getPropertyValue(UNO_ORDER);
- if (order != null && order.length() != 0)
- {
- composer.setOrder(order);
- }
- final Boolean applyFilter = (Boolean) prop.getPropertyValue(UNO_APPLY_FILTER);
- if (applyFilter.booleanValue())
+ composer.setOrder(order);
+ }
+ final Boolean applyFilter = (Boolean) prop.getPropertyValue(UNO_APPLY_FILTER);
+ if (applyFilter.booleanValue())
+ {
+ final String filter = (String) prop.getPropertyValue(UNO_FILTER);
+ if (filter != null && filter.length() != 0)
{
- final String filter = (String) prop.getPropertyValue(UNO_FILTER);
- if (filter != null && filter.length() != 0)
- {
- composer.setFilter(filter);
- }
+ composer.setFilter(filter);
}
- statement = composer.getQuery();
}
+ statement = composer.getQuery();
}
}
}
break;
+ }
case CommandType.COMMAND:
statement = command;
break;
}
out.setElementaryQuery(statement);
return out;
- } catch ( Exception e )
+ }
+ catch (Exception e)
{
}
return null;
}
- int fillParameter(final Map parameters,
- final XConnectionTools tools,
- final String command,
- final int commandType, final XRowSet rowSet)
+ private void fillParameter(final Map parameters,
+ final XRowSet rowSet,final ParameterDefinition paramDef)
throws SQLException,
UnknownPropertyException,
PropertyVetoException,
IllegalArgumentException,
WrappedTargetException
{
- int oldParameterCount = 0;
+ final ArrayList masterValues = (ArrayList) parameters.get(MASTER_VALUES);
+ if (masterValues != null && !masterValues.isEmpty())
+ {
+ final XParameters para = (XParameters) UnoRuntime.queryInterface(XParameters.class, rowSet);
+
+ for (int i = 0;
+ i < masterValues.size();
+ i++)
+ {
+ Object object = masterValues.get(i);
+ if (object instanceof BigDecimal)
+ {
+ object = ((BigDecimal) object).toString();
+ }
+ final Integer pos = (Integer)paramDef.parameterIndex.get(i);
+ para.setObject(pos + 1, object);
+ }
+ }
+ }
+
+ private final Object[] createRowSet(final RowSetProperties rowSetProps,final Map parameters)
+ throws Exception
+ {
+ final ArrayList detailColumns = (ArrayList) parameters.get(DETAIL_COLUMNS);
+ if (rowSetProperties.containsKey(rowSetProps) && detailColumns != null && !detailColumns.isEmpty() )
+ {
+ return new Object[]{ rowSetProperties.get(rowSetProps),parameterMap.get(rowSetProps)};
+ }
+
+ rowSetCreated = true;
+ final XRowSet rowSet = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, m_cmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.sdb.RowSet", m_cmpCtx));
+ final XPropertySet rowSetProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, rowSet);
+
+ rowSetProp.setPropertyValue("ActiveConnection", connection);
+ rowSetProp.setPropertyValue(ESCAPEPROCESSING, rowSetProps.escapeProcessing);
+ rowSetProp.setPropertyValue(UNO_COMMAND_TYPE, Integer.valueOf(rowSetProps.commandType));
+ rowSetProp.setPropertyValue(UNO_COMMAND, rowSetProps.command);
+
+ if (rowSetProps.filter != null)
+ {
+ rowSetProp.setPropertyValue("Filter", rowSetProps.filter);
+ rowSetProp.setPropertyValue(APPLY_FILTER, Boolean.valueOf(rowSetProps.filter.length() != 0));
+ }
+ else
+ {
+ rowSetProp.setPropertyValue(APPLY_FILTER, Boolean.FALSE);
+ }
+
+ if (rowSetProps.maxRows != null)
+ {
+ rowSetProp.setPropertyValue("MaxRows", rowSetProps.maxRows);
+ }
- final XSingleSelectQueryComposer composer = getComposer(tools, command, commandType);
- if ( composer != null )
+ final XConnectionTools tools = (XConnectionTools) UnoRuntime.queryInterface(XConnectionTools.class, connection);
+ fillOrderStatement(rowSetProps.command, rowSetProps.commandType, parameters, tools, rowSetProp);
+ final ParameterDefinition paramDef = createParameter(parameters, tools, rowSetProps, rowSet);
+
+ rowSetProperties.put(rowSetProps, rowSet);
+ parameterMap.put(rowSetProps, paramDef);
+
+ return new Object[]{rowSet,paramDef};
+ }
+
+ private ParameterDefinition createParameter(final Map parameters,
+ final XConnectionTools tools,
+ RowSetProperties rowSetProps, final XRowSet rowSet)
+ throws SQLException,
+ UnknownPropertyException,
+ PropertyVetoException,
+ IllegalArgumentException,
+ WrappedTargetException
+ {
+ final ParameterDefinition paramDef = new ParameterDefinition();
+ final XSingleSelectQueryComposer composer = getComposer(tools, rowSetProps.command, rowSetProps.commandType);
+ if (composer != null)
{
final XPropertySet rowSetProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, rowSet);
- if ( ((Boolean)rowSetProp.getPropertyValue(APPLY_FILTER)).booleanValue() )
+ if (((Boolean) rowSetProp.getPropertyValue(APPLY_FILTER)).booleanValue())
{
- composer.setFilter((String)rowSetProp.getPropertyValue("Filter"));
+ composer.setFilter((String) rowSetProp.getPropertyValue("Filter"));
}
// get old parameter count
+ final ArrayList detailColumns = (ArrayList) parameters.get(DETAIL_COLUMNS);
+ final ArrayList handledColumns = new ArrayList();
final XParametersSupplier paraSup = (XParametersSupplier) UnoRuntime.queryInterface(XParametersSupplier.class, composer);
- if ( paraSup != null )
+ if (paraSup != null)
{
final XIndexAccess params = paraSup.getParameters();
- if ( params != null )
+ if (params != null)
{
- oldParameterCount = params.getCount();
+ final int oldParameterCount = params.getCount();
+ paramDef.parameterCount = oldParameterCount;
+ if ( detailColumns != null )
+ {
+ for (int i = 0; i < oldParameterCount; i++)
+ {
+ try
+ {
+ final XPropertySet parameter = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i));
+ if (parameter != null)
+ {
+ final String name = (String) parameter.getPropertyValue("Name");
+ for (int j = 0; j < detailColumns.size(); j++)
+ {
+ if ( name.equals(detailColumns.get(j) ) )
+ {
+ handledColumns.add(name);
+ paramDef.parameterIndex.add(Integer.valueOf(i));
+ --paramDef.parameterCount;
+ break;
+ }
+ }
+ }
+ }
+ catch (IndexOutOfBoundsException ex)
+ {
+ Logger.getLogger(SDBCReportDataFactory.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ }
}
}
final ArrayList masterValues = (ArrayList) parameters.get(MASTER_VALUES);
- if ( masterValues != null && !masterValues.isEmpty() )
+ if (masterValues != null && !masterValues.isEmpty() && paramDef.parameterIndex.size() != detailColumns.size() )
{
// Vector masterColumns = (Vector) parameters.get("master-columns");
- final ArrayList detailColumns = (ArrayList) parameters.get(DETAIL_COLUMNS);
- if ( oldParameterCount < detailColumns.size() )
+
+ // create the new filter
+ final String quote = connection.getMetaData().getIdentifierQuoteString();
+ final StringBuffer oldFilter = new StringBuffer();
+ oldFilter.append(composer.getFilter());
+ if (oldFilter.length() != 0)
{
- // create the new filter
- final String quote = connection.getMetaData().getIdentifierQuoteString();
- final StringBuffer oldFilter = new StringBuffer();
- oldFilter.append(composer.getFilter());
- if ( oldFilter.length() != 0 )
- {
- oldFilter.append(" AND ");
- }
- int newParamterCounter = 1;
- for (final Iterator it = detailColumns.iterator(); it.hasNext();
- ++newParamterCounter)
+ oldFilter.append(" AND ");
+ }
+ int newParamterCounter = 1;
+ for (final Iterator it = detailColumns.iterator(); it.hasNext();
+ ++newParamterCounter)
+ {
+ final String detail = (String) it.next();
+ if ( !handledColumns.contains(detail) )
{
- final String detail = (String) it.next();
//String master = (String) masterIt.next();
oldFilter.append(quote);
oldFilter.append(detail);
oldFilter.append(quote);
oldFilter.append(" = :link_");
oldFilter.append(newParamterCounter);
- if ( it.hasNext() )
+ if (it.hasNext())
{
oldFilter.append(" AND ");
}
+ paramDef.parameterIndex.add(Integer.valueOf(newParamterCounter + paramDef.parameterCount - 1));
}
-
- composer.setFilter(oldFilter.toString());
}
- else
- oldParameterCount = 0;
+
+ composer.setFilter(oldFilter.toString());
final String sQuery = composer.getQuery();
rowSetProp.setPropertyValue(UNO_COMMAND, sQuery);
- rowSetProp.setPropertyValue(UNO_COMMAND_TYPE,
- new Integer(CommandType.COMMAND));
-
- final XParameters para = (XParameters) UnoRuntime.queryInterface(XParameters.class, rowSet);
-
- for (int i = 0;
- i < masterValues.size();
- i++)
- {
- Object object = masterValues.get(i);
- if ( object instanceof BigDecimal )
- {
- object = ((BigDecimal) object).toString();
- }
- para.setObject(oldParameterCount + i + 1, object);
- }
+ rowSetProp.setPropertyValue(UNO_COMMAND_TYPE,Integer.valueOf(CommandType.COMMAND));
}
}
-
- return oldParameterCount;
- }
-
- private final XRowSet createRowSet(final String command,
- final int commandType, final Map parameters)
- throws Exception
- {
- final XRowSet rowSet = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, m_cmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.sdb.RowSet", m_cmpCtx));
- final XPropertySet rowSetProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, rowSet);
-
- rowSetProp.setPropertyValue("ActiveConnection", connection);
- final Boolean escapeProcessing = (Boolean)parameters.get(ESCAPE_PROCESSING);
- rowSetProp.setPropertyValue("EscapeProcessing", escapeProcessing);
- rowSetProp.setPropertyValue(UNO_COMMAND_TYPE, new Integer(commandType));
- rowSetProp.setPropertyValue(UNO_COMMAND, command);
-
- final String filter = (String) parameters.get(UNO_FILTER);
- if ( filter != null )
- {
- rowSetProp.setPropertyValue("Filter", filter);
- rowSetProp.setPropertyValue(APPLY_FILTER, Boolean.valueOf(filter.length() != 0));
- }
- else
- {
- rowSetProp.setPropertyValue(APPLY_FILTER, Boolean.FALSE);
- }
- return rowSet;
+ return paramDef;
}
void fillOrderStatement(final String command,
@@ -598,16 +746,16 @@ public class SDBCReportDataFactory implements DataSourceFactory
NoSuchElementException
{
final StringBuffer order = new StringBuffer(getOrderStatement(commandType, command, (ArrayList) parameters.get(GROUP_EXPRESSIONS)));
- if ( order.length() > 0 && commandType != CommandType.TABLE )
+ if (order.length() > 0 && commandType != CommandType.TABLE)
{
String statement = command;
final XSingleSelectQueryComposer composer = getComposer(tools, command, commandType);
- if ( composer != null )
+ if (composer != null)
{
statement = composer.getQuery();
composer.setQuery(statement);
final String sOldOrder = composer.getOrder();
- if ( sOldOrder.length() > 0 )
+ if (sOldOrder.length() > 0)
{
order.append(',');
order.append(sOldOrder);
@@ -617,15 +765,15 @@ public class SDBCReportDataFactory implements DataSourceFactory
}
else
{
- if ( commandType == CommandType.QUERY )
+ if (commandType == CommandType.QUERY)
{
final XQueriesSupplier xSupplyQueries = (XQueriesSupplier) UnoRuntime.queryInterface(XQueriesSupplier.class, connection);
final XNameAccess queries = xSupplyQueries.getQueries();
- if ( queries.hasByName(command) )
+ if (queries.hasByName(command))
{
final XPropertySet prop = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, queries.getByName(command));
- final Boolean escape = (Boolean) prop.getPropertyValue("EscapeProcessing");
- rowSetProp.setPropertyValue("EscapeProcessing", escape);
+ final Boolean escape = (Boolean) prop.getPropertyValue(ESCAPEPROCESSING);
+ rowSetProp.setPropertyValue( ESCAPEPROCESSING, escape);
final String queryCommand = (String) prop.getPropertyValue(UNO_COMMAND);
statement = "SELECT * FROM (" + queryCommand + ")";
}
@@ -637,7 +785,7 @@ public class SDBCReportDataFactory implements DataSourceFactory
}
}
rowSetProp.setPropertyValue(UNO_COMMAND, statement);
- rowSetProp.setPropertyValue(UNO_COMMAND_TYPE, new Integer(CommandType.COMMAND));
+ rowSetProp.setPropertyValue(UNO_COMMAND_TYPE, Integer.valueOf(CommandType.COMMAND));
}
rowSetProp.setPropertyValue("Order", order.toString());
}