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

templates.Repository.xpt Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
?IMPORT core?
?IMPORT dom?
?EXTENSION extensions::EntityExtension?
?EXTENSION extensions::File?
?EXTENSION extensions::JavaUtil?
?EXTENSION extensions::Properties?
?EXTENSION extensions::Strings?
?EXTENSION extensions::Validation?
?EXTENSION extensions::Names?
?EXTENSION org::openxma::dsl::common::extensions::LogUtil?
/**
 * main entry point for all generated artefacts of the persistence layer
 */
?DEFINE main FOR Model?
    ?LET getDaos() AS daos?
    ?EXPAND genInterface           FOREACH daos?
    ?EXPAND manInterface           FOREACH daos?
    ?EXPAND genClass             FOREACH daos?
    ?EXPAND manClass             FOREACH daos?
    /**
     * do not change the order of hibernate mapping file creation (see HbmFileMergePostProcessor)
     */
    ?EXPAND hibernateMapping(this) FOREACH daos.select(e1|!daos.exists(e2|e1.entity.superType==e2.entity))?
    ?EXPAND hibernateGenMapping(this) FOREACH daos.select(e1|!daos.exists(e2|e1.entity.superType==e2.entity))?
    ?EXPAND hibernateFragmentMapping(this) FOREACH daos.select(e1|!daos.exists(e2|e1.entity.superType==e2.entity))?
    ?ENDLET?
?ENDDEFINE?
/**
 * Generates the dao interface of the given entity
 */
?DEFINE genInterface FOR Dao?
?info("Write "+getGenInterfaceFileName())?
?FILE getGenInterfaceFileName()-?
package ?getPackageName(false)?;

import org.openxma.dsl.platform.dao.*;
?addImports()-?

/**
?EXPAND Documentation::documentationLines FOR this-?
 * Represents a Data Access Object, as defined in the
 * Core J2EE Pattern Catalog (see http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html),
 * to abstract and encapsulate all access to entity ?name?.
 * @see ?getFullyQualifiedName(false)?
 */
public interface ?getGenInterfaceName()? extends GenericDao, EntityFactory {
	?IF !entity.sortOrders.isEmpty-?
	/**
	 * Sort order constants
	 */
    ?EXPAND  orderSpecificationConstant FOREACH entity.sortOrders-?
	?ENDIF-?
    ?IF !queryOperation.isEmpty-?
	/**
	 * Query name constants
	 */
    ?EXPAND  queryNameConstant FOREACH queryOperation.select(e|!CallableStatement.isInstance(e.statement))-?
    /**
	 * Stored procedure name constants
	 */
    ?EXPAND  spNameConstant FOREACH queryOperation.select(e|CallableStatement.isInstance(e.statement))-?
    ?ENDIF-?
    ?EXPAND  createOperationInterface FOR this-?
    ?EXPAND  genOperationInterface FOR this-?
    ?FOREACH dataBaseConstraints.reject(e|e.type==DataBaseConstraintType::PRIMARY)    AS constraint-?
        ?EXPAND dbConstraintFinderSignature(null) FOR constraint?;
    ?ENDFOREACH-?
    ?FOREACH operations AS operation-?
        ?EXPAND daoOperationSignature(null) FOR operation-?;
    ?ENDFOREACH-?
    ?FOREACH queryOperation AS queryOperation-?
        ?EXPAND queryOperationSignature(null) FOR queryOperation-?;
    ?ENDFOREACH-?
}
?ENDFILE?
?ENDDEFINE?
/**
 * Generates the manual dao interface of the given entity
 */
?DEFINE manInterface FOR Dao?
?info("Write "+getInterfaceFileName())?
?FILE getInterfaceFileName() OUTLET_JAVA-?
package ?getPackageName(false)?;

?addImports()-?

?EXPAND Documentation::documentation FOR this-?
public interface ?name? extends ?getGenInterfaceName()? {
    ?EXPAND  manOperationInterface FOR this-?
}
?ENDFILE?
?ENDDEFINE?
/**
 * Generates the dao implemenation of the given entity
 */
?DEFINE genClass FOR Dao?
?info("Write "+getGenClassFileName())?
?FILE getGenClassFileName()-?
package ?getPackageName(true)?;

import org.openxma.dsl.platform.dao.*;
import org.openxma.dsl.platform.dao.impl.*;
import org.openxma.dsl.platform.service.Mapper;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;
?addImports()-?
?EXPAND genImportsImpl FOR this-?
/**
 * @see ?getQualifiedInterfaceName()?
 */
@SuppressWarnings("unused")
public abstract class ?getGenClassName()? extends ?IF getDaoBaseClass().compareTo("org.openxma.dsl.platform.dao.impl.GenericDaoHibernateImpl")==0?GenericDaoHibernateImpl?ELSE??registerImport(getDaoBaseClass())??ENDIF? implements ?getQualifiedInterfaceName()? {

    public ?getGenClassName()?() {
        super(?entity.getQualifiedClassName()?.class);
    }
    ?EXPAND createOperationImpl FOR this-?
    ?EXPAND genOperationImpl FOR this-?
    ?EXPAND dbConstraintFinderImpl FOREACH dataBaseConstraints.reject(e|e.type==DataBaseConstraintType::PRIMARY)-?
    ?FOREACH operations.select(e|e.expression!=null) AS operation-?
        ?EXPAND daoOperationImpl FOR operation-?
    ?ENDFOREACH-?
    ?FOREACH queryOperation AS qlOperation-?
        ?EXPAND queryOperationImpl FOR qlOperation-?
    ?ENDFOREACH-?
    
    protected Mapper getNamedQueryMapper(String queryName) {
		return new ?name?QueryMapper();
	}
	
	protected class ?name?QueryMapper extends NamedQueryMapper {
	
		@SuppressWarnings("unchecked")
		public  E mapOne(Object sourceObject, E targetObject, Object context) {
			?FOREACH queryOperation.select(e|e.many && DataView.isInstance(e.type) && SelectProperties.isInstance(e.statement)) AS qlOperation-?
			if ("?qlOperation.getQualifiedQueryName()?".equals(getQueryName(context))) {
				return (E) map?qlOperation.name.toFirstUpper()?Tuple((Object[]) sourceObject, 1);
			}
		    ?ENDFOREACH-?
			return super.mapOne(sourceObject, targetObject);
		}
	}
}
?ENDFILE?
?ENDDEFINE?
/**
 * Generates the dao implemenation of the given entity
 */
?DEFINE manClass FOR Dao?
?info("Write "+getClassFileName())?
?FILE getClassFileName() OUTLET_JAVA-?
package ?getPackageName(true)?;

import org.springframework.stereotype.Repository;
?addImports()-?
?EXPAND manImportsImpl FOR this-?

@Repository("?name.toFirstLower()?")
public class ?getClassName()? extends ?getGenClassName()? {
    ?FOREACH operations.select(e|e.expression==null) AS operation-?
    ?EXPAND daoOperationSignature("public") FOR operation-? {
        throw new IllegalStateException("not implemented");
    }
    ?ENDFOREACH-?
    ?EXPAND  manOperationImpl FOR this-?
}
?ENDFILE?
?ENDDEFINE?
/**
 * Generates the order specification for the entity
 */
?DEFINE orderSpecificationConstant FOR AttributeGroup-?
    ?EXPAND Documentation::documentationIndented FOR this-?
    static final SortOrderSpecification ?getConstantName()? = SortOrderSpecification.create("?getEntity().name?.?name?")?FOREACH attributes AS orderDefinition-??IF orderDefinition.asc?.asc("?orderDefinition.attribute.name?")?ELSE-? .desc("?orderDefinition.attribute.name?")?ENDIF-??ENDFOREACH-?;
?ENDDEFINE?
/**
 * Generates a constant name for a given queryOperation
 */
?DEFINE queryNameConstant FOR QueryOperation-?
    static final String ?getQueryName().toUnderScoreString().toUpperCase()? = "?getQualifiedQueryName()?";
?ENDDEFINE?
/**
 * Generates a constant name for a given callableStatement
 */
?DEFINE spNameConstant FOR QueryOperation-?
    static final String ?getStoredProcedureConstantName()? = "?((CallableStatement)statement).name.toSimpleName()?";
?ENDDEFINE?
/**
 * Generates the factory interface methods signature of the given entity
 */
?DEFINE createOperationInterface FOR Dao-?
    /**
     * Factory method to create an empty ?entity.name? entity with an already assigned identifier.
     * The advantage of this approach, coupled with the fact that we're using the id for equals,
     * is that equality test's are immediately possible and therefore independent from the persistence state
     * of the entity. This in contrast to other solutions where auto generated Keys are used
     * which must wait until the object is persisted or differentiate between transient and managed states.
    ?IF primaryKey!=null-?
     * @return a new (transient), empty ?entity.name? entity with an already assigned identifier.
     */
    ?entity.name? create();
    ?LET entity.requiredReferences.toList().addAll(entity.requiredAttributes.select(e|!e.isIdOrVersion())) AS notNullFields-?
    ?IF !notNullFields.isEmpty-?
    /**
     * Factory method to create an empty ?entity.name? taking all not null attributes.
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH notNullFields-?
     * @return a new (transient ) ?entity.name? entity with the given natural identifier and not null attributes set.
     */
    ?entity.name? create(?EXPAND Features::methodParameter FOREACH notNullFields SEPARATOR ','-?);
    /**
     * Factory method to create and save an empty ?entity.name? taking all not null attributes.
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH notNullFields-?
     * @return a new (transient) ?entity.name? entity with the given natural identifier and not null attributes set.
     */
    ?entity.name? createAndSave(?EXPAND Features::methodParameter FOREACH notNullFields SEPARATOR ','-?);
    ?ENDIF-?
    ?ENDLET-?
    ?ELSE-?
    ?LET naturalKey.attributes AS naturalKeyFields-?
    ?EXPAND Features::methodParameterJavaDoc FOREACH naturalKeyFields-?
     * @return a new (transient), empty ?entity.name? entity with an already assigned identifier.
     */
    ?entity.name? create(?EXPAND Features::methodParameter   FOREACH naturalKeyFields SEPARATOR ','-?);
    ?ENDLET-?
    ?LET naturalKey.attributes.select(e|true).addAll(entity.requiredReferences.toList().addAll(entity.requiredAttributes.select(e|!e.isIdOrVersion()))).toSet() AS notNullFields-?
    ?IF !notNullFields.select(e|true).removeAll(naturalKey.attributes).isEmpty-?
    /**
     * Factory method to create an empty ?entity.name? taking all required (not-null) attributes.
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH notNullFields-?
     * @return a new, transient (i.e. is not associated with a persistence context and has no persistent representation in the database) ?entity.name? entity with the given natural identifier and not null attributes set.
     */
    ?entity.name? create(?EXPAND Features::methodParameter FOREACH notNullFields SEPARATOR ','-?);
    ?ENDIF-?
    /**
     * Factory method to create and save an empty ?entity.name? taking all required (not-null) attributes.
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH notNullFields-?
     * @return a new, transient (i.e. is not associated with a persistence context and has no persistent representation in the database) ?entity.name? entity with the given natural identifier and not null attributes set.
     */
    ?entity.name? createAndSave(?EXPAND Features::methodParameter FOREACH notNullFields SEPARATOR ','-?);
    ?ENDLET-?
    ?ENDIF-?
?ENDDEFINE?
/**
 * Generates the factory interface methods signature of the given entity
 */
?DEFINE createOperationImpl FOR Dao?
    /**
     * @param context the context for the object creation
     * @return a transient instance of entity ?entity.name? with an already assigned identifier.
     */
    public ?entity.name? createEntity(Object context) {
        ?IF primaryKey!=null-?
        return create();
        ?ELSE-?
        return createEntityInstance();
        ?ENDIF-?
    }
    ?IF primaryKey!=null-?

    public ?entity.name? create()
    {
        ?entity.name? ?entity.name.toVariableName()? = createEntityInstance();
        ?IF primaryKeyColumn.attribute.getImplementationType()=="Long"-?
        ?entity.name.toVariableName()?.?primaryKeyColumn.attribute.getMutatorMethodName()?(Long.valueOf(dataFieldMaxValueIncrementer.nextLongValue()));
        ?ELSEIF primaryKeyColumn.attribute.getImplementationType()=="String"-?
        ?entity.name.toVariableName()?.?primaryKeyColumn.attribute.getMutatorMethodName()?(dataFieldMaxValueIncrementer.nextStringValue());
        ?ELSEIF primaryKeyColumn.attribute.getImplementationType()=="Integer"-?
        ?entity.name.toVariableName()?.?primaryKeyColumn.attribute.getMutatorMethodName()?(dataFieldMaxValueIncrementer.nextIntValue());
        ?ELSEIF ((SimpleType)primaryKeyColumn.attribute.type.dataType).getJavaType()=="org.openxma.dsl.platform.valueobject.ValueObjectString"-?
        ?entity.name.toVariableName()?.?primaryKeyColumn.attribute.getMutatorMethodName()?(new ?primaryKeyColumn.attribute.getImplementationType()?(dataFieldMaxValueIncrementer.nextStringValue()));
        ?ELSEIF ((SimpleType)primaryKeyColumn.attribute.type.dataType).getJavaType()=="org.openxma.dsl.platform.valueobject.ValueObjectLong"-?
        ?entity.name.toVariableName()?.?primaryKeyColumn.attribute.getMutatorMethodName()?(new ?primaryKeyColumn.attribute.getImplementationType()?(dataFieldMaxValueIncrementer.nextLongValue()));
        ?ENDIF-?
        return ?entity.name.toVariableName()?;
    }
    ?LET entity.requiredReferences.addAll(entity.requiredAttributes.select(e|!e.isIdOrVersion())) AS notNullFields-?
    ?IF !notNullFields.isEmpty-?

    public ?entity.name? create(?EXPAND Features::methodParameter   FOREACH  notNullFields SEPARATOR ','-?) {
        ?FOREACH  notNullFields AS attribute-?
        Assert.notNull(?attribute.getResolvedName().toFirstLower()?, "Parameter '?attribute.getResolvedName().toFirstLower()?' must not be null");
        ?ENDFOREACH-?
        ?entity.getName(true)? ?entity.name.toVariableName()? = (?entity.getName(true)?) create();
        ?FOREACH notNullFields AS attribute-?
        ?entity.name.toVariableName()?.?attribute.getMutatorMethodName()?(?attribute.getResolvedName().toFirstLower()?);
        ?ENDFOREACH-?
        return ?entity.name.toVariableName()?;
    }

    public ?entity.name? createAndSave(?EXPAND Features::methodParameter   FOREACH  notNullFields SEPARATOR ','-?) {
        ?entity.getName(false)? ?entity.name.toVariableName()? = create(?FOREACH  notNullFields AS attribute SEPARATOR ','??attribute.getResolvedName().toFirstLower()??ENDFOREACH?);
        saveOrUpdate(?entity.name.toVariableName()?);
        return ?entity.name.toVariableName()?;
    }
    ?ENDIF-?
    ?ENDLET-?
    ?ELSE-?

    ?LET naturalKey.attributes AS naturalKeyFields-?
    public ?entity.name? create(?EXPAND Features::methodParameter   FOREACH naturalKeyFields SEPARATOR ','-?) {
        ?FOREACH  naturalKeyFields AS field-?
        Assert.notNull(?((Attribute)field).getResolvedName().toFirstLower()?, "Parameter '?((Attribute)field).getResolvedName().toFirstLower()?' must not be null");
        ?ENDFOREACH-?
        ?entity.getClassName()? ?entity.name.toVariableName()? = new ?entity.getQualifiedClassName()?();
        ?FOREACH naturalKeyFields AS field-?
        ?entity.name.toVariableName()?.?field.getMutatorMethodName()?(?((Attribute)field).getResolvedName().toFirstLower()?);
        ?ENDFOREACH-?
        return ?entity.name.toVariableName()?;
    }
    ?ENDLET-?
    ?LET naturalKey.attributes AS naturalKeyFields-?
    ?LET entity.requiredReferences.toList().addAll(entity.requiredAttributes.select(e|!e.isIdOrVersion())) AS notNullFields-?
    ?LET naturalKeyFields.select(e|true).addAll(notNullFields).toSet() AS fields-?
    ?IF !notNullFields.select(e|true).removeAll(naturalKeyFields).isEmpty-?

    public ?entity.name? create(?EXPAND Features::methodParameter FOREACH fields SEPARATOR ','-?) {
        ?entity.getName(true)? ?entity.name.toVariableName()? = (?entity.getName(true)?) create(?FOREACH naturalKeyFields AS field SEPARATOR ","??field.name??ENDFOREACH?);
        ?FOREACH  notNullFields AS field-?
        Assert.notNull(?field.getResolvedName().toFirstLower()?, "Parameter '?field.getResolvedName().toFirstLower()?' must not be null");
        ?ENDFOREACH-?
        ?FOREACH  notNullFields AS field-?
        ?entity.name.toVariableName()?.?field.getMutatorMethodName()?(?field.getResolvedName().toFirstLower()?);
        ?ENDFOREACH-?
        return ?entity.name.toVariableName()?;
    }
    ?ENDIF?
    public ?entity.name? createAndSave(?EXPAND Features::methodParameter FOREACH fields SEPARATOR ','-?) {
        ?entity.getName(false)? ?entity.name.toVariableName()? = create(?FOREACH fields AS field SEPARATOR ','??field.getResolvedName().toFirstLower()??ENDFOREACH?);
        saveOrUpdate(?entity.name.toVariableName()?);
        return ?entity.name.toVariableName()?;
    }
    ?ENDLET-?
    ?ENDLET-?
    ?ENDLET-?
    ?ENDIF-?
?ENDDEFINE?
/**
 * defines a hook for generating additional imports in the GENERATED repository IMPLEMENTATION
 */
?DEFINE genImportsImpl FOR Dao??ENDDEFINE?
/**
 * defines a hook for generating additional imports in the MANUAL repository IMPLEMENTATION
 */
?DEFINE manImportsImpl FOR Dao??ENDDEFINE?
/**
 * defines a hook for generating additional operations for the GENERATED repository INTERFACE
 */
?DEFINE genOperationInterface FOR Dao??ENDDEFINE?
/**
 * defines a hook for generating additional operations for the GENERATED repository IMPLEMENTATION
 */
?DEFINE genOperationImpl FOR Dao??ENDDEFINE?
/**
 * defines a hook for generating additional operations for the MANUAL repository INTERFACE
 */
?DEFINE manOperationInterface FOR Dao??ENDDEFINE?
/**
 * defines a hook for generating additional operations for the MANUAL repository IMPLEMENTATION
 */
?DEFINE manOperationImpl FOR Dao??ENDDEFINE?
/**
 * Generates the finder method implementation for the database constraints
 */
?DEFINE dbConstraintFinderImpl FOR DataBaseConstraint?
?LET resolvedAttributeList AS resolvedAttributes-?
    ?EXPAND dbConstraintFinderSignature("public") FOR this-? {
    ?IF type == DataBaseConstraintType::NATURAL || type == DataBaseConstraintType::INDEX-?
        ?FOREACH resolvedAttributes AS attribute ITERATOR iterator-?
        ?IF iterator.firstIteration-?
        Criterion criterion = equal("?attribute.getEntity()!=this.getEntity() && attribute.getEntity().repository!=null && attribute.getEntity()!=this.getEntity().superType  ? attribute.getQualifiedName():attribute.name?", ?attribute.getResolvedName()?, ?!attribute.required?);
        ?ELSE-?
        criterion = and(criterion,"?attribute.getEntity()!=this.getEntity() && attribute.getEntity().repository!=null  && attribute.getEntity()!=this.getEntity().superType  ? attribute.getQualifiedName():attribute.name?", ?attribute.getResolvedName()?, ?!attribute.required?);
        ?ENDIF-?
        ?ENDFOREACH-?
    ?ELSE-?
        ?FOREACH attributes AS field ITERATOR iterator-?
        ?LET (field.getProperty("fqn")!=null && field.getProperty("fqn")!=getEntity().name) ? field.getQualifiedName():field.name AS propertyName-?
        ?IF iterator.firstIteration-?
        Criterion criterion = equal("?propertyName?", ?field.getResolvedName()?, ?!field.required?);
        ?ELSE-?
        criterion = and(criterion,"?propertyName?", ?field.getResolvedName()?, ?!field.required?);
        ?ENDIF-?
        ?ENDLET-?
        ?ENDFOREACH-?
    ?ENDIF-?
        Criteria criteria = createCriteria(criterion);
    ?IF type == DataBaseConstraintType::NATURAL || type == DataBaseConstraintType::INDEX-?
        ?FOREACH resolvedAttributes.select(e|e.getEntity()!=this.getEntity() && e.getEntity().repository!=null && e.getEntity()!=this.getEntity().superType).getFQNProperty().toSet() AS alias-?
        criteria.createAlias("?alias.toFirstLower()?","?alias.toFirstLower()?");
        ?ENDFOREACH-?
    ?ELSE-?
        ?FOREACH ((List[String])this.getProperty("alias")) AS alias-?
        criteria.createAlias("?alias?","?alias?");
        ?ENDFOREACH-?
    ?ENDIF-?
    ?IF type == DataBaseConstraintType::NATURAL || type == DataBaseConstraintType::UNIQUE-?
        return (?getEntity().getFullyQualifiedName(false)?) unique(criteria);
    ?ELSEIF type == DataBaseConstraintType::INDEX-?
        applyPagingParameters(criteria,firstResult,maxResults);
        return new ?registerImport("java.util.LinkedHashSet")?(list(criteria));
    ?ENDIF-?
    }
?ENDLET-?
?ENDDEFINE?
/**
 * Generates the finder methods for the corresponding database constraints
 */
?DEFINE dbConstraintFinderSignature(String visibilityModifier) FOR DataBaseConstraint-?
?LET resolvedAttributeList AS resolvedAttributes-?
    ?IF type == DataBaseConstraintType::NATURAL-?
    ?IF visibilityModifier==null-?
    /**
     * Return the persistent instance of the ?getEntity().name? entity class
     * with the given natural identifier or null if not found.
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH resolvedAttributes-?
     * @return the persistent ?getEntity().name? instance, or null if not found
     */
    ?ENDIF-?
    ?IF visibilityModifier!=null-?
    ?visibilityModifier-??ENDIF? ?getEntity().name? ?getMethodName()?(?EXPAND Features::methodParameter FOREACH resolvedAttributes SEPARATOR ','-?)?ELSEIF type == DataBaseConstraintType::UNIQUE-?
    ?IF visibilityModifier==null-?
    /**
     * Return the persistent instance of the ?getEntity().name? entity class
     * with the given unique-key or null if not found.
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH attributes-?
     * @return the persistent ?getEntity().name? instance, or null if not found
     */
    ?ENDIF-?
    ?IF visibilityModifier!=null-?
    ?visibilityModifier-??ENDIF? ?getEntity().name? ?getMethodName()?(?EXPAND Features::methodParameter FOREACH attributes SEPARATOR ','-?)?ELSEIF type == DataBaseConstraintType::INDEX-?
    ?IF visibilityModifier==null-?
    /**
     * Execute a query based on the given index attributes.
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH resolvedAttributes-?
     * @param firstResult the index of the first result object to be retrieved (numbered from 0 or null if ignored)
     * @param maxResults the maximum number of result objects to retrieved (null or <=0 for no limit)
     * @return a {@link Set} containing 0 or more persistent ?getEntity().name? instances
     */
    ?ENDIF-?
    ?IF visibilityModifier!=null-?
    ?visibilityModifier-??ENDIF? ?registerImport("java.util.Set")? ?getMethodName()?(?EXPAND Features::methodParameter FOREACH resolvedAttributes SEPARATOR ','?,Integer firstResult,Integer maxResults?")"??ENDIF-?
?ENDLET-?
?ENDDEFINE?

?DEFINE queryOperationImpl FOR QueryOperation?
?IF CallableStatement.isInstance(statement)-?
?LET ((CallableStatement)statement) AS callableStatement-?
?EXPAND queryOperationSignature("public") FOR this-? {
		SimpleJdbcCall jdbcCall = prepare?name.toFirstUpper()?JdbcCall(?FOREACH queryParameters AS parameter SEPARATOR "," ??parameter.getName()??ENDFOREACH?);
		Map _resultMap = execute?name.toFirstUpper()?(jdbcCall?IF !queryParameters.isEmpty?,?ENDIF??FOREACH queryParameters AS parameter SEPARATOR "," ??parameter.getName()??ENDFOREACH?);
		?IF type!=null-?
		return map?name.toFirstUpper()?Result(_resultMap?IF !queryParameters.isEmpty?,?ENDIF??FOREACH queryParameters AS parameter SEPARATOR "," ??parameter.getName()??ENDFOREACH?);
		?ENDIF-?
    }	
    
    protected SimpleJdbcCall prepare?name.toFirstUpper()?JdbcCall(?EXPAND Features::methodParameter FOREACH queryParameters SEPARATOR ","?) {
    	?registerImport("org.springframework.jdbc.core.simple.SimpleJdbcCall")? jdbcCall = createJdbcCall(?getStoredProcedureConstantName()??IF callableStatement.name.contains(".")?,"?callableStatement.name.toPackageName()?"?ENDIF?);
		?IF callableStatement.functionCall-?
		jdbcCall.setFunction(true);
		?ENDIF-?
		?IF many-?
		?IF ComplexType.isInstance(type)-?
		jdbcCall.addDeclaredRowMapper("_resultSet", new ?registerImport("org.springframework.jdbc.core.simple.ParameterizedRowMapper")?() {
			public ?type.name? mapRow(?registerImport("java.sql.ResultSet")? rs, int rowNum) throws ?registerImport("java.sql.SQLException")? {
				?type.name? _?type.name.toFirstLower()? = new ?type.name?();
				?FOREACH callableStatement.outParameter.select(e|e.attribute!=null) AS outParameter-?
				_?type.name.toFirstLower()?.?outParameter.attribute.getMutatorMethodName()?(?registerImport("org.openxma.dsl.platform.jdbc.JdbcUtils2")?.getResultSetValue(rs,"?outParameter.name?",?outParameter.attribute.type.getFullyQualifiedName(false)?.class));
				?ENDFOREACH-?
				return _?type.name.toFirstLower()?;
			}
		});
		?ELSE-?
		jdbcCall.addDeclaredRowMapper("_resultSet", new ?registerImport("org.springframework.jdbc.core.simple.ParameterizedRowMapper")?() {
			public ?type.name? mapRow(?registerImport("java.sql.ResultSet")? rs, int rowNum) throws ?registerImport("java.sql.SQLException")? {
				return ?registerImport("org.openxma.dsl.platform.jdbc.JdbcUtils2")?.getResultSetValue(rs,"?callableStatement.outParameter.first().name?",?type.getFullyQualifiedName(false)?.class);
			}
		});
		?ENDIF-?
		?ELSEIF ComplexType.isInstance(type)-?
		?FOREACH callableStatement.outParameter.select(e|e.attribute.many && !ComplexType.isInstance(e.attribute.dataType)) AS outParameter-?
		jdbcCall.addDeclaredRowMapper("_?outParameter.attribute.name?_resultSet", new ?registerImport("org.springframework.jdbc.core.simple.ParameterizedRowMapper")?() {
			public ?outParameter.attribute.type.getFullyQualifiedName(false)? mapRow(?registerImport("java.sql.ResultSet")? rs, int rowNum) throws ?registerImport("java.sql.SQLException")? {
				return ?registerImport("org.openxma.dsl.platform.jdbc.JdbcUtils2")?.getResultSetValue(rs,"?outParameter.name?",?outParameter.attribute.type.getFullyQualifiedName(false)?.class);
			}
		});
		?ENDFOREACH-?
		?FOREACH callableStatement.outParameter.attribute.select(e|e.many && ComplexType.isInstance(e.dataType)).toSet() AS complexTypeAttribute-?
		?FOREACH callableStatement.outParameter.select(e|e.attribute==complexTypeAttribute) AS outParameter ITERATOR index-?
		?IF index.firstIteration-?
		jdbcCall.addDeclaredRowMapper("_?outParameter.attribute.name?_resultSet", new ?registerImport("org.springframework.jdbc.core.simple.ParameterizedRowMapper")?() {
			public ?outParameter.attribute.type.getFullyQualifiedName(false)? mapRow(?registerImport("java.sql.ResultSet")? rs, int rowNum) throws ?registerImport("java.sql.SQLException")? {
				?complexTypeAttribute.type.getFullyQualifiedName(false)? _?complexTypeAttribute.name.toFirstLower()? = new ?complexTypeAttribute.type.getFullyQualifiedName(true)?();		
		?ENDIF-?
				_?complexTypeAttribute.name.toFirstLower()?.?outParameter.nestedAttribute.getMutatorMethodName()?(?registerImport("org.openxma.dsl.platform.jdbc.JdbcUtils2")?.getResultSetValue(rs,"?outParameter.name?",?outParameter.nestedAttribute.type.getFullyQualifiedName(false)?.class));		
		?ENDFOREACH-?
				return _?complexTypeAttribute.name.toFirstLower()?;
			}
		});
		?ENDFOREACH-?
		?ENDIF-?
		return jdbcCall;
    }
    
    protected Map execute?name.toFirstUpper()?(SimpleJdbcCall jdbcCall?IF !queryParameters.isEmpty?,?ENDIF??EXPAND Features::methodParameter FOREACH queryParameters SEPARATOR ","?) {
        ?registerImport("java.util.Map")? parametersMap = new ?registerImport("java.util.HashMap")?();
		?FOREACH callableStatement.inParameter AS inParameter-?
		parametersMap.put("?inParameter.name!=null ? inParameter.name : (inParameter.attribute!=null ? inParameter.attribute.name : inParameter.parameter.getName())?",?IF inParameter.attribute!=null??inParameter.parameter.getName()?==null ? null:?inParameter.parameter.getName()?.?inParameter.attribute.getAccessorMethodName()?()?ELSE??inParameter.parameter.getName()??ENDIF?);
		?ENDFOREACH-?
		return executeJdbcCall(jdbcCall,parametersMap);
    }
    ?IF type!=null-?
    
    protected ?getType()? map?name.toFirstUpper()?Result(Map _resultMap?IF !queryParameters.isEmpty?,?ENDIF??EXPAND Features::methodParameter FOREACH queryParameters SEPARATOR ","?) {
    	?IF many-?
	    @SuppressWarnings("unchecked")
	    ?getType()? _resultSet = (?getType()?) _resultMap.get("_resultSet");
	    return _resultSet;
	    ?ELSEIF ComplexType.isInstance(type)-?
	    ?type.name? _?type.name.toFirstLower()? = new ?type.name?();
	    ?FOREACH callableStatement.outParameter.select(e|!ComplexType.isInstance(e.attribute.dataType)) AS outParameter-?
	    ?IF outParameter.attribute.many-?
	    @SuppressWarnings("unchecked")
	    ?registerImport("java.util.List")? _?outParameter.attribute.name?ResultSet = (List) _resultMap.get("_?outParameter.attribute.name?_resultSet");
	    _?type.name.toFirstLower()?.?outParameter.attribute.getMutatorMethodName()?(_?outParameter.attribute.name?ResultSet);
	    ?ELSEIF !outParameter.attribute.many-?
		_?type.name.toFirstLower()?.?outParameter.attribute.getMutatorMethodName()?((?outParameter.attribute.type.getFullyQualifiedName(false)?)_resultMap.get("?outParameter.name?"));
	    ?ENDIF-?
		?ENDFOREACH-?
		?FOREACH callableStatement.outParameter.attribute.select(e|e.many && ComplexType.isInstance(e.dataType)).toSet() AS complexTypeAttribute-?
		@SuppressWarnings("unchecked")
	    ?registerImport("java.util.List")? _?complexTypeAttribute.name?ResultSet = (List) _resultMap.get("_?complexTypeAttribute.name?_resultSet");
	    _?type.name.toFirstLower()?.?complexTypeAttribute.getMutatorMethodName()?(_?complexTypeAttribute.name?ResultSet);
		?ENDFOREACH-?
		?FOREACH callableStatement.outParameter.attribute.select(e|!e.many && ComplexType.isInstance(e.dataType)).toSet() AS complexTypeAttribute-?
		?FOREACH callableStatement.outParameter.select(e|e.attribute==complexTypeAttribute && e.nestedAttribute!=null) AS outParameter ITERATOR index-?
		?IF index.firstIteration-?
		?complexTypeAttribute.dataType.getFullyQualifiedName(false)? _?complexTypeAttribute.name? = new ?complexTypeAttribute.dataType.getFullyQualifiedName(false)?();
		_?type.name.toFirstLower()?.?complexTypeAttribute.getMutatorMethodName()?(_?complexTypeAttribute.name?);
		?ENDIF-?
		_?complexTypeAttribute.name?.?outParameter.nestedAttribute.getMutatorMethodName()?((?outParameter.nestedAttribute.type.getFullyQualifiedName(false)?)_resultMap.get("?outParameter.name?"));
		?ENDFOREACH-?
		?ENDFOREACH-?
	    return _?type.name.toFirstLower()?;
	    ?ELSE-?
	    return (?getType()?) ?IF callableStatement.functionCall?_resultMap.get("return")?ELSE?_resultMap.get("?callableStatement.outParameter.first().name?")?ENDIF?;
	    ?ENDIF-?    
    }
    ?ENDIF-?
?ENDLET-?
?ELSE-?
?EXPAND queryOperationSignature("public") FOR this-? {
		String queryName = ?getDaoConstantName()?;
        Query namedQuery = this.sessionFactory.getCurrentSession().getNamedQuery(queryName);
        ?FOREACH queryParameters.reject(e|Parameter.isInstance(e) && (((Parameter)e).name=="firstResult" || ((Parameter)e).name=="maxResults")) AS parameter ITERATOR iter-?
        ?LET statement.eAllContents.typeSelect(QueryParameterValue).selectFirst(e|e.parameter==parameter || e.parameter==parameter.attribute) AS queryParameterValue-?
        ?IF queryParameterValue != null-?
        ?IF Entity.isInstance(parameter.getParameterType()) && !parameter.isMany() && queryParameterValue.attribute==null-?
        namedQuery.setEntity?IF parameter.isMany()?List?ENDIF?("?parameter.getName()?", ?parameter.getName()?);
        ?ELSEIF ComplexType.isInstance(parameter.getParameterType()) && queryParameterValue.attribute!=null-?
        ?FOREACH statement.eAllContents.typeSelect(QueryParameterValue).select(e|e.parameter==parameter).attribute.toSet().sortBy(e|e.name) AS attribute-?
        namedQuery.?attribute.type.getSetParameterMethodName()??IF attribute.many?List?ENDIF?("?parameter.getName()?_?attribute.name?", ?parameter.getName()?.?attribute.getAccessorMethodName()?());
        ?ENDFOREACH-?
        ?ELSE-?
        namedQuery.?parameter.getSetParameterMethodName()??IF parameter.isMany()?List?ENDIF?("?parameter.getName()?", ?parameter.getName()?);
        ?ENDIF-?
        ?ENDIF-?
        ?ENDLET-?
        ?ENDFOREACH-?
        apply?name.toFirstUpper()?QueryHints(namedQuery?IF !queryParameters.isEmpty?,?ENDIF??FOREACH queryParameters AS parameter SEPARATOR "," ??parameter.getName()??ENDFOREACH?);
        ?IF UpdateStatement.isInstance(statement) || DeleteStatement.isInstance(statement)-?
        ?IF type!=null?return ?ENDIF?namedQuery.executeUpdate();
        ?ELSEIF DataView.isInstance(type) && SelectProperties.isInstance(statement)-?
        ?IF many-?
        return getNamedQueryMapper(queryName).createAndMapMany(list(namedQuery), ?type.name?.class, ?registerImport("java.util.Collections")?.singletonMap(QUERY_NAME, queryName));
        ?ELSE-?
        Object[] tuple = unique(namedQuery);
        return map?name.toFirstUpper()?Tuple(tuple);
        ?ENDIF-?
        ?ELSEIF many-?
        ?IF !statement.eAllContents.typeSelect(Join).isEmpty-?
        Collection result = list(namedQuery);
        return new ?registerImport("java.util.LinkedHashSet")?(result);
        ?ELSE-?
        return list(namedQuery);
        ?ENDIF-?
        ?ELSEIF type!=null-?
        return unique(namedQuery);
        ?ENDIF-?
    }

    protected void apply?name.toFirstUpper()?QueryHints(Query query?IF !queryParameters.isEmpty?,?ENDIF??EXPAND Features::methodParameter FOREACH queryParameters SEPARATOR ","?) {
           ?FOREACH queryParameters.select(e|dom::Parameter.isInstance(e)) AS parameter ITERATOR iter-?
        ?IF parameter.getName()=="firstResult"-?
        if (firstResult!=null) {
            query.setFirstResult(?parameter.getName()?);
        }
        ?ELSEIF parameter.getName()=="maxResults"-?
        if (maxResults!=null) {
            query.setMaxResults(?parameter.getName()?);
        }
        ?ENDIF-?
        ?ENDFOREACH-?
        // override this method and apply other hints that influence how a query is executed
    }
    ?IF DataView.isInstance(type) && SelectProperties.isInstance(statement)-?

    ?LET ((DataView)type) AS dataView-?
    protected ?type.name? map?name.toFirstUpper()?Tuple(Object[] tuple?IF many?, int rowNumber?ENDIF?) {
        ?type.name? ?type.name.toFirstLower()? = null;
    	if (tuple!=null) {
    		?type.name.toFirstLower()? = new ?type.name?();
	        ?LET ((SelectProperties)statement) AS selectProperties-?
	        ?FOREACH selectProperties.properties AS expression ITERATOR index-?
	        ?IF AliasedExpression.isInstance(expression) && dataView.allAttributes.selectFirst(e|e.name==((AliasedExpression)expression).name)!=null-?
	        ?LET dataView.allAttributes.selectFirst(e|e.name==((AliasedExpression)expression).name) AS attribute-?
	        ?type.name.toFirstLower()?.?attribute.getMutatorMethodName()?((?attribute.type.getFullyQualifiedName(false)?)tuple[?index.counter0?]);
	        ?ENDLET-?
	        ?ELSEIF PropertyValue.isInstance(expression) && dataView.allAttributes.selectFirst(e|e.name==((PropertyValue)expression).segments.last())!=null-?
	        ?LET dataView.allAttributes.selectFirst(e|e.name==((PropertyValue)expression).segments.last()) AS attribute-?
	        ?type.name.toFirstLower()?.?attribute.getMutatorMethodName()?((?attribute.type.getFullyQualifiedName(false)?)tuple[?index.counter0?]);
	        ?ENDLET-?
	        ?ENDIF-?
	        ?ENDFOREACH-?
	        ?ENDLET-?
    	}
        return ?type.name.toFirstLower()?;
    }
    ?ENDLET-?
    ?ENDIF-?
?ENDIF-?
?ENDDEFINE?

?DEFINE daoOperationImpl FOR Operation?
?EXPAND daoOperationSignature("public") FOR this-? {
        ?FOREACH parameters.select(e|e.name!="firstResult" && e.name!="maxResults") AS parameter-?
        Assert.notNull(?parameter.name.toFirstLower()-?, "Parameter '?parameter.name.toFirstLower()-?' must not be null");
        ?ENDFOREACH-?
        Query namedQuery = this.sessionFactory.getCurrentSession().getNamedQuery("?((Dao)eContainer).entity.name?.?name.toFirstUpper()?");
        ?IF expression.contains("?")-?
        ?FOREACH parameters AS parameter ITERATOR iter-?
        namedQuery.setParameter(?iter.counter0?, ?parameter.name?);
        ?ENDFOREACH-?
        ?ELSE-?
        ?FOREACH parameters AS parameter ITERATOR iter-?
        ?IF parameter.name=="firstResult"-?
        if (firstResult!=null) {
            namedQuery.setFirstResult(?parameter.name?);
        }
        ?ELSEIF parameter.name=="maxResults"-?
        if (maxResults!=null) {
            namedQuery.setMaxResults(?parameter.name?);
        }
        ?ELSEIF SimpleType.isInstance(parameter.type) && ((SimpleType)parameter.type).validatorReference.isDateValidator()-?
        namedQuery.setDate?IF parameter.many?List?ENDIF?("?parameter.name?", ?parameter.name?);
        ?ELSEIF SimpleType.isInstance(parameter.type) && ((SimpleType)parameter.type).validatorReference.isTimestampValidator()-?
        namedQuery.setTimestamp?IF parameter.many?List?ENDIF?("?parameter.name?", ?parameter.name?);
        ?ELSEIF Entity.isInstance(parameter.type) && !parameter.many-?
        namedQuery.setEntity("?parameter.name?", ?parameter.name?);
        ?ELSE-?
        namedQuery.setParameter?IF parameter.many?List?ENDIF?("?parameter.name?", ?parameter.name?);
        ?ENDIF-?
        ?ENDFOREACH-?
        ?ENDIF-?
        apply?name.toFirstUpper()?QueryHints(namedQuery?IF !parameters.isEmpty?,?ENDIF??FOREACH parameters AS parameter SEPARATOR "," ??parameter.name??ENDFOREACH?);
        return ?IF many?list(namedQuery)?ELSE?unique(namedQuery)?ENDIF?;
    }

    protected void apply?name.toFirstUpper()?QueryHints(Query query?IF !parameters.isEmpty?,?ENDIF??EXPAND Features::methodParameter FOREACH parameters SEPARATOR ","?) {
           //apply other hints that influence how a query is executed
    }
?ENDDEFINE?

?DEFINE daoOperationSignature(String visibilityModifier) FOR Operation-?
    ?IF visibilityModifier!=null-?
    ?ELSE-?
    /**
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH parameters-?
     ?IF many-?
     * @return a collection containing 0 or more persistent ?type.name? instances
     ?ELSE-?
     * @return the ?type.name.toFirstLower()? instance, or null if not found
     ?ENDIF-?
     */
     ?ENDIF-?
    ?IF visibilityModifier!=null-?
    ?visibilityModifier-? ?ENDIF??getType()? ?name?(?EXPAND Features::methodParameter FOREACH parameters SEPARATOR ","??")"-?
?ENDDEFINE?

?DEFINE queryOperationSignature(String visibilityModifier) FOR QueryOperation-?
    ?IF visibilityModifier!=null-?
    ?ELSE-?
    /**
?EXPAND Documentation::documentationLinesIndented FOR this-?
     *
     ?EXPAND Features::methodParameterJavaDoc FOREACH queryParameters-?
     ?IF many-?     
     * @return a collection containing 0 or more persistent ?type.name? instances
     ?ELSE-?
     * @return the ?type.name.toFirstLower()? instance, or null if not found
     ?ENDIF-?
     */
     ?ENDIF-?
    ?IF visibilityModifier!=null-?
    ?visibilityModifier-? ?ENDIF??getType()? ?name?(?EXPAND Features::methodParameter FOREACH queryParameters SEPARATOR ","??")"-?
?ENDDEFINE?
/**
 * Generates the hbm.xml for the given entity
 **/
?DEFINE hibernateMapping(Model model) FOR Dao?
?info("Write "+getHbmXmlFileName())?
?FILE getHbmXmlFileName() OUTLET_GENERATED_RESOURCES-?



    ?EXPAND hibernateClassMapping(model)-?
    ?EXPAND namedQueries-?
    ?EXPAND namedQueries FOREACH getDaosForSubClasses(model,entity)-?

?ENDFILE?
?ENDDEFINE?

/**
 * Generates the hbm.gen.xml for the given entity
 **/
?DEFINE hibernateGenMapping(Model model) FOR Dao?
?info("Write "+getGeneratedHbmXmlFileName())?
?FILE getGeneratedHbmXmlFileName() OUTLET_GENERATED_RESOURCES-?



    ?EXPAND hibernateClassMapping(model)-?
    ?EXPAND namedQueries-?
    ?EXPAND namedQueries FOREACH getDaosForSubClasses(model,entity)-?

?ENDFILE?
?ENDDEFINE?

/**
 * Generates the hbm.fragment.xml for the given entity
 **/
?DEFINE hibernateFragmentMapping(Model model) FOR Dao?
?info("Write "+getFragmentHbmXmlFileName())?
?FILE getFragmentHbmXmlFileName() OUTLET_RESOURCES-?



    
	
	

        
    

    

?ENDFILE?
?ENDDEFINE?

?DEFINE hibernateClassMapping(Model model) FOR Dao-?
    
		?IF entity.txtDescription!=null-?
        
		?ENDIF-?
        ?IF primaryKey!=null-?
        
            ?EXPAND column FOR primaryKeyColumn-?
            ?EXPAND type FOR primaryKeyColumn-?
            
        
        ?ELSE-?
        
        ?FOREACH naturalKeyColumns AS naturalKeyColumn-?
            
                ?EXPAND column FOR naturalKeyColumn-?
                ?EXPAND type FOR naturalKeyColumn-?
            
        ?ENDFOREACH-?
        
        ?ENDIF-?
        ?IF !getDaosForSubClasses(model,entity).isEmpty-?
        
        ?ENDIF-?
        ?IF versionColumn!=null-?
        ?LET versionColumn.attribute.getImplementationType() AS versionType-?
        
            ?EXPAND column FOR versionColumn-?
        
        ?ENDLET-?
        ?ENDIF-?
        ?IF primaryKey!=null-?
        ?EXPAND property FOREACH columns.reject(e|e.attribute.identifier || e.attribute.version || manyToOneAssociations.columnName.contains(e.columnName))-?
        ?ELSE-?
        ?EXPAND property FOREACH columns.select(e|true).removeAll(naturalKeyColumns).reject(e|e.attribute.identifier || e.attribute.version || manyToOneAssociations.columnName.contains(e.columnName))-?
        ?ENDIF-?
        ?EXPAND relation FOREACH oneToManyAssociations-?
        ?EXPAND relation FOREACH manyToOneAssociations-?
        ?EXPAND relation FOREACH oneToOneAssociations-?
        ?EXPAND relation FOREACH manyToManyAssociations-?
        ?FOREACH getDaosForSubClasses(model,entity) AS daoForSubClass-?
        
            ?EXPAND property FOREACH daoForSubClass.columns.select(e|daoForSubClass.entity.attributes.exists(sca|sca.name==e.attribute.name))-?
            ?EXPAND relation FOREACH daoForSubClass.oneToManyAssociations-?
            ?EXPAND relation FOREACH daoForSubClass.manyToOneAssociations-?
            ?EXPAND relation FOREACH daoForSubClass.oneToOneAssociations-?
            ?EXPAND relation FOREACH daoForSubClass.manyToManyAssociations-?
        
        ?ENDFOREACH-?
    
?ENDDEFINE?

?DEFINE property FOR Column-?
?IF null!=columns && !columns.isEmpty-?
        
?FOREACH columns AS column-?
            
                ?EXPAND column FOR column-?
                ?EXPAND type FOR column-?
            
?ENDFOREACH-?
        
?ELSE-?
        
            ?EXPAND column FOR this-?
            ?EXPAND type FOR this-?
        
?ENDIF-?
?ENDDEFINE?

?DEFINE column FOR Column-?
			
			?IF hasComment()-?
				
			
			?ENDIF-?
?ENDDEFINE?


?DEFINE type FOR Column-?
?IF userType!=null-?
            ?IF userType.parameterValues.isEmpty-?
            
            ?ELSE-?
            
            ?FOREACH userType.parameterValues AS parameterValue ITERATOR index-?
                ?parameterValue.getValueAsString()?
            ?ENDFOREACH-?
              
            ?ENDIF-?
?ENDIF-?
?ENDDEFINE?

?DEFINE relation FOR OneToMany-?
        
            ?IF !columns.isEmpty-?
            
            ?FOREACH columns AS foreignKeyColumn-?
                
            ?ENDFOREACH-?
            
            ?ELSE-?
            
            ?ENDIF-?
            
        
?ENDDEFINE?

?DEFINE relation FOR ManyToMany-?
        
            
            
        
?ENDDEFINE?

?DEFINE relation FOR ManyToOne-?
        
            ?IF !columns.isEmpty-?
            ?FOREACH columns AS foreignKeyColumn-?
            
            ?ENDFOREACH-?
            ?ELSE-?
            
            ?ENDIF-?
        
?ENDDEFINE?
?DEFINE relation FOR OneToOne-?
        
?ENDDEFINE?

?DEFINE namedQueries FOR Dao-?
    ?FOREACH operations.select(e|e.expression!=null) AS operation-?
    
    ?ENDFOREACH-?
    ?FOREACH queryOperation.select(e|!CallableStatement.isInstance(e.statement)) AS queryOperation-?
    
    
    
    ?ENDFOREACH-?
?ENDDEFINE?

?DEFINE statement FOR QlStatement??ENDDEFINE?
?DEFINE statement FOR DeleteStatement?
delete ?entity.getClassName()? as ?name? ?IF where!=null?where ?EXPAND expression FOR where? ?ENDIF-?
?ENDDEFINE?
?DEFINE statement FOR InsertStatement?
insert into ?entity.getClassName()? (?EXPAND expression FOREACH expression SEPARATOR ','?)  ?EXPAND statement FOR selectStatement?
?ENDDEFINE?
?DEFINE statement FOR UpdateStatement?
update?IF versioned? versioned?ENDIF? ?entity.getClassName()? as ?name?
set ?FOREACH assignment AS propertyAssignment SEPARATOR ','??EXPAND expression FOR propertyAssignment.property? = ?EXPAND expression FOR propertyAssignment.expression??ENDFOREACH?
?IF where!=null-?
where ?EXPAND expression FOR where-?
?ENDIF-?
?ENDDEFINE?

?DEFINE statement FOR SelectStatement?
?EXPAND commonSelect FOR this-?
?ENDDEFINE?

?DEFINE statement FOR SelectProperties?
select ?IF distinct?distinct ?ENDIF??FOREACH properties AS property SEPARATOR ','??EXPAND expression FOR property??ENDFOREACH??" "-?
?EXPAND commonSelect FOR this-?
?ENDDEFINE?
?DEFINE statement FOR SelectClass?
select new ?class?(?FOREACH arguments AS argument SEPARATOR ','??EXPAND expression FOR argument??ENDFOREACH?)
?EXPAND commonSelect FOR this-?
?ENDDEFINE?
?DEFINE statement FOR SelectObject?
select object(?name?)
?EXPAND commonSelect FOR this-?
?ENDDEFINE?

?DEFINE commonSelect FOR SelectStatement-?
?IF !from.isEmpty-?
from ?FOREACH from AS from SEPARATOR ','??EXPAND fromRange FOR from??ENDFOREACH-?
?ENDIF-?
?FOREACH join AS join?
?IF join.type!=null? ?join.type??ENDIF? join ?IF join.fetch?fetch ?ENDIF??join.entity.name?.?join.reference.name? as ?join.name? ?IF join.propertyFetch?fetch all properties?ENDIF??IF join.expression!=null? with ?EXPAND expression FOR join.expression??ENDIF-?
?ENDFOREACH-?
?IF where!=null?
where ?EXPAND expression FOR where-?
?ENDIF-?
?IF !groupBy.isEmpty?
group by ?FOREACH groupBy AS groupBy SEPARATOR ','??EXPAND expression FOR groupBy??ENDFOREACH??IF having!=null? having ?EXPAND expression FOR having? ?ENDIF-?
?ENDIF-?
?IF !orderBy.isEmpty?
order by ?FOREACH orderBy AS orderBy SEPARATOR ','??EXPAND expression FOR orderBy.expression? ?orderBy.sortOrder??ENDFOREACH-?
?ENDIF-?
?ENDDEFINE?

?DEFINE fromRange FOR FromRange??ENDDEFINE?
?DEFINE fromRange FOR FromClass??entity.getClassName()? as ?name??IF popertyFetch? fetch all properties?ENDIF??ENDDEFINE?
?DEFINE fromRange FOR InClass??name? in class ?class??ENDDEFINE?
?DEFINE fromRange FOR InCollection?in (?path?) ?alias??ENDDEFINE?
?DEFINE fromRange FOR InCollectionElements??name? in elements (?reference?)?ENDDEFINE?

?DEFINE expression FOR AliasedExpression??EXPAND expression FOR expression? ?IF name!=null? as ?name? ?ENDIF??ENDDEFINE?
?DEFINE expression FOR Expression??ENDDEFINE?
?DEFINE expression FOR BinaryExpression??EXPAND expression FOR left? ?operator? ?EXPAND expression FOR right??ENDDEFINE?
?DEFINE expression FOR UnaryExpression??operator??EXPAND expression FOR expression??ENDDEFINE?
?DEFINE expression FOR NotExpression? not ?EXPAND expression FOR expression??ENDDEFINE?
?DEFINE expression FOR InExpression??EXPAND expression FOR expression??IF not? not?ENDIF? ?operator? ?EXPAND expression FOR in??ENDDEFINE?
?DEFINE expression FOR BetweenExpression??EXPAND expression FOR expression??IF not? not?ENDIF? ?operator? ?EXPAND expression FOR left? and ?EXPAND expression FOR right??ENDDEFINE?
?DEFINE expression FOR LikeExpression??EXPAND expression FOR expression??IF not? not?ENDIF? ?operator? ?EXPAND expression FOR like??IF escape!=null? escape ?EXPAND expression FOR escape??ENDIF??ENDDEFINE?
?DEFINE expression FOR MemberOfExpression??EXPAND expression FOR expression??IF not? not?ENDIF? ?operator? of ?memberOf??ENDDEFINE?
?DEFINE expression FOR PropertyValue??name??FOREACH segments AS e?.?e??ENDFOREACH??ENDDEFINE?

?DEFINE expression FOR FunctionCall??function?(?EXPAND expression FOREACH arguments SEPARATOR ','?)?ENDDEFINE?
?DEFINE expression FOR TrimFunction?trim(?IF mode!=null??mode? ?ENDIF??IF character!=null??character? from ?ENDIF??EXPAND expression FOR from?)?ENDDEFINE?
?DEFINE expression FOR CastFunction?
?IF 'cast'==function-?
?function?(?EXPAND expression FOR from? as ?name?)
?ELSE-?
?function?(?name? from ?EXPAND expression FOR from?)
?ENDIF-?
?ENDDEFINE?
?DEFINE expression FOR AggregateFunction??IF aggregateExpression!=null??function?(?EXPAND expression FOR aggregateExpression?)?ELSE??function?(?IF all?*?ELSEIF distinct?distinct ?ENDIF??IF from!=null??from??ELSE??EXPAND expression FOR collection??ENDIF?)?ENDIF??ENDDEFINE?
?DEFINE expression FOR QueryParameterValue?:?dom::Parameter.isInstance(parameter) ? ((dom::Parameter)parameter).name:((Attribute)parameter).name??IF attribute!=null?_?attribute.name??ENDIF??ENDDEFINE?
?DEFINE expression FOR QuantifiedExpression??quantifier? ?EXPAND expression FOR expression? ?name??ENDDEFINE?

?DEFINE expression FOR CaseExpression?
?IF expression==null-?
case ?EXPAND expression FOREACH whenClause? ?IF null!=elseExpression? else ?EXPAND expression FOR elseExpression? ?ENDIF? end
?ELSE-?
case ?EXPAND expression FOR expression? ?EXPAND expression FOREACH altWhenClause??IF elseExpression!=null? else ?EXPAND expression FOR elseExpression? ?ENDIF? end
?ENDIF-?
?ENDDEFINE?
?DEFINE expression FOR WhenClause? when ?EXPAND expression FOR whenExpression? then ?EXPAND expression FOR thenExpression??ENDDEFINE?
?DEFINE expression FOR AltWhenClause? when ?EXPAND expression FOR whenExpression? then ?EXPAND expression FOR thenExpression??ENDDEFINE?

?DEFINE expression FOR CollectionFunction??function? ?EXPAND expression FOR property??ENDDEFINE?
?DEFINE expression FOR SubQuery?(?EXPAND statement FOREACH queries SEPARATOR 'union'?)?ENDDEFINE?
?DEFINE expression FOR ParenthesizedExpression?(?EXPAND expression FOREACH expressions SEPARATOR ','?)?ENDDEFINE?

?DEFINE expression FOR StringLiteralValue?'?value?'?ENDDEFINE?
?DEFINE expression FOR IntegerLiteralValue??value??ENDDEFINE?
?DEFINE expression FOR RealLiteralValue??value??ENDDEFINE?
?DEFINE expression FOR BooleanLiteralValue??isTrue ? 'true':'false'??ENDDEFINE?
?DEFINE expression FOR EmptyLiteralValue?empty?ENDDEFINE?
?DEFINE expression FOR NullLiteralValue?null?ENDDEFINE?




© 2015 - 2024 Weber Informatics LLC | Privacy Policy