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

rm-generator.1.5.0.source-code.declared_queries.vm Maven / Gradle / Ivy

The newest version!
## Velocity template to generate the code for all declared queries
#if($class.isInterface())
package $class.InterfacePackageName;
#else
package $class.PackageName;
#end

import ${class.BeanPackageName}.*;
import org.noorm.jdbc.*;
import java.util.*;
#if(!$class.isInterface() && $class.hasInterface())
import ${class.InterfacePackageName}.${class.JavaInterfaceName};
#end

/**
 * Generated database access functionality for all declared queries
 * DO NOT EDIT! This file has been auto-generated by NoORM
 */
#if($class.isInterface())
public interface ${class.JavaInterfaceName} {
#else

#if($class.hasInterface())
public class ${class.JavaName} implements ${class.JavaInterfaceName} {
#else
public class ${class.JavaName} {
#end
#end
#if(!$class.hasInterface())

	private static ${class.JavaName} ourInstance = new ${class.JavaName}();
#end
#if(!$class.isInterface())
#if ($class.hasDataSourceName())

	private static final String DATA_SOURCE_NAME = "$class.getDataSourceName()";
#end
#end
#if(!$class.isInterface() && !$class.hasInterface())

	protected ${class.JavaName}() {
	}

	public static ${class.JavaName} getInstance() {

		return ourInstance;
	}
#end
#foreach($query in $class.queries)

#if($class.isInterface())
	#if(!$query.isSingleRowQuery())List<#end$query.getBeanName()#if(!$query.isSingleRowQuery())>#end $query.getMethodName()(#foreach($param in $query.Parameters)#if(!$param.isUnaryOperator())final #if($param.isList())List<#end$param.JavaType#if($param.isList())>#end ${param.JavaName}#if($foreach.count<$query.Parameters.size()),${nl}${subindent}#end#end#end#if($query.useFilterExtension())#if($query.Parameters.size()>0), #{end}final FilterExtension pFilterExtension#end);
#else
	public #if(!$query.isSingleRowQuery())List<#end$query.getBeanName()#if(!$query.isSingleRowQuery())>#end $query.getMethodName()(#foreach($param in $query.Parameters)#if(!$param.isUnaryOperator())final #if($param.isList())List<#end$param.JavaType#if($param.isList())>#end ${param.JavaName}#if($foreach.count<$query.Parameters.size()),${nl}${subindent}#end#end#end#if($query.useFilterExtension())#if($query.Parameters.size()>0), #{end}final FilterExtension pFilterExtension#end) {

#if($class.hasDataSourceName())
		DataSourceProvider.setActiveDataSource(DATA_SOURCE_NAME);
#end
		final Map parameters = new HashMap();
#foreach ($param in $query.Parameters)
#if($param.isUnaryOperator())
		parameters.put(new QueryColumn("$param.getDbParamName().toLowerCase()", new Operator(Operator.Name.$param.getOperator()),#if($param.hasCustomExpression()) "$param.getCustomExpression()"#else null#end), null);
#else
		parameters.put(new QueryColumn("$param.getDbParamName().toLowerCase()", new Operator(Operator.Name.$param.getOperator()),#if($param.hasCustomExpression()) "$param.getCustomExpression()"#else null#end), $param.JavaName);
#end
#end
		final JDBCQueryProcessor<$query.getBeanName()> queryProcessor = JDBCQueryProcessor.getInstance();
		final List<$query.getBeanName()> results = queryProcessor.getBeanListFromSQL("$query.getTableName()", parameters, ${query.getBeanName()}.class, $query.isAcquireLock()#if($query.useFilterExtension()), pFilterExtension#end);
#if($query.isSingleRowQuery())
		if (results.isEmpty()) {
			return null;
		} else {
			return results.get(0);
		}
#else
		return results;
#end
	}
#end
#end
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy