<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
  PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    
	<query name="BaseAll">
		<![CDATA[from magoffin.matt.ieat.domain.Base base order by lower(base.Value) asc]]>
	</query>

	<query name="CourseAll">
		<![CDATA[from magoffin.matt.ieat.domain.Course course order by lower(course.Value) asc]]>
	</query>

	<query name="DifficultyAll">
		<![CDATA[from magoffin.matt.ieat.domain.Difficulty difficulty order by difficulty.id asc]]>
	</query>

	<query name="EthnicityAll">
		<![CDATA[from magoffin.matt.ieat.domain.Ethnicity ethnicity order by lower(ethnicity.Value) asc]]>
	</query>

	<query name="IngredientAll">
		<![CDATA[from magoffin.matt.ieat.domain.Ingredient ingredient order by lower(ingredient.Name) asc]]>
	</query>

	<query name="MealsForUser">
		<![CDATA[from magoffin.matt.ieat.domain.Meal meal where meal.Owner.id = ? order by lower(meal.Name) asc]]>
	</query>

	<query name="PrepTimeAll">
		<![CDATA[from magoffin.matt.ieat.domain.PrepTime prep order by prep.id asc]]>
	</query>

	<query name="RecipeAll">
		<![CDATA[from magoffin.matt.ieat.domain.Recipe recipe order by recipe.id asc]]>
	</query>
	
	<query name="RecipeAllCount">
		<![CDATA[select count(*) from magoffin.matt.ieat.domain.Recipe]]>
	</query>
	
	<query name="RecipeUsedAsIngredient">
		<![CDATA[
			select rr
			from magoffin.matt.ieat.domain.Recipe rr, 
				magoffin.matt.ieat.domain.RecipeIngredient ri
			where ri in elements(rr.Ingredient)
			and ri.Recipe.id = ?
			order by lower(rr.Name)
		]]>
	</query>
	
	<query name="SystemAll">
		<![CDATA[from magoffin.matt.ieat.domain.System sys order by lower(sys.Value) asc]]>
	</query>

	<query name="UserByEmail">
		<![CDATA[from magoffin.matt.ieat.domain.User user where lower(user.Email) = lower(?)]]>
	</query>

	<query name="UserByLogin">
		<![CDATA[from magoffin.matt.ieat.domain.User user where user.Login = ?]]>
	</query>

	<query name="UsersForAccessLevel">
		<![CDATA[from magoffin.matt.ieat.domain.User user where user.AccessLevel >= ?]]>
	</query>

	<query name="UnitsAll">
		<![CDATA[from magoffin.matt.ieat.domain.Unit units order by lower(units.Value) asc]]>
	</query>
	
	<query name="UnitsForSystem">
		<![CDATA[from magoffin.matt.ieat.domain.Unit units where units.SystemId = ? or units.SystemId is null order by lower(units.Value) asc]]>
	</query>
	
	<!-- SQL queries below -->

	<sql-query name="UsersStaleRegistration">
		<return alias="users" class="magoffin.matt.ieat.domain.User"/>
		<![CDATA[select {users.*} from users {users} where users.createdDate < (CURRENT_DATE - INTERVAL '14 DAYS') and users.accessLevel < 0]]>
	</sql-query>

</hibernate-mapping>
