VMware Cloud Community
admin
Immortal
Immortal

hq r11146 - in trunk/src/org/hyperic: hibernate/dialect hq/measurement/server/session

0 Kudos
1 Reply
scottmf
Enthusiast
Enthusiast

reviewed by clee

On Sep 15, 2008, at 4:36 PM, scottmf@hyperic.com wrote:

> Author: scottmf
> Date: 2008-09-15 16:36:05 -0700 (Mon, 15 Sep 2008)
> New Revision: 11146
> URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=11146
>
> Modified:
> trunk/src/org/hyperic/hibernate/dialect/HQDialect.java
> trunk/src/org/hyperic/hibernate/dialect/MySQL5InnoDBDialect.java
> trunk/src/org/hyperic/hibernate/dialect/Oracle9Dialect.java
> trunk/src/org/hyperic/hibernate/dialect/PostgreSQLDialect.java
> trunk/src/org/hyperic/hq/measurement/server/session/
> MetricAuxLogDAO.java
> Log:
> [HHQ-2436] added Expression limit to dialect mainly so that oracle
> does not blow up due to its 1000 expr limit. Updated
> MetricAuxLogDAO to respect the new rule.
>
> Modified: trunk/src/org/hyperic/hibernate/dialect/HQDialect.java
> ===================================================================
> --- trunk/src/org/hyperic/hibernate/dialect/HQDialect.java
> 2008-09-15 23:18:24 UTC (rev 11145)
> +++ trunk/src/org/hyperic/hibernate/dialect/HQDialect.java
> 2008-09-15 23:36:05 UTC (rev 11146)
> @@ -49,6 +49,13 @@
> public boolean useEamNumbers();
>
> /*
> + * Returns -1 if Max Expressions supported in the db is
> unlimited.
> + * This applies mainly to SQL in statements e.g. where ids in
> (0, 1, 2,...)
> + * Or a sequence of SQL 'and' or 'or' statements in one statement
> + */
> + public int getMaxExpressions();
> +
> + /*
> * Returns true if the database supports a multi insert stmt.
> */
> public boolean supportsMultiInsertStmt();
>
> Modified: trunk/src/org/hyperic/hibernate/dialect/
> MySQL5InnoDBDialect.java
> ===================================================================
> --- trunk/src/org/hyperic/hibernate/dialect/MySQL5InnoDBDialect.java
> 2008-09-15 23:18:24 UTC (rev 11145)
> +++ trunk/src/org/hyperic/hibernate/dialect/MySQL5InnoDBDialect.java
> 2008-09-15 23:36:05 UTC (rev 11146)
> @@ -411,4 +411,8 @@
> public boolean useEamNumbers() {
> return false;
> }
> +
> + public int getMaxExpressions() {
> + return -1;
> + }
> }
>
> Modified: trunk/src/org/hyperic/hibernate/dialect/Oracle9Dialect.java
> ===================================================================
> --- trunk/src/org/hyperic/hibernate/dialect/Oracle9Dialect.java
> 2008-09-15 23:18:24 UTC (rev 11145)
> +++ trunk/src/org/hyperic/hibernate/dialect/Oracle9Dialect.java
> 2008-09-15 23:36:05 UTC (rev 11146)
> @@ -158,4 +158,9 @@
> public boolean useEamNumbers() {
> return true;
> }
> +
> + public int getMaxExpressions() {
> + // oracle limit is 1000, but leave room for others
> + return 900;
> + }
> }
>
> Modified: trunk/src/org/hyperic/hibernate/dialect/
> PostgreSQLDialect.java
> ===================================================================
> --- trunk/src/org/hyperic/hibernate/dialect/PostgreSQLDialect.java
> 2008-09-15 23:18:24 UTC (rev 11145)
> +++ trunk/src/org/hyperic/hibernate/dialect/PostgreSQLDialect.java
> 2008-09-15 23:36:05 UTC (rev 11146)
> @@ -159,4 +159,8 @@
> public boolean useEamNumbers() {
> return true;
> }
> +
> + public int getMaxExpressions() {
> + return -1;
> + }
> }
>
> Modified: trunk/src/org/hyperic/hq/measurement/server/session/
> MetricAuxLogDAO.java
> ===================================================================
> --- trunk/src/org/hyperic/hq/measurement/server/session/
> MetricAuxLogDAO.java 2008-09-15 23:18:24 UTC (rev 11145)
> +++ trunk/src/org/hyperic/hq/measurement/server/session/
> MetricAuxLogDAO.java 2008-09-15 23:36:05 UTC (rev 11146)
> @@ -28,17 +28,19 @@
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Iterator;
> +import java.util.List;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.hibernate.Session;
> import org.hibernate.criterion.Expression;
> import org.hyperic.dao.DAOFactory;
> +import org.hyperic.hibernate.Util;
> +import org.hyperic.hibernate.dialect.HQDialect;
> import org.hyperic.hq.dao.HibernateDAO;
> import org.hyperic.hq.galerts.server.session.GalertAuxLog;
> import org.hyperic.hq.galerts.server.session.GalertAuxLogProvider;
> import org.hyperic.hq.galerts.server.session.GalertDef;
> -import org.hyperic.util.jdbc.DBUtil;
>
> public class MetricAuxLogDAO extends HibernateDAO {
> private static Log _log =
> LogFactory.getLog(MetricAuxLogDAO.class);
> @@ -64,11 +66,20 @@
> "delete from MetricAuxLogPojo where metric.id in (:ids)";
>
> Session session = getSession();
> + HQDialect dialect = Util.getHQDialect();
> + int maxExprs;
> + if (-1 == (maxExprs = dialect.getMaxExpressions())) {
> + return session.createQuery(hql)
> + .setParameterList("ids", ids)
> + .executeUpdate();
> + }
> +
> int count = 0;
> + ArrayList subIds = new ArrayList(maxExprs);
> for (Iterator it = ids.iterator(); it.hasNext(); ) {
> - ArrayList subIds = new ArrayList();
> + subIds.clear();
>
> - for (int i = 0; i<DBUtil.IN_CHUNK_SIZE &&
> it.hasNext(); i++) {
> + for (int i = 0; i<maxExprs && it.hasNext(); i++) {
> subIds.add(it.next());
> }
>
> @@ -91,11 +102,29 @@
> }
>
> Collection find(Collection mids) {
> + List rtn = new ArrayList();
> + HQDialect dialect = Util.getHQDialect();
> String sql = "from MetricAuxLogPojo p where p.metric.id in
> (:metrics)";
> -
> - return getSession().createQuery(sql)
> - .setParameterList("metrics", mids)
> - .list();
> + int maxExprs;
> + if (-1 == (maxExprs = dialect.getMaxExpressions())) {
> + return getSession()
> + .createQuery(sql).setParameterList("metrics",
> mids).list();
> + }
> + int i=0;
> + ArrayList metrics = new ArrayList(maxExprs);
> + for (Iterator it=mids.iterator(); it.hasNext(); i++) {
> + if (i != 0 && (i % maxExprs) == 0) {
> + metrics.clear();
> + metrics.add(it.next());
> + rtn.addAll(getSession()
> + .createQuery(sql)
> + .setParameterList("metrics", metrics).list());
> + } else {
> + metrics.add(it.next());
> + continue;
> + }
> + }
> + return rtn;
> }
>
> void removeAll(GalertDef def) {
>


0 Kudos