[Suiviobsmer-commits] r495 - in trunk: . wao-business wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/xmi wao-business/src/test/java/fr/ifremer/wao
Author: fdesbois Date: 2010-06-08 10:01:43 +0000 (Tue, 08 Jun 2010) New Revision: 495 Log: - Use last ToPIA and EUGene - Add WaoQueryBuilder to centralize filtering with TopiaQuery - Refactor some queries using QueryBuilder + last TopiaQuery methods Added: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java Modified: trunk/pom.xml trunk/wao-business/pom.xml trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java trunk/wao-business/src/main/xmi/wao.properties trunk/wao-business/src/test/java/fr/ifremer/wao/ErrorDB1_0Test.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-06-07 19:43:01 UTC (rev 494) +++ trunk/pom.xml 2010-06-08 10:01:43 UTC (rev 495) @@ -235,10 +235,10 @@ <!-- libraries version --> <i18n.version>1.2.2</i18n.version> <nuitonutils.version>1.2.2</nuitonutils.version> - <topia.version>2.3.3</topia.version> - <eugene.version>2.0.1</eugene.version> - <!--<topia.version>2.4-SNAPSHOT</topia.version>--> - <!--<eugene.version>2.0.2-SNAPSHOT</eugene.version>--> + <!--<topia.version>2.3.3</topia.version>--> + <!--<eugene.version>2.0.1</eugene.version>--> + <topia.version>2.4-SNAPSHOT</topia.version> + <eugene.version>2.0.2-SNAPSHOT</eugene.version> <tapestry.version>5.1.0.5</tapestry.version> </properties> Modified: trunk/wao-business/pom.xml =================================================================== --- trunk/wao-business/pom.xml 2010-06-07 19:43:01 UTC (rev 494) +++ trunk/wao-business/pom.xml 2010-06-08 10:01:43 UTC (rev 495) @@ -135,9 +135,9 @@ <defaultPackage>fr.ifremer.wao</defaultPackage> <templates> org.nuiton.topia.generator.TopiaMetaTransformer, - org.nuiton.topia.generator.BeanTransformer, + org.nuiton.eugene.java.JavaBeanTransformer, org.nuiton.topia.generator.ServiceTransformer, - org.nuiton.topia.generator.InterfaceTransformer + org.nuiton.eugene.java.JavaInterfaceTransformer </templates> </configuration> <goals> Added: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-08 10:01:43 UTC (rev 495) @@ -0,0 +1,636 @@ +package fr.ifremer.wao; + +import fr.ifremer.wao.bean.*; +import fr.ifremer.wao.entity.*; +import org.apache.commons.lang.StringUtils; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.PeriodDates; + +import java.util.*; + +/** + * Created: 7 juin 2010 + * + * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ + */ +public class WaoQueryBuilder { + + public static String ALIAS_SAMPLE_ROW = "SR"; + + public static String ALIAS_CONTACT = "C"; + + public static String ALIAS_FISHING_ZONE = "FZ"; + + public static String ALIAS_ELLIGIBLE_BOAT = "EB"; + + public static String ALIAS_BOAT = "B"; + + String sampleRowProperty; + + String fishingZoneProperty; + + String boatProperty; + + String contactProperty; + + String elligibleBoatProperty; + + protected TopiaQuery query; + + public WaoQueryBuilder(Class<?> entityClass) { + initialize(entityClass); + } + + public WaoQueryBuilder(TopiaQuery query) { + this.query = query; + } + + private void initialize(Class<?> entityClass) { + if (Boat.class.isAssignableFrom(entityClass)) { + boatProperty = ALIAS_BOAT; + query = createQuery(Boat.class, boatProperty); + + } else if (SampleRow.class.isAssignableFrom(entityClass)) { + sampleRowProperty = ALIAS_SAMPLE_ROW; + query = createQuery(SampleRow.class, sampleRowProperty); + + } else if (FishingZone.class.isAssignableFrom(entityClass)) { + fishingZoneProperty = ALIAS_FISHING_ZONE; + query = createQuery(FishingZone.class, fishingZoneProperty); + + } else if (Contact.class.isAssignableFrom(entityClass)) { + contactProperty = ALIAS_CONTACT; + query = createQuery(Contact.class, contactProperty); + } + } + + protected TopiaQuery createQuery(Class<?> entityClass, String alias) { + return new TopiaQuery((Class<? extends TopiaEntity>)entityClass, alias); + } + + public TopiaQuery toQuery() { + return getQuery(); + } + + public TopiaQuery getQuery() { + return query; + } + +// public void setQuery(TopiaQuery query) { +// this.query = query; +// } +// +// public void setSampleRowProperty(String sampleRowProperty) { +// this.sampleRowProperty = sampleRowProperty; +// } +// +// public void setFishingZoneProperty(String fishingZoneProperty) { +// this.fishingZoneProperty = fishingZoneProperty; +// } +// +// public void setBoatProperty(String boatProperty) { +// this.boatProperty = boatProperty; +// } +// +// public void setContactProperty(String contactProperty) { +// this.contactProperty = contactProperty; +// } +// +// public void setElligibleBoatProperty(String elligibleBoatProperty) { +// this.elligibleBoatProperty = elligibleBoatProperty; +// } + + public String getSectorNameProperty() { + String result = getProperty(fishingZoneProperty, + FishingZone.SECTOR_NAME); + return result; + } + + public String getFacadeNameProperty() { + String result = getProperty(fishingZoneProperty, + FishingZone.FACADE_NAME); + return result; + } + + public String getFishingZoneSampleRowProperty() { + String result = getProperty(fishingZoneProperty, + FishingZone.SAMPLE_ROW); + return result; + } + + public String getCodeDCF5Property() { + String result = getProperty(sampleRowProperty, + SampleRow.PROFESSION, + Profession.CODE_DCF5); + return result; + } + + public String getProgramNameProperty() { + String result = getProperty(sampleRowProperty, + SampleRow.PROGRAM_NAME); + return result; + } + + public String getSampleRowBeginProperty() { + String result = getProperty(sampleRowProperty, + SampleRow.PERIOD_BEGIN); + return result; + } + + public String getSampleRowEndProperty() { + String result = getProperty(sampleRowProperty, + SampleRow.PERIOD_END); + return result; + } + + public String getSampleRowCompanyProperty() { + String result = getProperty(sampleRowProperty, + SampleRow.COMPANY); + return result; + } + + public String getBoatImmatriculationProperty() { + String result = getProperty(boatProperty, + Boat.IMMATRICULATION); + return result; + } + + public String getBoatNameProperty() { + String result = getProperty(boatProperty, + Boat.NAME); + return result; + } + + public String getBoatDistrictProperty() { + String result = getProperty(boatProperty, + Boat.DISTRICT_CODE); + return result; + } + + public String getBoatElligibleProperty() { + String result = getProperty(boatProperty, + Boat.ELLIGIBLE_BOAT); + return result; + } + + public String getBoatOrderProperty(String order) { + String result = getProperty(boatProperty, + order); + return result; + } + + public String getContactObserverProperty() { + String result = getProperty(contactProperty, + Contact.OBSERVER); + return result; + } + + public String getContactSampleRowProperty() { + String result = getProperty(contactProperty, + Contact.SAMPLE_ROW); + return result; + } + + public String getContactBoatProperty() { + String result = getProperty(contactProperty, + Contact.BOAT); + return result; + } + + public String getMammalsObservationProperty() { + String result = getProperty(contactProperty, + Contact.MAMMALS_OBSERVATION); + return result; + } + + public String getMammalsCaptureProperty() { + String result = getProperty(contactProperty, + Contact.MAMMALS_CAPTURE); + return result; + } + + public String getValidationProgramProperty() { + String result = getProperty(contactProperty, + Contact.VALIDATION_PROGRAM); + return result; + } + + public String getValidationCompanyProperty() { + String result = getProperty(contactProperty, + Contact.VALIDATION_COMPANY); + return result; + } + + public String getContactStateProperty() { + String result = getProperty(contactProperty, + Contact.STATE); + return result; + } + + public String getContactCreateDateProperty() { + String result = getProperty(contactProperty, + Contact.TOPIA_CREATE_DATE); + return result; + } + +// public String getContactBeginTideProperty() { +// String result = getProperty(contactProperty, +// Contact.TIDE_BEGIN_DATE); +// return result; +// } +// +// public String getElligibleBoatProperty() { +// String result = getProperty(elligibleBoatProperty, +// ElligibleBoat.BOAT); +// return result; +// } + + public String getElligibleSampleRowProperty() { + String result = getProperty(elligibleBoatProperty, + ElligibleBoat.SAMPLE_ROW); + return result; + } + + public String getElligibleCompanyActiveProperty() { + String result = getProperty(elligibleBoatProperty, + ElligibleBoat.COMPANY_ACTIVE); + return result; + } + + public String getElligibleGlobalActiveProperty() { + String result = getProperty(elligibleBoatProperty, + ElligibleBoat.GLOBAL_ACTIVE); + return result; + } + + private String getProperty(String... properties) { + // Add property cache managment + return TopiaQuery.getProperty(properties); + } + + public WaoQueryBuilder applyUserFilter(TopiaQuery query, UserFilter filter) { + Integer startIndex = filter.getStartIndex(); + Integer endIndex = filter.getEndIndex(); + + if (startIndex != null && endIndex != null) { + query.setLimit(startIndex, endIndex); + } + return this; + } + + /** + * Prepare the {@code query} for fishingZone filters. Need to know the + * FishingZone {@code main} alias for the query. + * + * @return the query with elements added + * @since 1.1.2 + */ + public WaoQueryBuilder applySimpleFishingZoneFilter(SamplingFilter filter, TopiaQuery query) { + + // need fishingZoneProperty + + if (query == null) { + query = this.query; + } + + String sectorName = filter.getSectorName(); + String facadeName = filter.getFacadeName(); + + if (StringUtils.isNotEmpty(sectorName)) { + query.addEquals(getSectorNameProperty(), sectorName); + } else if (StringUtils.isNotEmpty(facadeName)) { + query.addEquals(getFacadeNameProperty(), facadeName); + } + return this; + } + + public WaoQueryBuilder applyFishingZoneFilter(SamplingFilter filter) { + + Company company = filter.getCompany(); + String programName = filter.getProgramName(); + + if (company != null || StringUtils.isNotEmpty(programName)) { + + sampleRowProperty = ALIAS_SAMPLE_ROW; + + query.addFrom(SampleRow.class, sampleRowProperty). + addWhere(new StringBuilder(sampleRowProperty). + append(" IN elements("). + append(getFishingZoneSampleRowProperty()). + append(")"). + toString() + ); + } + + if (company != null) { + query.addEquals(getSampleRowCompanyProperty(), company); + } + + if (programName != null) { + query.addEquals(getProgramNameProperty(), programName); + } + return this; + } + + /** + * Prepare the {@code query} with sampleRow filters. Need the {@code main} + * alias to set SampleRow properties. The zoneAlias can also be used if + * the query already have the fishingZone. + * + * @return the query with filtered elements added + */ + public WaoQueryBuilder applySamplingFilter(SamplingFilter filter) { + + // need sampleRowProperty, may have fishingZoneProperty + + SampleRow sampleRow = filter.getSampleRow(); + String codeDCF5 = filter.getCodeDCF5(); + String programName = filter.getProgramName(); + PeriodDates period = filter.getPeriod(); + Date fromDate = filter.getFromDate(); + Company company = filter.getCompany(); + Integer nbMonthsFinishedFromToday = filter.getNbMonthFinishedFromToday(); + + // SampleRow filter depends on SampleRow OR sectorName OR facadeName + // sectorName and facadeName are the two FishingZone filters known + if (sampleRow != null) { + query.addEquals(sampleRowProperty, sampleRow); + + // FishingZone filter (sectorName OR facadeName) + } else if (StringUtils.isNotEmpty(filter.getSectorName()) || + StringUtils.isNotEmpty(filter.getFacadeName())) { + + // If zoneAlias is set, no need to create a subquery to link + // with fishingZone + if (fishingZoneProperty != null) { + applySimpleFishingZoneFilter(filter, null); + } else { + // Otherwise, create a subquery to retrieve sampleRows + // corresponding to fishingZone filters + String sampleRowSubAlias = "SR2"; + String sampleRowFishingZoneProperty = + TopiaQuery.getProperty(sampleRowSubAlias, SampleRow.FISHING_ZONE); + + fishingZoneProperty = ALIAS_FISHING_ZONE; + + TopiaQuery subquery = createQuery(SampleRow.class, sampleRowSubAlias). + setSelect(sampleRowSubAlias).addDistinct(). + addLeftJoin(sampleRowFishingZoneProperty, fishingZoneProperty, + false); + +// addFrom(FishingZone.class, fishingZoneProperty). +// // FIXME : for ToPIA 2.4 : replace by addInElements +// addWhere(new StringBuilder(fishingZoneProperty). +// append(" IN elements("). +// append(sampleRowfishingZoneProperty). +// append(")"). +// toString() +// ); + // addInElements(fishingZoneProperty, sampleRowfishingZoneProperty); + + // Apply filter for fishingZone on subQuery + applySimpleFishingZoneFilter(filter, subquery); + + // FIXME : for ToPIA 2.4 : replace by addSubQuery +// query.addWhere(new StringBuilder(sampleRowProperty). +// append(" IN ("). +// append(subquery.fullQuery()). +// append(")"). +// toString() +// ).addParams(subquery.getParams()); + query.addSubQuery(sampleRowProperty + " IN (?)", subquery); + } + } + + // CodeDCF5 filter + if (codeDCF5 != null) { + query.addWhere(getCodeDCF5Property(), TopiaQuery.Op.LIKE, "%" + codeDCF5 + "%"); + } + + // Program filter + if (programName != null) { + query.addEquals(getProgramNameProperty(), programName); + } + + // Period filter on sampleRow dates + if (period != null) { + period.initDayOfMonthExtremities(); + query.addWhere(getSampleRowBeginProperty(), TopiaQuery.Op.LT, period.getThruDate()). + addWhere(getSampleRowEndProperty(), TopiaQuery.Op.GT, period.getFromDate()); + } else if (fromDate != null) { + query.addWhere(getSampleRowEndProperty(), TopiaQuery.Op.GE, fromDate); + } + + // Company + if (company != null) { + query.addEquals(getSampleRowCompanyProperty(), company); + } + + if (nbMonthsFinishedFromToday != null) { + // Only rows which are not finished will be kept + Calendar calendar = Calendar.getInstance(); + calendar.setTime(WaoUtils.getCurrentDate()); + calendar.add(Calendar.MONTH, nbMonthsFinishedFromToday); + query.addWhere(getSampleRowEndProperty(), TopiaQuery.Op.GE, calendar.getTime()); + } + return this; + } + + public WaoQueryBuilder applySimpleBoatFilter(BoatFilter filter) { + + // need boatProperty + + String boatName = filter.getBoatName(); + String boatDistrictCode = filter.getBoatDistrictCode(); + Integer boatImmatriculation = filter.getBoatImmatriculation(); + + // Limit + applyUserFilter(query, filter); + + if (StringUtils.isNotEmpty(boatName)) { + query.addWhere(getBoatNameProperty(), TopiaQuery.Op.LIKE, boatName.trim() + "%"); + } + + if (StringUtils.isNotEmpty(boatDistrictCode)) { + query.addEquals(getBoatDistrictProperty(), boatDistrictCode.trim()); + } + + if (boatImmatriculation != null) { + query.addEquals(getBoatImmatriculationProperty(), boatImmatriculation); + } + + return this; + } + + /** + * Apply {@code filter} on current query. Used to retrieve boats filtered. + * Need boatProperty to be defined using for example new WaoQueryBuilder(Boat.class) + * + * @param filter BoatFilter to apply on the query + * @return the WaoQueryBuilder + */ + public WaoQueryBuilder applyBoatFilter(BoatFilter filter) { + + //boatProperty = query.getMainAlias(); + + Company company = filter.getCompany(); + String orderBy = filter.getOrderBy(); + + applySimpleBoatFilter(filter); + + // Sampling filter + if (filter.isSamplingFiltered()) { +// query.addFrom(ElligibleBoat.class, ALIAS_ELLIGIBLE_BOAT). +// addWhere(new StringBuilder(getElligibleBoatProperty()). +// append(" = "). +// append(boatProperty). +// toString() +// ); + + // Add join for ElligibleBoat + elligibleBoatProperty = ALIAS_ELLIGIBLE_BOAT; + query.addLeftJoin(getBoatElligibleProperty(), elligibleBoatProperty, + false); + // To have no doubloons + query.setSelect(boatProperty).addDistinct(); + + // Apply filter for sampling + sampleRowProperty = getElligibleSampleRowProperty(); + applySamplingFilter(filter); + + // Company + if (company != null) { + // Test only valid ElligibleBoat for that company + query.addWhere(new StringBuilder(getElligibleCompanyActiveProperty()). + append(" = :booleanTrue "). + append("OR ("). + append(getElligibleCompanyActiveProperty()). + append(" IS NULL AND "). + append(getElligibleGlobalActiveProperty()). + append(" = :booleanTrue)"). + toString() + ).addParam("booleanTrue", Boolean.TRUE); + // TopiaQuery.newOr(getElligibleCompanyActiveProperty()). + // or("? = :booleanTrue"). + // orEnclosed("? IS NULL AND $1 = :booleanTrue", + // getElligibleGlobalActiveProperty()). + // toString() + } + } + + if (StringUtils.isNotEmpty(orderBy)) { + query.addOrder(getBoatOrderProperty(orderBy)); + } + + return this; + } + + public WaoQueryBuilder applyContactFilter(ContactFilter filter) { + + // need contactProperty + + WaoUser observer = filter.getObserver(); + Company company = filter.getCompany(); + Date fromDate = filter.getFromDate(); + Boolean mammalsObservation = filter.getMammalsObservation(); + Boolean mammalsCapture = filter.getMammalsCapture(); + Boolean programAccepted = filter.getProgramAccepted(); + Boolean programRefused = filter.getProgramRefused(); + Boolean programUndefined = filter.getProgramUndefined(); + Boolean companyAccepted = filter.getCompanyAccepted(); + Boolean companyRefused = filter.getCompanyRefused(); + Boolean companyUndefined = filter.getCompanyUndefined(); + ContactState contactState = filter.getState(); + + // OBSERVER + if (observer != null) { + query.addEquals(getContactObserverProperty(), observer); + } + + // Company filter is managed by SamplingFilter because the company is + // linked with the sampleRow instead of contact user + + + // Ano #2327 : Reset fromDate, don't manage it in prepareQueryForSampling + filter.setFromDate(null); + + if (filter.isSamplingFiltered() || company != null) { + sampleRowProperty = getContactSampleRowProperty(); + applySamplingFilter(filter); + } + + boatProperty = getContactBoatProperty(); + applySimpleBoatFilter(filter); + + // MAMMALS_OBSERVATION and MAMMALS_CAPTURE + + if (mammalsObservation && mammalsCapture) { + query.addWhere(new StringBuilder(getMammalsObservationProperty()). + append(" = :mammals OR "). + append(getMammalsCaptureProperty()). + append(" = :mammals"). + toString() + ).addParam("mammals", Boolean.TRUE); + // TopiaQuery.newOr(getMammalsObservationProperty()). + // or("? = :mammals"). + // or("$1 = :mammals", getMammalsCaptureProperty()). + // toString() + } else if (mammalsObservation) { + query.addEquals(getMammalsObservationProperty(), Boolean.TRUE); + } else if (mammalsCapture) { + query.addEquals(getMammalsCaptureProperty(), Boolean.TRUE); + } + + // VALIDATION_PROGRAM + List<Object> programValidValues = new ArrayList<Object>(); + if (programAccepted) { + programValidValues.add(Boolean.TRUE); + } + if (programRefused) { + programValidValues.add(Boolean.FALSE); + } + if (programUndefined) { + programValidValues.add(null); + } + query.addEquals(getValidationProgramProperty(), programValidValues.toArray()); + + // VALIDATION_COMPANY + List<Object> companyValidValues = new ArrayList<Object>(); + if (companyAccepted) { + companyValidValues.add(Boolean.TRUE); + } + if (companyRefused) { + companyValidValues.add(Boolean.FALSE); + } + if (companyUndefined) { + companyValidValues.add(null); + } + query.addEquals(getValidationCompanyProperty(), companyValidValues.toArray()); + + // STATE + if (contactState != null) { + query.addEquals(getContactStateProperty(), contactState.ordinal()); + } + + // FROM_DATE + if (fromDate != null) { +// query.add("(" + tideBeginDateProperty + " IS NOT NULL AND " +// + tideBeginDateProperty + " >= :fromDate)" + +// " OR (" + tideBeginDateProperty + " IS NULL AND " +// + createDateProperty + " >= :fromDate)"); +// query.addParam("fromDate", getFromDate()); + + query.addWhere(getContactCreateDateProperty(), TopiaQuery.Op.GE, fromDate); + } + + // Reinitialize fromDate of the filter, don't know if it's really needed + filter.setFromDate(fromDate); + return this; + } + + + +} Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-07 19:43:01 UTC (rev 494) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-08 10:01:43 UTC (rev 495) @@ -27,13 +27,8 @@ import com.csvreader.CsvReader; import com.csvreader.CsvWriter; -import fr.ifremer.wao.WaoBusinessException; +import fr.ifremer.wao.*; import fr.ifremer.wao.WaoBusinessException.Type; -import fr.ifremer.wao.WaoContext; -import fr.ifremer.wao.WaoDAOHelper; -import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.WaoProperty; -import fr.ifremer.wao.WaoUtils; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; @@ -59,9 +54,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Level; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.RollingFileAppender; import org.nuiton.topia.TopiaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,9 +99,13 @@ BoatFilter filter) throws TopiaException { BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - TopiaQuery query = dao.createQuery("B"); +// TopiaQuery query = dao.createQuery("B"); +// +// query = createQueryForBoatFilter(query, filter); - query = createQueryForBoatFilter(query, filter); + TopiaQuery query = new WaoQueryBuilder(Boat.class). + applyBoatFilter(filter). + toQuery(); query.addLoad(Boat.ACTIVITY_CALENDAR); @@ -117,23 +113,32 @@ logger.debug("Query : " + query); } - return dao.findAllMappedByQuery(query, + Map<Integer, Boat> results = dao.findAllMappedByQuery(query, Boat.IMMATRICULATION, Integer.class); + + return results; } @Override public int executeGetNbBoatsByFilter(TopiaContext transaction, BoatFilter filter) throws TopiaException { + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - TopiaQuery query = dao.createQuery("B"); +// TopiaQuery query = dao.createQuery("B"); +// +// query = createQueryForBoatFilter(query, filter); - query = createQueryForBoatFilter(query, filter); + TopiaQuery query = new WaoQueryBuilder(Boat.class). + applyBoatFilter(filter). + toQuery(); - // Ano #560 in ToPIA, distinct will be manage in executeCount() for 2.4 - //return query.executeCount(); - return query.executeToInteger("COUNT(DISTINCT B)"); +// int count = query.executeToInteger("COUNT(DISTINCT B)"); + int count = dao.countByQuery(query); + + return count; } - + + @Deprecated protected TopiaQuery createQueryForBoatFilter(TopiaQuery query, BoatFilter filter) throws TopiaException { String main = query.getMainAlias(); @@ -337,8 +342,13 @@ BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - return dao.createQuery().addDistinct().setSelect(Boat.NAME). - add(Boat.NAME, Op.LIKE, input + "%").execute(); + List<String> boatNames = dao.createQuery(). + addDistinct(). + setSelect(Boat.NAME). + addEquals(Boat.NAME, Op.LIKE, input + "%"). + execute(transaction); + + return boatNames; } /** Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-06-07 19:43:01 UTC (rev 494) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-06-08 10:01:43 UTC (rev 495) @@ -92,8 +92,21 @@ query = prepareQueryForFishingZoneFilter(query, filter); - return (List<String>)query.addDistinct(). - setSelect("F." + FishingZone.FACADE_NAME).execute(); + query.addDistinct(). + setSelect("F." + FishingZone.FACADE_NAME).execute(); + + List<String> results = query.execute(); + +// WaoQueryBuilder queryBuilder = new WaoQueryBuilder(FishingZone.class). +// applyFishingZoneFilter(filter); +// +// TopiaQuery query = queryBuilder.toQuery(). +// addDistinct(). +// setSelect(queryBuilder.getFacadeNameProperty()); +// +// List<String> results = query.execute(); + + return results; } @Override @@ -108,9 +121,23 @@ if (StringUtils.isNotEmpty(filter.getFacadeName())) { query.add("F." + FishingZone.FACADE_NAME, filter.getFacadeName()); } + query.addDistinct(). + setSelect("F." + FishingZone.SECTOR_NAME).execute(); - return (List<String>)query.addDistinct(). - setSelect("F." + FishingZone.SECTOR_NAME).execute(); +// WaoQueryBuilder queryBuilder = new WaoQueryBuilder(FishingZone.class). +// applyFishingZoneFilter(filter); +// +// TopiaQuery query = queryBuilder.toQuery(). +// addDistinct(). +// setSelect(queryBuilder.getSectorNameProperty()); +// +// if (StringUtils.isNotEmpty(filter.getFacadeName())) { +// query.add(queryBuilder.getFacadeNameProperty(), filter.getFacadeName()); +// } + + List<String> results = query.execute(); + + return results; } protected TopiaQuery prepareQueryForFishingZoneFilter(TopiaQuery query, Modified: trunk/wao-business/src/main/xmi/wao.properties =================================================================== --- trunk/wao-business/src/main/xmi/wao.properties 2010-06-07 19:43:01 UTC (rev 494) +++ trunk/wao-business/src/main/xmi/wao.properties 2010-06-08 10:01:43 UTC (rev 495) @@ -1,6 +1,7 @@ model.tagvalue.copyright=/* *##%\n Copyright (C) 2009 Wao\n *##%*/ model.tagvalue.java.lang.String=text model.tagvalue.exceptionClass=fr.ifremer.wao.WaoException +model.tagvalue.notGenerateToString=true #model.tagvalue.useLegacyDAO=true Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/ErrorDB1_0Test.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/ErrorDB1_0Test.java 2010-06-07 19:43:01 UTC (rev 494) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/ErrorDB1_0Test.java 2010-06-08 10:01:43 UTC (rev 495) @@ -127,7 +127,7 @@ String tideBegin = contact + "." + Contact.TIDE_BEGIN_DATE; String sampleRow = contact + "." + Contact.SAMPLE_ROW; - query.add(sampleRow, curr); + query.addEquals(sampleRow, curr); query.addGroup(sampleRow); @@ -135,10 +135,10 @@ Date begin = DateUtils.setFirstDayOfMonth(month.getPeriodDate()); Date end = DateUtils.setLastDayOfMonth(month.getPeriodDate()); - query.add(tideBegin + " BETWEEN :begin AND :end"). + query.addWhere(tideBegin + " BETWEEN :begin AND :end"). addParam("begin", begin).addParam("end", end); - int nbRealTides = query.executeCount(); + int nbRealTides = dao.countByQuery(query); boolean ok = month.getRealTidesValue() == nbRealTides; String ko = ok ? "" : "## KO ";
participants (1)
-
fdesbois@users.labs.libre-entreprise.org