Created
July 15, 2011 19:37
-
-
Save gAmUssA/1085386 to your computer and use it in GitHub Desktop.
ClearDataBuilder feature request. Implement code generation for Collection as fill method parameter ITestService.java - service interface
TestService.java - expanded implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javaheadbrain.experiments.amf; | |
import java.util.List; | |
import com.acme.supperapp.entities.UserEntity; | |
import clear.cdb.annotations.CX_FillMethod; | |
import clear.cdb.annotations.CX_JPQLMethod; | |
import clear.cdb.annotations.CX_Service; | |
import clear.cdb.annotations.CX_TransferInfo; | |
@CX_Service | |
public interface ITestService { | |
@CX_JPQLMethod(query="SELECT u FROM UserEntity u WHERE u.lastName LIKE UPPER (CONCAT(:lastName, '%')) AND u.userId in :idslist ", | |
listAsParameter=true, | |
transferInfo=@CX_TransferInfo(type="com.acme.superapp.dto.UserDTO", | |
mappedBy=UserEntity.class)) | |
List<?> getUserseByLastNameAndId(String lastName, List<String> idsList); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javaheadbrain.experiments.amf; | |
import org.hibernate.Query; | |
import com.javaheadbrain.experiments.amf.generated._TestService; | |
public class TestService extends _TestService { | |
@Override | |
public java.util.List<?> getUserseByLastNameAndId(java.lang.String lastName, | |
java.util.List<java.lang.String> idsList) { | |
try { | |
UserTransactionManager.joinUserTransaction(); | |
Session session = SessionFactoryUtils.getCurrentSession(); | |
Query query = session.createQuery("SELECT u.usrId, u.firstName, u.lastName, u.emailId FROM UserEntity u WHERE u.lastName LIKE UPPER (CONCAT(:lastName, '%')) AND u.userId in :idslist"); | |
query.setParameter("lastName", lastName); | |
query.setParameterList("idslist", idslist); | |
query.setResultTransformer(new ResultTransformer() { | |
private static final long serialVersionUID = 1L; | |
@Override | |
public Object transformTuple(Object[] aobj, String[] as) { | |
com.acme.superapp.dto.UserDTO dto = new com.acme.superapp.dto.UserDTO(); | |
dto.setUsrId((java.lang.Long)aobj[0]); | |
dto.setFirstName((java.lang.String)aobj[1]); | |
dto.setLastName((java.lang.String)aobj[2]); | |
dto.setEmailId((java.lang.String)aobj[3]); | |
return dto; | |
} | |
@Override | |
@SuppressWarnings({ "unchecked" }) | |
public List transformList(List list) { | |
return list; | |
} | |
}); | |
@SuppressWarnings({ "unchecked" }) | |
List result = query.list(); | |
UserTransactionManager.commitUserTransaction(); | |
return result; | |
} catch (Throwable e) { | |
try { | |
UserTransactionManager.rollbackUserTransaction(); | |
} catch (Throwable th) { | |
throw new RuntimeException(th); | |
} | |
throw new RuntimeException(e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment