rb.templates.persistence_impl.erb Maven / Gradle / Ivy
<%#
# Copyright 2011 Rapleaf
#
# 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.
%>
<%= autogenerated %>
package <%= root_package %>.impl;
import java.sql.SQLRecoverableException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;
import java.sql.Timestamp;
import <%= JACK_NAMESPACE %>.AbstractDatabaseModel;
import <%= JACK_NAMESPACE %>.BaseDatabaseConnection;
import <%= JACK_NAMESPACE %>.queries.WhereConstraint;
import <%= JACK_NAMESPACE %>.queries.WhereClause;
import <%= JACK_NAMESPACE %>.util.JackUtility;
import <%= root_package %>.iface.<%= model_defn.iface_name %>;
import <%= root_package %>.models.<%= model_defn.model_name %>;
import <%= root_package %>.query.<%= model_defn.query_builder_name %>;
import <%= root_package %>.query.<%= model_defn.delete_builder_name %>;
import <%= project_defn.databases_namespace %>.IDatabases;
public class <%= model_defn.impl_name %> extends AbstractDatabaseModel<<%= model_defn.model_name %>> implements <%= model_defn.iface_name %> {
private final IDatabases databases;
public <%= model_defn.impl_name %>(BaseDatabaseConnection conn, IDatabases databases) {
super(conn, "<%= model_defn.table_name %>", Arrays.asList(<%= model_defn.fields.map{|x| "\"#{x.name}\""}.join(", ") %>));
this.databases = databases;
}
@Override
public <%= model_defn.model_name %> create(Map fieldsMap) throws IOException {
<% model_defn.fields.each do |field_defn| %>
<% if field_defn.default_value.nil? %>
<%= field_defn.java_type %> <%= field_defn.name %> = (<%= field_defn.java_type(true) %>) fieldsMap.get(<%= model_defn.model_name %>._Fields.<%= field_defn.name %>);
<% else %>
<%= field_defn.java_type(true) %> <%= field_defn.name %>_tmp = (<%= field_defn.java_type(true) %>) fieldsMap.get(<%= model_defn.model_name %>._Fields.<%= field_defn.name %>);
<%= field_defn.java_type %> <%= field_defn.name %> = <%= field_defn.name %>_tmp == null ? <%= field_defn.default_value %> : <%= field_defn.name %>_tmp;
<% end %>
<% end %>
return create(<%= model_defn.fields.map{|field| field.name }.join(', ') %>);
}
<%= render_create_method(model_defn, create_signature_full) %>
<% unless create_signature_small.nil? %>
<%= render_create_method(model_defn, create_signature_small, true) %>
<% end %>
public <%= model_defn.model_name %> createDefaultInstance() throws IOException {
return create(<%= create_argument_defaults %>);
}
public List<<%= model_defn.model_name %>> find(Map fieldsMap) throws IOException {
return find(null, fieldsMap);
}
public List<<%= model_defn.model_name %>> find(Collection ids, Map fieldsMap) throws IOException {
List<<%= model_defn.model_name %>> foundList = new ArrayList<>();
if (fieldsMap == null || fieldsMap.isEmpty()) {
return foundList;
}
StringBuilder statementString = new StringBuilder();
statementString.append("SELECT * FROM <%= model_defn.table_name %> WHERE (");
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy