// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java
// public class Customer extends CustomerAbstract
// {
//     public Customer(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public Customer(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java
// public class CustomerAccount extends CustomerAccountAbstract
// {
//     public CustomerAccount(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public CustomerAccount(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java
// public class DateUtils
// {
//     private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd");
// 
//     private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS");
// 
//     public static Timestamp parseFull(String dateTimeString)
//     {
//         DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString);
//         return new Timestamp(dateTime.toDateTime().getMillis());
//     }
// 
//     public static String printFull(Timestamp ts)
//     {
//         return DATE_TIME_FORMATTER_FULL.print(ts.getTime());
//     }
// 
//     public static Timestamp parse(String dateTimeString)
//     {
//         DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString);
//         return new Timestamp(dateTime.toDateTime().getMillis());
//     }
// 
//     public static String print(Timestamp ts)
//     {
//         return DATE_TIME_FORMATTER.print(ts.getTime());
//     }
// }


import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Timestamp;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import bitemporalbank.domain.Customer;
import bitemporalbank.domain.CustomerAccount;
import bitemporalbank.domain.CustomerAccountFinder;
import bitemporalbank.domain.CustomerFinder;
import bitemporalbank.util.DateUtils;
import com.gs.fw.common.mithra.MithraManagerProvider;
import com.gs.fw.common.mithra.MithraTransaction;
import com.gs.fw.common.mithra.finder.Operation;
import com.gs.fw.common.mithra.test.ConnectionManagerForTests;
import com.gs.fw.common.mithra.test.MithraTestResource;
import com.gs.fw.common.mithra.util.dbextractor.DbExtractor;
import org.junit.Before;
import org.junit.Test;
/*
Copyright 2016 Goldman Sachs.
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.
*/

package bitemporalbank.api;




public class BitemporalChainingInAction
{
    private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml";

    @Before
    public void setup() throws Exception
    {
        intializeReladomoForTest();
    }

    private void intializeReladomoForTest()
    {
        MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML);
        ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db");
        testResource.createSingleDatabase(connectionManager);
        testResource.setUp();
    }

    @Test
    public void run() throws Exception
    {
        int accountId = 12345;

        createAccount("2017-01-01", accountId);

        fetchAccountWithBusinessDate("2017-01-01", accountId);

        updateBalance("2017-01-20", accountId, 200);

        dumpCustomerAccount(accountId);

        updateBalance("2017-01-17", "2017-01-25", accountId, 50);

        dumpCustomerAccount(accountId);

        balanceAsOfJan12_OnJan23(accountId);

        dumpCustomer(1);
    }

// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java
// public class Customer extends CustomerAbstract
// {
//     public Customer(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public Customer(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java
// public class CustomerAccount extends CustomerAccountAbstract
// {
//     public CustomerAccount(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public CustomerAccount(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java
// public class DateUtils
// {
//     private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd");
// 
//     private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS");
// 
//     public static Timestamp parseFull(String dateTimeString)
//     {
//         DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString);
//         return new Timestamp(dateTime.toDateTime().getMillis());
//     }
// 
//     public static String printFull(Timestamp ts)
//     {
//         return DATE_TIME_FORMATTER_FULL.print(ts.getTime());
//     }
// 
//     public static Timestamp parse(String dateTimeString)
//     {
//         DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString);
//         return new Timestamp(dateTime.toDateTime().getMillis());
//     }
// 
//     public static String print(Timestamp ts)
//     {
//         return DATE_TIME_FORMATTER.print(ts.getTime());
//     }
// }


// Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalChainingInAction.java
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Timestamp;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import bitemporalbank.domain.Customer;
import bitemporalbank.domain.CustomerAccount;
import bitemporalbank.domain.CustomerAccountFinder;
import bitemporalbank.domain.CustomerFinder;
import bitemporalbank.util.DateUtils;
import com.gs.fw.common.mithra.MithraManagerProvider;
import com.gs.fw.common.mithra.MithraTransaction;
import com.gs.fw.common.mithra.finder.Operation;
import com.gs.fw.common.mithra.test.ConnectionManagerForTests;
import com.gs.fw.common.mithra.test.MithraTestResource;
import com.gs.fw.common.mithra.util.dbextractor.DbExtractor;
import org.junit.Before;
import org.junit.Test;

/*
Copyright 2016 Goldman Sachs.
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.
*/

package bitemporalbank.api;




public class BitemporalChainingInAction
{
    private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml";

    @Before
    public void setup() throws Exception
    {
        intializeReladomoForTest();
    }

    private void intializeReladomoForTest()
    {
        MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML);
        ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db");
        testResource.createSingleDatabase(connectionManager);
        testResource.setUp();
    }

    @Test
    public void run() throws Exception
    {
        int accountId = 12345;

        createAccount("2017-01-01", accountId);

        fetchAccountWithBusinessDate("2017-01-01", accountId);

        updateBalance("2017-01-20", accountId, 200);

        dumpCustomerAccount(accountId);

        updateBalance("2017-01-17", "2017-01-25", accountId, 50);

        dumpCustomerAccount(accountId);

        balanceAsOfJan12_OnJan23(accountId);

        dumpCustomer(1);
    }

    private void createAccount(String date, int accountId)