From: <ssk...@vh...> - 2005-12-09 13:43:55
|
Author: sskracic Date: 2005-12-09 14:41:22 +0100 (Fri, 09 Dec 2005) New Revision: 1043 Modified: trunk/ccm-core/src/com/arsdigita/domain/DomainQuery.java trunk/ccm-core/src/com/arsdigita/persistence/DataQuery.java trunk/ccm-core/src/com/arsdigita/persistence/DataQueryDecorator.java trunk/ccm-core/src/com/arsdigita/persistence/DataQueryImpl.java trunk/ccm-core/src/com/redhat/persistence/Cursor.java trunk/ccm-core/src/com/redhat/persistence/Engine.java trunk/ccm-core/src/com/redhat/persistence/engine/rdbms/RDBMSEngine.java Log: Somewhat hackish way to pass some additional parameters to persistence engine. This time, for performance reasons, I needed to override default result window size for a query. Added methods setOption() and getOption() to DataQeury interface, and changed few classes which are exposing this API to the com.redhat.persistence. Modified: trunk/ccm-core/src/com/arsdigita/domain/DomainQuery.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/domain/DomainQuery.java 2005-12-09 13:21:16 UTC (rev 1042) +++ trunk/ccm-core/src/com/arsdigita/domain/DomainQuery.java 2005-12-09 13:41:22 UTC (rev 1043) @@ -700,4 +700,13 @@ public void alias(String fromPrefix, String toPrefix) { m_dataQuery.alias(fromPrefix, toPrefix); } + + + public void setOption(String name, Object value) { + m_dataQuery.setOption(name, value); + } + + public Object getOption(String name) { + return m_dataQuery.getOption(name); + } } Modified: trunk/ccm-core/src/com/arsdigita/persistence/DataQuery.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/persistence/DataQuery.java 2005-12-09 13:21:16 UTC (rev 1042) +++ trunk/ccm-core/src/com/arsdigita/persistence/DataQuery.java 2005-12-09 13:41:22 UTC (rev 1043) @@ -499,6 +499,28 @@ /** + * Allows a user to pass arbitrary options to the underlying + * persistence engine. Currently, only one option is implemented + * "jdbc_resultset_windowsize" which, if set, overrides the + * default window size for the curreny query. This option must be + * set before a call to next() has been made. + * + * @param optionName The name of the option parameter + * @param value The value to assign to option parameter + */ + void setOption(String optionName, Object value); + + /** + * Examine the query configuration options. + * + * @param optionName The name of the query option parameter + * @return the object representing the value of the query + * option parameter or "null" if not set + */ + Object getOption(String optionName); + + + /** * Allows a caller to get a parameter value for a parameter that * has already been set * @@ -507,7 +529,7 @@ * parameter specified by the name or "null" if the parameter value * has not yet been set. */ - public Object getParameter(String parameterName); + Object getParameter(String parameterName); /** Modified: trunk/ccm-core/src/com/arsdigita/persistence/DataQueryDecorator.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/persistence/DataQueryDecorator.java 2005-12-09 13:21:16 UTC (rev 1042) +++ trunk/ccm-core/src/com/arsdigita/persistence/DataQueryDecorator.java 2005-12-09 13:41:22 UTC (rev 1043) @@ -233,4 +233,12 @@ protected DataQuery getDataQuery() { return m_dq; } + + public void setOption(String name, Object value) { + m_dq.setOption(name, value); + } + + public Object getOption(String name) { + return m_dq.getOption(name); + } } Modified: trunk/ccm-core/src/com/arsdigita/persistence/DataQueryImpl.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/persistence/DataQueryImpl.java 2005-12-09 13:21:16 UTC (rev 1042) +++ trunk/ccm-core/src/com/arsdigita/persistence/DataQueryImpl.java 2005-12-09 13:41:22 UTC (rev 1043) @@ -73,6 +73,8 @@ private static final String s_mapAndAddPath = "com.arsdigita.persistence.DataQueryImpl.mapAndAddPath"; + private Map m_options = new HashMap(); + private SQLParser getParser(String key, Reader reader, SQLParser.Mapper mapper) { TransactionContext ctx = m_ssn.getTransactionContext(); @@ -485,7 +487,15 @@ return m_bindings.get(parameterName); } + public void setOption(String optionName, Object value) { + m_options.put(optionName, value); + } + public Object getOption(String optionName) { + return m_options.get(optionName); + } + + public void setRange(Integer beginIndex) { setRange(beginIndex, null); } @@ -634,7 +644,9 @@ } protected Cursor execute(Signature sig, Expression expr) { - return new DataSet(m_pssn, sig, expr).getCursor(); + Cursor cursor = new DataSet(m_pssn, sig, expr).getCursor(); + cursor.setOptions(m_options); + return cursor; } public boolean next() { Modified: trunk/ccm-core/src/com/redhat/persistence/Cursor.java =================================================================== --- trunk/ccm-core/src/com/redhat/persistence/Cursor.java 2005-12-09 13:21:16 UTC (rev 1042) +++ trunk/ccm-core/src/com/redhat/persistence/Cursor.java 2005-12-09 13:41:22 UTC (rev 1043) @@ -20,6 +20,7 @@ import com.redhat.persistence.common.Path; import java.util.Map; +import java.util.HashMap; import org.apache.log4j.Logger; /** @@ -41,11 +42,17 @@ private Map m_values = null; private long m_position = 0; private boolean m_closed = false; + private Map m_options = new HashMap(); protected Cursor(DataSet ds) { m_ds = ds; } + public void setOptions(Map options) { + m_options.clear(); + m_options.putAll(options); + } + public DataSet getDataSet() { return m_ds; } @@ -55,26 +62,26 @@ } public boolean isClosed() { - return m_closed; + return m_closed; } private Object getInternal(Path path) { - if (m_values.containsKey(path)) { - return m_values.get(path); - } else { - Object o = getInternal(path.getParent()); + if (m_values.containsKey(path)) { + return m_values.get(path); + } else { + Object o = getInternal(path.getParent()); if (o == null) { return null; } - return getSession().get(o, Path.get(path.getName())); - } + return getSession().get(o, Path.get(path.getName())); + } } public Object get(Path path) { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } if (m_position <= 0) { - throw new NoRowException(this); + throw new NoRowException(this); } if (!m_rs.isFetched(path)) { @@ -89,29 +96,29 @@ } public Object get(String path) { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } return get(Path.get(path)); } public Object get() { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } return m_values.get(null); } public boolean next() { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } - if (m_position == -1) { - return false; - } + if (m_position == -1) { + return false; + } if (m_rs == null) { getSession().flush(); @@ -131,38 +138,39 @@ } protected RecordSet execute() { - return getSession().getEngine().execute(m_ds.getSignature(), - m_ds.getExpression()); + return getSession().getEngine().execute(m_ds.getSignature(), + m_ds.getExpression(), + m_options); } public boolean isBeforeFirst() { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } return m_position == 0; } public boolean isFirst() { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } return m_position == 1; } public boolean isAfterLast() { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } return m_position == -1; } public long getPosition() { - if (m_closed) { - throw new ClosedException(this); - } + if (m_closed) { + throw new ClosedException(this); + } if (m_position > 0) { return m_position; @@ -174,19 +182,19 @@ public void rewind() { close(); m_position = 0; - m_closed = false; + m_closed = false; } private void free() { if (m_rs != null) { m_rs.close(); - m_rs = null; + m_rs = null; } } public void close() { - free(); - m_closed = true; + free(); + m_closed = true; } } Modified: trunk/ccm-core/src/com/redhat/persistence/Engine.java =================================================================== --- trunk/ccm-core/src/com/redhat/persistence/Engine.java 2005-12-09 13:21:16 UTC (rev 1042) +++ trunk/ccm-core/src/com/redhat/persistence/Engine.java 2005-12-09 13:41:22 UTC (rev 1043) @@ -19,6 +19,7 @@ package com.redhat.persistence; import com.redhat.persistence.oql.Expression; +import java.util.Map; /** @@ -47,6 +48,7 @@ protected abstract void rollback(); protected abstract void commit(); protected abstract RecordSet execute(Signature sig, Expression expr); + protected abstract RecordSet execute(Signature sig, Expression expr, Map options); protected abstract long size(Expression expr); } Modified: trunk/ccm-core/src/com/redhat/persistence/engine/rdbms/RDBMSEngine.java =================================================================== --- trunk/ccm-core/src/com/redhat/persistence/engine/rdbms/RDBMSEngine.java 2005-12-09 13:21:16 UTC (rev 1042) +++ trunk/ccm-core/src/com/redhat/persistence/engine/rdbms/RDBMSEngine.java 2005-12-09 13:41:22 UTC (rev 1043) @@ -72,6 +72,7 @@ private static final Logger LOG = Logger.getLogger(RDBMSEngine.class); + public static final String OPTION_WINDOW_SIZE = "option:window_size"; private ArrayList m_operations = new ArrayList(); private HashMap m_operationMap = new HashMap(); @@ -91,6 +92,8 @@ private SQLWriter m_writer; private RDBMSProfiler m_profiler; + private Map m_options; + public RDBMSEngine(ConnectionSource source, SQLWriter writer) { this(source, writer, null); } @@ -260,6 +263,11 @@ } public RecordSet execute(Signature sig, Expression expr) { + return execute(sig, expr, Collections.EMPTY_MAP); + } + + public RecordSet execute(Signature sig, Expression expr, Map options) { + m_options = options; Select sel = new Select(this, sig, expr); if (LOG.isInfoEnabled()) { @@ -489,9 +497,17 @@ try { if (cycle != null) { cycle.beginExecute(); } - if (s_windowSize > 0) { + int windowSize = 0; + if (m_options != null + && m_options.containsKey(OPTION_WINDOW_SIZE)) { + windowSize = ( (Integer) m_options.get(OPTION_WINDOW_SIZE)).intValue(); + LOG.info("Overridden WINDOW_SIZE for query to: " + windowSize); + } else { + windowSize = s_windowSize; + } + if (windowSize > 0) { ps.setFetchDirection(ResultSet.FETCH_FORWARD); - ps.setFetchSize(s_windowSize); + ps.setFetchSize(windowSize); } if (ps.execute()) { if (cycle != null) { cycle.endExecute(0); } |