<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.wmg.digital.esdc.freeflag.domain" default-lazy="true">
<class
name="FreeFlagError"
table="ESDC_SUSPENSE_QUEUE"
dynamic-update="true"
mutable="true"
>
<cache usage="read-write"/>
<id
name="id"
type="long"
column="ID"
>
<generator class="sequence">
<param name="sequence">ESDC_QUEUE_ID_SEQ</param>
</generator>
</id>
<version
name="version"
type="long"
column="VERSION"
>
</version>
<property
name="errorId"
type="long"
column="ERROR_ID"
not-null="true"
>
</property>
<property
name="detailId"
type="long"
column="DETAIL_ID"
not-null="true"
>
</property>
<property
name="statusId"
type="long"
column="STATUS_ID"
not-null="true"
>
</property>
<property
name="dealerAccountId"
type="long"
column="DEALER_ACCOUNT_ID"
not-null="false"
>
</property>
<property
name="units"
type="long"
column="UNITS"
not-null="false"
>
</property>
<property
name="dsp"
type="string"
column="DSP"
not-null="false"
length="255"
>
</property>
<property
name="artist"
type="string"
column="REPORTED_ARTIST"
not-null="false"
length="255"
>
</property>
<property
name="title"
type="string"
column="REPORTED_TITLE"
not-null="false"
length="255"
>
</property>
<property
name="primaryProductIdentifier"
type="string"
column="PRIMARY_PRODUCT_IDENTIFIER"
not-null="false"
length="100"
>
</property>
<property
name="freeFlag"
type="yes_no"
column="FREE_FLAG"
not-null="false"
>
</property>
<property
name="transactionDate"
type="date"
column="TRANSACTION_DATE"
not-null="false"
>
</property>
<property
name="lastUpdateUser"
type="string"
column="LAST_UPDATE_USER"
not-null="false"
length="25"
>
</property>
</class>
</hibernate-mapping>
package com.wmg.digital.esdc.freeflag.dao.impl.hibernate;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.wmg.core.springframework.orm.hibernate3.GeneralCriteriaCallback;
import com.wmg.core.springframework.orm.hibernate3.UniqueCriteriaCallback;
import com.wmg.digital.esdc.freeflag.dao.FreeFlagErrorDao;
import com.wmg.digital.esdc.freeflag.domain.FreeFlagError;
import com.wmg.digital.esdc.freeflag.domain.Error;
public class FreeFlagErrorImpl extends HibernateDaoSupport implements FreeFlagErrorDao {
@SuppressWarnings("unchecked")
public List<FreeFlagError> findAllFreeFlagError() {
GeneralCriteriaCallback callback = new GeneralCriteriaCallback(
FreeFlagError.class);
callback.addFetchMode("freeflagerror", FetchMode.SELECT);
callback.addExpression(Restrictions.eq("errorId", Error.FREE_FLAG_ERROR_ID));
callback.addExpression(Restrictions.ne("statusId", Error.STATUS_ID_PROCESSED));
callback.addOrderBy(Order.desc("units"));
List<FreeFlagError> ffe = (List<FreeFlagError>) getHibernateTemplate()
.execute(callback);
return ffe;
}
public List<FreeFlagError> findTop10FreeFlagError() {
GeneralCriteriaCallback callback = new GeneralCriteriaCallback(
FreeFlagError.class);
callback.addFetchMode("freeflagerror", FetchMode.SELECT);
callback.addExpression(Restrictions.eq("errorId", Error.FREE_FLAG_ERROR_ID));
callback.addExpression(Restrictions.ne("statusId", Error.STATUS_ID_PROCESSED));
callback.addOrderBy(Order.desc("units"));
callback.setMaxResults(10);
List<FreeFlagError> ffe = (List<FreeFlagError>) getHibernateTemplate()
.execute(callback);
return ffe;
}
public List<FreeFlagError> findFreeFlagErrorByDSP(String pattern) {
String newPattern = StringUtils.replace(pattern, "*", "%");
GeneralCriteriaCallback callback = new GeneralCriteriaCallback(
FreeFlagError.class);
callback.addFetchMode("freeflagerror", FetchMode.SELECT);
callback.addExpression(Restrictions.eq("errorId", Error.FREE_FLAG_ERROR_ID));
callback.addExpression(Restrictions.ne("statusId", Error.STATUS_ID_PROCESSED));
if (StringUtils.isNotEmpty(newPattern)) {
callback.addExpression(Restrictions.like("dsp", newPattern)
.ignoreCase());
}
callback.addOrderBy(Order.desc("units"));
List<FreeFlagError> ffe = (List<FreeFlagError>) getHibernateTemplate().execute(callback);
return ffe;
}
public List<FreeFlagError> findFreeFlagErrorByArtist(String pattern) {
String newPattern = StringUtils.replace(pattern, "*", "%");
GeneralCriteriaCallback callback = new GeneralCriteriaCallback(
FreeFlagError.class);
callback.addFetchMode("freeflagerror", FetchMode.SELECT);
callback.addExpression(Restrictions.eq("errorId", Error.FREE_FLAG_ERROR_ID));
callback.addExpression(Restrictions.ne("statusId", Error.STATUS_ID_PROCESSED));
if (StringUtils.isNotEmpty(newPattern)) {
callback.addExpression(Restrictions.like("artist", newPattern)
.ignoreCase());
}
callback.addOrderBy(Order.desc("units"));
List<FreeFlagError> ffe = (List<FreeFlagError>) getHibernateTemplate().execute(callback);
return ffe;
}
public List<FreeFlagError> findFreeFlagErrorByTitle(String pattern) {
String newPattern = StringUtils.replace(pattern, "*", "%");
GeneralCriteriaCallback callback = new GeneralCriteriaCallback(
FreeFlagError.class);
callback.addFetchMode("freeflagerror", FetchMode.SELECT);
callback.addExpression(Restrictions.eq("errorId", Error.FREE_FLAG_ERROR_ID));
callback.addExpression(Restrictions.ne("statusId", Error.STATUS_ID_PROCESSED));
if (StringUtils.isNotEmpty(newPattern)) {
callback.addExpression(Restrictions.like("title", newPattern)
.ignoreCase());
}
callback.addOrderBy(Order.desc("units"));
List<FreeFlagError> ffe = (List<FreeFlagError>) getHibernateTemplate().execute(callback);
return ffe;
}
public FreeFlagError getFreeFlagErrorById(Long ffid) {
UniqueCriteriaCallback callback = new UniqueCriteriaCallback(
FreeFlagError.class);
callback.addExpression(Restrictions.eq("id", ffid));
FreeFlagError ffe = (FreeFlagError) getHibernateTemplate().execute(callback);
return ffe;
}
public void updateFfe(FreeFlagError ffe) {
getHibernateTemplate().update(ffe);
}
public void updateAllFfes(List<FreeFlagError> ffes) {
try {
for (FreeFlagError ffe : ffes) {
getHibernateTemplate().saveOrUpdate(ffe);
}
} catch (Exception e) {
System.err.println(e);
}
}
}
|