All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wesleyhome.dao.processor.method.EqualsQueryMethodGenerator Maven / Gradle / Ivy

/*
 * @(#)EqualsQueryMethodGenerator.java
 * 
 * (C) Copyright 2014 by Travelers
 * All Rights Reserved.
 * 
 * This software is the confidential and proprietary information
 * of the Travelers Corporation. ("Confidential Information").
 * Redistribution of the source code or binary form is not permitted
 * without prior authorization from Travelers.
 */
package com.wesleyhome.dao.processor.method;

import java.util.Date;
import java.util.List;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JInvocation;
import com.sun.codemodel.JVar;
import com.wesleyhome.dao.processor.model.MappingType;

/**
 * The EqualsQueryMethodGenerator class is a
 * 
 * @author
 * @since
 */
public class EqualsQueryMethodGenerator extends BaseQueryParameterMethodGenerator {

	@Override
	protected JInvocation addPredicateArg(final JCodeModel model, final JInvocation predicateInvoke, final JVar jVar) {
		try {
			String className = jVar.type().fullName();
			System.out.println(className);
			Class argClass = Class.forName(className);
			System.out.println(argClass);
			if(Date.class.equals(argClass)) {
				System.out.println("Doing something different");
				return predicateInvoke.arg(JExpr._new(model.ref(java.sql.Date.class)).arg(jVar.invoke("getTime")));
			}
			return predicateInvoke.arg(jVar);
		} catch (ClassNotFoundException e) {
			return predicateInvoke.arg(jVar);
		}
	}

	@Override
	protected JClass getReturnType(final JCodeModel model, final JClass entityJClass, final MappingType mappingType) {
		switch(mappingType) {
			case ONE_TO_ONE:
			case UNIQUE_OBJECT:
				return entityJClass;
			case OBJECT:
			case MANY_TO_ONE:
			default:
				return model.ref(List.class).narrow(entityJClass);
		}
	}

	@Override
	protected String getReturnCall(final MappingType mappingType) {
		switch(mappingType) {
			case ONE_TO_ONE:
			case UNIQUE_OBJECT:
				return "getSingleResult";
			case OBJECT:
			case MANY_TO_ONE:
			default:
				return "getResultList";
		}
	}

	/* (non-Javadoc)
	 * @see com.travelers.smart.dao.generator.processor.method.BaseQueryMethodGenerator#getQueryTypeName()
	 */
	@Override
	protected String getQueryTypeName() {
		return "Equals";
	}

	/* (non-Javadoc)
	 * @see com.travelers.smart.dao.generator.processor.method.BaseQueryMethodGenerator#getPredicateMethodName()
	 */
	@Override
	protected String getPredicateMethodName() {
		return "equals";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy