![JAR search and dependency download from the Maven repository](/logo.png)
uk.theretiredprogrammer.nbpcg.templates.remoteentity.template Maven / Gradle / Ivy
<#--
Copyright 2015-2017 Richard Linsdale.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<#if license = "apache20" >
/*
* Copyright ${copyright}.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if>
<#if license = "gpl30" >
/*
* Copyright (C) ${copyright}
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#if>
<#if license = "lgpl21" >
/*
* Copyright (C) ${copyright}
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#if>
<#-- Freemarker Template for Remote Entity class -->
<#assign templateauthor = "Richard Linsdale (richard at theretiredprogrammer.uk)" />
<#assign PSTORE = persistencestore[usepersistencestore] >
<#list PSTORE.persistenceentity![] as entity >
<#if entity.name = useentity >
package ${package};
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import javax.json.JsonValue;
import javax.json.stream.JsonGenerator;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Query;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import uk.theretiredprogrammer.jeelibrary.IdandstampEntity;
import uk.theretiredprogrammer.jeelibrary.JsonUtil;
/**
* The ${entity.name} Remote Entity.
*
* (Class generated by NetBeans Platform Code Generator tools using ${DEFINITION_FILE}.
* Do not edit this file. Apply any changes to the definition file and regenerate all files.)
*
* @author ${templateauthor}
*/
@Entity
@Table(name = "${entity.name}")
@NamedQueries({
@NamedQuery(name = "${entity.name}.findAll", query = "SELECT a FROM ${entity.name} a"),
<#list entity.persistencefield![] as field >
@NamedQuery(name = "${entity.name}.findBy${field.name?cap_first}", query = "SELECT a FROM ${entity.name} a WHERE a.${field.name} = :${field.name}"),
#list>
})
public class ${entity.name} extends IdandstampEntity<${entity.name}> implements Serializable {
private static final long serialVersionUID = 1L;
<#list entity.persistencefield![] as field >
<#if field.primarykey = "yes">
@Id
#if>
<#if field.primarykey = "auto">
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
#if>
<#if field.jsontype = "Reference">
@Basic(optional = false)
<#if !field.nullallowed?? >
@NotNull
#if>
@Column(name = "${field.name}")
private Integer ${field.name};
<#elseif field.jsontype = "String">
@Basic(optional = false)
@NotNull
@Size(min = ${field.min}, max = ${field.max})
@Column(name = "${field.name}")
private String ${field.name};
<#else>
@Basic(optional = false)
@NotNull
@Column(name = "${field.name}")
private ${field.jsontype} ${field.name};
#if>
#list>
public static List<${entity.name}> queryByName(EntityManager em, String field, Object value) throws IOException {
Query query;
switch (field) {
<#list entity.persistencefield![] as field >
case "${field.name}":
query = em.createNamedQuery("${entity.name}.findBy${field.name?cap_first}");
query.setParameter("${field.name}", value);
return query.getResultList();
#list>
default:
throw new IOException("Unknown filter field requested (" + field + ")");
}
}
@Override
public void setField(String key, JsonValue value) throws ClassCastException {
switch (key) {
<#list entity.persistencefield![] as field >
case "${field.name}":
${field.name} = JsonUtil.get${field.jsontype}Value(value);
return;
#list>
default:
throw new ClassCastException();
}
}
@Override
public void writeField(JsonGenerator generator, String key) throws ClassCastException {
switch (key) {
<#list entity.persistencefield![] as field >
case "${field.name}":
generator.write("${field.name}", ${field.name});
return;
#list>
default:
throw new ClassCastException();
}
}
@Override
public void writePK(JsonGenerator generator) {
generator.write(id);
}
@Override
public void writePKwithkey(JsonGenerator generator) {
generator.write("pkey", id);
}
@Override
public void writeAllFields(JsonGenerator generator, String label) {
if (label == null ) {
generator.writeStartObject();
} else {
generator.writeStartObject(label);
}
<#list entity.persistencefield![] as field >
generator.write("${field.name}", ${field.name});
#list>
generator.writeEnd();
}
<#list entity.persistencefield![] as field >
<#if field.jsontype = "Reference" | field.jsontype = "Integer" >
<#if field.sys??>
@Override
public Integer get${field.name?cap_first}() {
return ${field.name};
}
@Override
public void set${field.name?cap_first}(Integer ${field.name}) {
this.${field.name} = ${field.name};
}
<#else>
/**
* Get the ${field.name}
*
* @return the value
*/
public Integer get${field.name?cap_first}() {
return ${field.name};
}
/**
* Set the ${field.name}
*
* @param ${field.name} the value
*/
public void set${field.name?cap_first}(Integer ${field.name}) {
this.${field.name} = ${field.name};
}
#if>
<#elseif field.jsontype = "Boolean" >
/**
* Get the ${field.name}
*
* @return the value
*/
public Boolean get${field.name?cap_first}() {
return ${field.name};
}
/**
* Set the ${field.name}
*
* @param ${field.name} the value
*/
public void set${field.name?cap_first}(Boolean ${field.name}) {
this.${field.name} = ${field.name};
}
<#elseif field.jsontype = "String" >
/**
* Get the ${field.name}
*
* @return the value
*/
public String get${field.name?cap_first}() {
return ${field.name};
}
<#if field.sys??>
@Override
public void set${field.name?cap_first}(String ${field.name}) {
this.${field.name} = ${field.name};
}
<#else>
/**
* Set the ${field.name}
*
* @param ${field.name} the value
*/
public void set${field.name?cap_first}(String ${field.name}) {
this.${field.name} = ${field.name};
}
#if>
#if>
#list>
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof ${entity.name})) {
return false;
}
${entity.name} other = (${entity.name}) object;
return this.id.equals(other.id);
}
@Override
public String toString() {
return "${entity.name}[ id=" + id + " ]";
}
}
#if>
#list>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy