com.gtcgroup.justify.jpa.po.JstQueryLanguageJpaPO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of justify-jpa Show documentation
Show all versions of justify-jpa Show documentation
JPA MODULE: PED Central is the home for the open-source �Justify� suite of software engineering modules. Justify seeks API alignment between Java 1.8+ application code and JUnit 5 test code.
/*
* [Licensed per the Open Source "MIT License".]
*
* Copyright (c) 2006 - 2017 by
* Global Technology Consulting Group, Inc. at
* http://gtcGroup.com
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.gtcgroup.justify.jpa.po;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import com.gtcgroup.justify.core.exception.internal.JustifyRuntimeException;
import com.gtcgroup.justify.jpa.po.internal.BaseQueryJpaPO;
/**
* This Parameter Object class supports native and query language queries.
*
*
* Copyright (c) 2006 - 2017 by Global Technology Consulting Group, Inc. at
* gtcGroup.com .
*
*
* @author Marvin Toll
* @since v.6.2
*/
public class JstQueryLanguageJpaPO extends BaseQueryJpaPO {
/**
* This method initializes the class.
*
* @return {@link JstQueryLanguageJpaPO}
*/
public static JstQueryLanguageJpaPO withQuery(final boolean suppressExceptionForNull) {
return new JstQueryLanguageJpaPO(suppressExceptionForNull);
}
protected String queryLanguageString;
protected Class> entityClass;
/**
* Constructor
*/
protected JstQueryLanguageJpaPO(final boolean suppressExceptionForNull) {
super(suppressExceptionForNull);
return;
}
/**
* @return {@link Query}
*/
protected Query createQueryLanguageQuery(final String queryLanguageString) {
return getEntityManager().createQuery(queryLanguageString);
}
/**
* @return {@link TypedQuery}
*/
protected TypedQuery createQueryLanguageQuery(final String queryLanguageString,
final Class resultClass) {
return getEntityManager().createQuery(queryLanguageString, resultClass);
}
/**
* @return {@link Query}
*/
@Override
public Query getQuery() {
if (null == this.query) {
try {
if (isResultClass() && isQueryLanaguageString()) {
this.query = createQueryLanguageQuery(getQueryLanguageString(), getEntityClass());
} else if (isQueryLanaguageString()) {
this.query = createQueryLanguageQuery(getQueryLanguageString());
} else {
throw new JustifyRuntimeException(
"Verify that a coherent set of parameters were defined in the PO ["
+ this.getClass().getName() + "].");
}
} catch (final Exception e) {
throw new JustifyRuntimeException(e);
}
}
return this.query;
}
/**
* @return {@link String}
*/
public String getQueryLanguageString() {
return this.queryLanguageString;
}
/**
* @return {@link Class}
*/
@SuppressWarnings("unchecked")
public Class getEntityClass() {
return (Class) this.entityClass;
}
/**
* @return boolean
*/
public boolean isQueryLanaguageString() {
return null != this.queryLanguageString;
}
/**
* @return boolean
*/
public boolean isResultClass() {
return null != this.entityClass;
}
/**
* @return {@link JstQueryLanguageJpaPO}
*/
public JstQueryLanguageJpaPO withEntityManager(final EntityManager entityManager) {
return (JstQueryLanguageJpaPO) super.withEntityManager(entityManager);
}
/**
* @return {@link JstQueryLanguageJpaPO}
*/
@Override
public JstQueryLanguageJpaPO withPersistenceUnitName(final String persistenceUnitName) {
return (JstQueryLanguageJpaPO) super.withPersistenceUnitName(persistenceUnitName);
}
/**
* @return {@link JstQueryLanguageJpaPO}
*/
public JstQueryLanguageJpaPO withQueryLanguageString(final String queryLanguageString) {
this.queryLanguageString = queryLanguageString;
return this;
}
/**
* @return {@link JstQueryLanguageJpaPO}
*/
public JstQueryLanguageJpaPO withEntityClass(final Class entityClass) {
this.entityClass = entityClass;
return this;
}
}