All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rb.templates.databases_impl.erb Maven / Gradle / Ivy

There is a newer version: 1.8
Show newest version
<%#
# 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 <%= project_defn.databases_namespace %>;

import <%= JACK_NAMESPACE %>.*;
<% project_defn.databases.each do |db| %>
import <%= db.namespace %>.I<%= db.name %>;
import <%= db.namespace %>.impl.<%= db.name %>Impl;
<% end %>
import <%= JACK_NAMESPACE %>.tracking.PostQueryAction;
import <%= JACK_NAMESPACE %>.tracking.NoOpAction;
import <%= JACK_NAMESPACE %>.transaction.TransactorImpl;

public class DatabasesImpl implements IDatabases {

  <% project_defn.databases.each do |db| %>
  private I<%= db.name %> <%= db.name.underscore %>;
  <% end %>

  private final PostQueryAction postQueryAction;

  public DatabasesImpl() {
    this(new NoOpAction());
  }

  public DatabasesImpl(PostQueryAction postQueryAction) {
    this.postQueryAction = postQueryAction;
  }

  public DatabasesImpl(<%= project_defn.databases.map{|db| ["BaseDatabaseConnection", db.connection_name].join(" ")}.join(", ") %>) {
    this(new NoOpAction(), <%= project_defn.databases.map{|db| db.connection_name}.join(", ") %>);
  }

  public DatabasesImpl(PostQueryAction postQueryAction, <%= project_defn.databases.map{|db| ["BaseDatabaseConnection", db.connection_name].join(" ")}.join(", ") %>) {
    <% project_defn.databases.each do |db| %>
    this.<%= db.name.underscore %> = new <%= db.name %>Impl(<%= db.connection_name %>, this, postQueryAction);
    <% end %>
    this.postQueryAction = postQueryAction;
  }

  <% project_defn.databases.each do |db| %>

  @Override
  public I<%= db.name %> <%= db.getter %> {
    if (<%= db.name.underscore %> == null) {
      this.<%= db.name.underscore %> = new <%= db.name %>Impl(new <%= db.adapter.capitalize %>DatabaseConnection("<%= db.name.underscore %>"), this, this.postQueryAction);
    }
    return <%= db.name.underscore %>;
  }

  @Override
  public TransactorImpl.Builder> get<%= db.name %>Transactor() {
    return TransactorImpl.create(() -> new DatabasesImpl().get<%= db.name %>());
  }
  <% end %>
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy