Author: tdraier
Date: Mon Jun 25 15:23:11 2007
New Revision: 17755
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17755&repname=
=3Djahia
Log:
optimized request with cast (JAHIA-1979) ( backport 17546, 17601 )
Modified:
trunk/core/src/java/org/jahia/hibernate/dao/JahiaFieldsDataDAO.java
Modified: trunk/core/src/java/org/jahia/hibernate/dao/JahiaFieldsDataDAO.ja=
va
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/hibernate/dao/JahiaFieldsDataDAO.java&rev=3D17755&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/hibernate/dao/JahiaFieldsDataDAO.java (or=
iginal)
+++ trunk/core/src/java/org/jahia/hibernate/dao/JahiaFieldsDataDAO.java Mon=
Jun 25 15:23:11 2007
@@ -31,8 +31,11 @@
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.HibernateTemplate;
+import org.hibernate.SQLQuery;
+import org.hibernate.Hibernate;
=
import java.util.*;
+import java.sql.SQLException;
=
/**
* Created by IntelliJ IDEA.
@@ -816,6 +819,14 @@
return template.find(hql, new Object[]{ownerKey.getIDInType(), own=
erKey.getType()});
}
=
+ public List findStagedFieldsByMetadataOwner(JahiaObjectPK ownerKey) {
+ String hql =3D "select f.comp_id.id from JahiaFieldsData f where f=
.metadataOwner.comp_id.id=3D? AND f.metadataOwner.comp_id.type=3D? AND f.co=
mp_id.workflowState>1";
+ final HibernateTemplate template =3D getHibernateTemplate();
+ template.setCacheQueries(false);
+ template.setFlushMode(HibernateTemplate.FLUSH_NEVER);
+ return template.find(hql, new Object[]{ownerKey.getIDInType(), own=
erKey.getType()});
+ }
+
public JahiaFieldsData loadPublishedField(Integer containerId) {
String queryString =3D "from JahiaFieldsData c where c.comp_id.id=
=3D? and c.comp_id.workflowState=3D1";
final HibernateTemplate template =3D getHibernateTemplate();
@@ -1037,41 +1048,97 @@
}
=
private static boolean implicitDataConversion =3D true;
+ private static Boolean isMySQLDB =3D null;
=
public Integer[] getSubPageId(Integer fieldId, Integer workflowState) {
final HibernateTemplate template =3D getHibernateTemplate();
template.setCacheQueries(true);
template.setFlushMode(HibernateTemplate.FLUSH_NEVER);
if (implicitDataConversion) {
- String hql =3D "select distinct f.value, p.pageType, f.comp_id=
.workflowState from JahiaFieldsData f, JahiaPagesData p where f.comp_id.id=
=3D? and f.type=3D"+ContentFieldTypes.PAGE+ " and " +
- "f.comp_id.versionId>-1 and f.comp_id.workflowState>0 =
and f.comp_id.workflowState<=3D? and p.comp_id.workflowState>0 and p.comp_i=
d.workflowState<=3D? and f.value=3Dp.comp_id.id order by f.comp_id.workflow=
State desc";
+ String hql;
try {
- List list =3D template.find(hql, new Object[]{fieldId, wor=
kflowState, workflowState});
- if (!list.isEmpty()) {
- Object[] objects =3D (Object[]) list.iterator().next();
- String s =3D (String) objects[0];
- Integer i =3D (Integer) objects[1];
- if (s !=3D null) {
- try {
- return new Integer[] { new Integer(s), i };
- } catch (NumberFormatException e) {
+ if (isMySQLDB =3D=3D null) {
+ isMySQLDB =3D new Boolean(getSession().connection()
+ .getMetaData()
+ .getDatabaseProductName()
+ .toLowerCase()
+ .indexOf("mysql") >=3D 0);
+ }
+ //Todo remove that test when going to upper hibernate vers=
ion by an extending dialect if hibernate bug not close around mysql cast er=
ror
+ if (isMySQLDB.booleanValue()) {
+ SQLQuery sqlQuery =3D
+ getSession().createSQLQuery(
+ "select distinct jahiafield0_.value_ja=
hia_fields_data as col_0_0_, " +
+ "jahiapages1_.pagetype_jahia_pages_dat=
a as col_1_0_, jahiafield0_.workflow_state as col_2_0_ " +
+ "from jahia_fields_data jahiafield0_, =
jahia_pages_data jahiapages1_ " +
+ "where jahiafield0_.id_jahia_fields_da=
ta=3D? and jahiafield0_.type_jahia_fields_data=3D " +
+ ContentFieldTypes.PAGE +
+ " and jahiafield0_.version_id>-1 and j=
ahiafield0_.workflow_state>0 " +
+ "and jahiafield0_.workflow_state<=3D? =
and jahiapages1_.workflow_state>0 " +
+ "and jahiapages1_.workflow_state<=3D? =
" +
+ "and cast(jahiafield0_.value_jahia_fie=
lds_data as unsigned)=3Djahiapages1_.id_jahia_pages_data " +
+ "order by jahiafield0_.workflow_state =
desc;");
+ sqlQuery.setInteger(0, fieldId.intValue());
+ sqlQuery.setInteger(1, workflowState.intValue());
+ sqlQuery.setInteger(2, workflowState.intValue());
+ sqlQuery.addScalar("col_0_0_", Hibernate.STRING);
+ sqlQuery.addScalar("col_1_0_", Hibernate.INTEGER);
+ sqlQuery.addScalar("col_2_0_", Hibernate.INTEGER);
+ List list =3D sqlQuery.list();
+ if (!list.isEmpty()) {
+ Object[] objects =3D (Object[]) list.iterator().ne=
xt();
+ String s =3D (String) objects[0];
+ Integer i =3D (Integer) objects[1];
+ if (s !=3D null) {
+ try {
+ return new Integer[]{new Integer(s), i};
+ } catch (NumberFormatException e) {
+ }
+ }
+ }
+ }
+ else {
+ hql =3D
+ "select distinct f.value, p.pageType, f.comp_i=
d.workflowState from JahiaFieldsData f, JahiaPagesData p where f.comp_id.id=
=3D? and f.type=3D" +
+ ContentFieldTypes
+ .PAGE +
+ " and f.comp_id.versionId>-1 and=
f.comp_id.workflowState>0 and f.comp_id.workflowState<=3D? and p.comp_id.w=
orkflowState>0 and p.comp_id.workflowState<=3D? and cast(f.value as integer=
)=3Dp.comp_id.id order by f.comp_id.workflowState desc";
+ try {
+
+ List list =3D template.find(hql, new Object[]{fiel=
dId, workflowState, workflowState});
+ if (!list.isEmpty()) {
+ Object[] objects =3D (Object[]) list.iterator(=
).next();
+ String s =3D (String) objects[0];
+ Integer i =3D (Integer) objects[1];
+ if (s !=3D null) {
+ try {
+ return new Integer[]{new Integer(s), i=
};
+ } catch (NumberFormatException e) {
+ }
+ }
}
+ } catch (DataAccessException e) {
+ implicitDataConversion =3D false;
}
}
- } catch (DataAccessException e) {
- implicitDataConversion =3D false;
+ } catch (SQLException e) {
+ logger.error(e);
}
}
if (!implicitDataConversion) {
- String hql =3D "select distinct f.value, f.comp_id.workflowSta=
te from JahiaFieldsData f where f.comp_id.id=3D? and f.type=3D"+ContentFiel=
dTypes.PAGE+ " and " +
- "f.comp_id.versionId>-1 and f.comp_id.workflowState>0 =
and f.comp_id.workflowState<=3D? order by f.comp_id.workflowState desc";
+ String hql =3D
+ "select distinct f.value, f.comp_id.workflowState from=
JahiaFieldsData f where f.comp_id.id=3D? and f.type=3D" +
+ ContentFieldTypes
+ .PAGE +
+ " and " +
+ "f.comp_id.versionId>-1 and f.comp_id.wo=
rkflowState>0 and f.comp_id.workflowState<=3D? order by f.comp_id.workflowS=
tate desc";
List list =3D template.find(hql, new Object[]{fieldId, workflo=
wState});
if (!list.isEmpty()) {
Object[] objects =3D (Object[]) list.iterator().next();
String s =3D (String) objects[0];
if (s !=3D null) {
try {
- return new Integer[] { new Integer(s), new Integer=
(-1) };
+ return new Integer[]{new Integer(s), new Integer(-=
1)};
} catch (NumberFormatException e) {
}
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list