001 // SECTION-START[License Header] 002 // <editor-fold defaultstate="collapsed" desc=" Generated License "> 003 /* 004 * Copyright (c) 2010 The JOMC Project 005 * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net> 006 * All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without 009 * modification, are permitted provided that the following conditions 010 * are met: 011 * 012 * o Redistributions of source code must retain the above copyright 013 * notice, this list of conditions and the following disclaimer. 014 * 015 * o Redistributions in binary form must reproduce the above copyright 016 * notice, this list of conditions and the following disclaimer in 017 * the documentation and/or other materials provided with the 018 * distribution. 019 * 020 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" 021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 022 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR 024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 031 * 032 * $Id: NamedQueryFactory.java 2236 2010-06-29 00:05:34Z schulte2005 $ 033 * 034 */ 035 // </editor-fold> 036 // SECTION-END 037 package org.jomc.sdk.jpa; 038 039 import java.util.Map; 040 import javax.persistence.EntityManager; 041 import javax.persistence.Query; 042 043 // SECTION-START[Documentation] 044 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 045 /** 046 * Factory providing a named JPA query instance. 047 * <p><b>Specifications</b><ul> 048 * <li>{@code 'javax.persistence.Query'} {@code (javax.persistence.Query)} {@code Multiton}</li> 049 * </ul></p> 050 * <p><b>Properties</b><ul> 051 * <li>"{@link #getParameterMap parameterMap}" 052 * <blockquote>Property of type {@code java.util.Map<String,Object>}. 053 * <p>Map of parameters to set on the query.</p> 054 * </blockquote></li> 055 * <li>"{@link #getQueryName queryName}" 056 * <blockquote>Property of type {@code java.lang.String}. 057 * <p>Name of the query to provide.</p> 058 * </blockquote></li> 059 * </ul></p> 060 * <p><b>Dependencies</b><ul> 061 * <li>"{@link #getEntityManager EntityManager}"<blockquote> 062 * Dependency on {@code 'javax.persistence.EntityManager'} {@code (javax.persistence.EntityManager)}.</blockquote></li> 063 * </ul></p> 064 * 065 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 066 * @version $Id: NamedQueryFactory.java 2236 2010-06-29 00:05:34Z schulte2005 $ 067 */ 068 // </editor-fold> 069 // SECTION-END 070 // SECTION-START[Annotations] 071 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 072 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 073 // </editor-fold> 074 // SECTION-END 075 public final class NamedQueryFactory 076 { 077 // SECTION-START[Query] 078 // SECTION-END 079 // SECTION-START[NamedQueryFactory] 080 081 public Query getObject() 082 { 083 final EntityManager em = this.getEntityManager(); 084 085 if ( em != null ) 086 { 087 final Query q = em.createNamedQuery( this.getQueryName() ); 088 089 for ( Map.Entry<String, Object> e : this.getParameterMap().entrySet() ) 090 { 091 q.setParameter( e.getKey(), e.getValue() ); 092 } 093 094 return q; 095 } 096 097 return null; 098 } 099 100 // SECTION-END 101 // SECTION-START[Constructors] 102 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 103 104 /** Creates a new {@code NamedQueryFactory} instance. */ 105 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 106 public NamedQueryFactory() 107 { 108 // SECTION-START[Default Constructor] 109 super(); 110 // SECTION-END 111 } 112 // </editor-fold> 113 // SECTION-END 114 // SECTION-START[Dependencies] 115 // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies "> 116 117 /** 118 * Gets the {@code EntityManager} dependency. 119 * <p>This method returns the {@code 'JOMC SDK JPA'} object of the {@code 'javax.persistence.EntityManager'} {@code (javax.persistence.EntityManager)} specification.</p> 120 * <p>That specification does not apply to any scope. A new object is returned whenever requested.</p> 121 * @return The {@code EntityManager} dependency. 122 * {@code null} if no object is available. 123 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 124 */ 125 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 126 private javax.persistence.EntityManager getEntityManager() 127 { 128 return (javax.persistence.EntityManager) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "EntityManager" ); 129 } 130 // </editor-fold> 131 // SECTION-END 132 // SECTION-START[Properties] 133 // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> 134 135 /** 136 * Gets the value of the {@code parameterMap} property. 137 * @return Map of parameters to set on the query. 138 * @throws org.jomc.ObjectManagementException if getting the property instance fails. 139 */ 140 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 141 private java.util.Map<String,Object> getParameterMap() 142 { 143 final java.util.Map<String,Object> _p = (java.util.Map<String,Object>) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "parameterMap" ); 144 assert _p != null : "'parameterMap' property not found."; 145 return _p; 146 } 147 148 /** 149 * Gets the value of the {@code queryName} property. 150 * @return Name of the query to provide. 151 * @throws org.jomc.ObjectManagementException if getting the property instance fails. 152 */ 153 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 154 private java.lang.String getQueryName() 155 { 156 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "queryName" ); 157 assert _p != null : "'queryName' property not found."; 158 return _p; 159 } 160 // </editor-fold> 161 // SECTION-END 162 // SECTION-START[Messages] 163 // SECTION-END 164 }