Search in sources :

Example 11 with ServerRuntime

use of org.apache.cayenne.configuration.server.ServerRuntime in project cayenne by apache.

the class Main method main.

public static void main(String[] args) {
    // starting Cayenne
    ServerRuntime cayenneRuntime = ServerRuntime.builder().addConfig("cayenne-project.xml").build();
    // getting a hold of ObjectContext
    ObjectContext context = cayenneRuntime.newContext();
    newObjectsTutorial(context);
    selectTutorial(context);
    deleteTutorial(context);
}
Also used : ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) ObjectContext(org.apache.cayenne.ObjectContext)

Example 12 with ServerRuntime

use of org.apache.cayenne.configuration.server.ServerRuntime in project CRMWebApp by jshioya0506.

the class CustomersFacade method doSearch.

/**
 * 顧客情報の絞り込み検索結果をモデルに設定
 * @param model
 * @param staffCode
 * @param companyCode
 * @return
 */
public boolean doSearch(Model model, String staffCode, String companyCode) {
    // DBの設定情報を取得
    ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-NexusCRM.xml");
    ObjectContext context = cayenneRuntime.getContext();
    // 顧客情報Beanのインスタンスを生成
    CustomerListBean bean = new CustomerListBean();
    // ************************************
    // 1.職員テーブルの検索条件を設定
    // ************************************
    // 検索条件1:失効日=0
    // ************************************
    // 2.職員テーブルを検索
    // ************************************
    // 検索結果を担当者のコンボボックスに設定
    // ************************************
    // 3.顧客管理テーブルの検索条件を設定
    // ************************************
    // 検索条件1:失効日=0
    // ************************************
    // 4.顧客管理テーブルを検索
    // ************************************
    // 検索結果を社名のコンボボックスに設定
    // ************************************
    // 5.顧客管理テーブルの検索条件を設定
    // ************************************
    // 検索条件1:失効日=0
    // 検索条件2:職員コード=%入力値% ※入力値が"*"だったら条件として指定しない
    // 検索条件3:顧客コード=%入力値% ※入力値が"*"だったら条件として指定しない
    // ************************************
    // 6.顧客管理テーブルを検索
    // ************************************
    // 検索結果を顧客情報のモデルに設定
    // 顧客の一覧情報をモデルへ設定
    model.addAttribute("bean", bean);
    return true;
}
Also used : ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) CustomerListBean(jp.co.nexus.crm.bean.CustomerListBean) ObjectContext(org.apache.cayenne.ObjectContext)

Example 13 with ServerRuntime

use of org.apache.cayenne.configuration.server.ServerRuntime in project CRMWebApp by jshioya0506.

the class CustomersFacade method doAction.

/**
 * 顧客の一覧情報を取得してモデルに設定
 * @param model SpringFrameworkのモデルクラス
 * @return 正常に処理できた場合はtrue
 */
public boolean doAction(Model model) {
    // DBの設定情報を取得
    ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-NexusCRM.xml");
    ObjectContext context = cayenneRuntime.getContext();
    // 顧客情報Beanのインスタンスを生成
    CustomerListBean bean = new CustomerListBean();
    // ************************************
    // 1.職員テーブルの検索条件を設定
    // ************************************
    // 検索条件1:失効日=0
    SelectQuery empQuery = new SelectQuery(Employee.class);
    Expression empExpr = ExpressionFactory.matchExp(Employee.LOST_YMD_PROPERTY, Integer.valueOf(0));
    empQuery.setQualifier(empExpr);
    // ************************************
    // 2.職員テーブルを検索
    // ************************************
    // 検索結果を担当者のコンボボックスに設定
    List<Employee> employees = (List<Employee>) context.performQuery(empQuery);
    for (Employee employee : employees) {
        // 社員番号=社員名
        bean.getEmployees().put(String.valueOf(employee.getEmpNo()), employee.getName());
    }
    // ************************************
    // 3.顧客管理テーブルの検索条件を設定
    // ************************************
    // 検索条件1:失効日=0
    SelectQuery customerQuery = new SelectQuery(NCCustomer.class);
    Expression exprExpireDate = ExpressionFactory.matchExp(NCCustomer.LOST_YMD_PROPERTY, Integer.valueOf(0));
    customerQuery.setQualifier(exprExpireDate);
    // ************************************
    // 4.顧客管理テーブルを検索
    // ************************************
    List<NCCustomer> customers = (List<NCCustomer>) context.performQuery(customerQuery);
    // 検索結果を社名のコンボボックスに設定
    if (customers != null && !customers.isEmpty()) {
        for (NCCustomer customer : customers) {
            // 顧客コード
            Integer customerCode = getCustomerCode(customer);
            // 会社名
            String companyName = customer.getName();
            // 検索結果を社名のコンボボックスに設定
            bean.getCompanies().put(String.valueOf(customerCode), companyName);
        }
    }
    // 検索結果を顧客情報のモデルに設定
    for (NCCustomer customer : customers) {
        CustomerInfoBean infoBean = new CustomerInfoBean();
        // エリア情報
        Area area = customer.getArea();
        // 営業担当情報
        Employee employee = customer.getEmployee();
        // 顧客コード
        Integer customerCode = getCustomerCode(customer);
        //  担当者情報から顧客情報を作成して、一覧情報として追加する
        List<NCPerson> persons = getPersons(context, customerCode);
        for (NCPerson person : persons) {
            // 顧客番号[エリアコード+顧客コード]
            String customerNo = DataFormatUtil.formatCustomerNumber(area.getAreaCd(), customerCode);
            infoBean.setCustomerNo(customerNo);
            // 担当営業
            infoBean.setStaffName(employee.getName());
            // ランク
            String rank = getRank(customer);
            infoBean.setRank(rank);
            // 社名
            infoBean.setCompanyName(customer.getName());
            // 住所
            infoBean.setPostAddress(customer.getAddress());
            // 担当者
            infoBean.setPersonnelName(person.getName());
            // 部署名
            NCDivision division = getDivision(context, customerCode, person.getDivisioncd());
            infoBean.setDepartmentName(division.getName());
            // TODO 役職(テーブルのカラムがないので表示保留)
            infoBean.setPositionName("");
            // 前回訪問日
            NCCalldoc calldoc = getLastVisitInfo(context, customerCode, person.getDivisioncd());
            String lastVisitDate = DataFormatUtil.formatDate(String.valueOf(calldoc.getCallYmd()));
            infoBean.setLastVisitDate(lastVisitDate);
            // 
            // TODO 関係性(テーブルのカラムがないので表示保留)
            infoBean.setRelationship("");
            // 顧客の一覧情報として追加
            bean.getCustomers().add(infoBean);
        }
    }
    // 顧客の一覧情報をモデルへ設定
    model.addAttribute("bean", bean);
    return !customers.isEmpty();
}
Also used : CustomerInfoBean(jp.co.nexus.crm.bean.CustomerInfoBean) NCDivision(jp.co.nexus.crm.db.NCDivision) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) NCPerson(jp.co.nexus.crm.db.NCPerson) SelectQuery(org.apache.cayenne.query.SelectQuery) NCCalldoc(jp.co.nexus.crm.db.NCCalldoc) Area(jp.co.nexus.crm.db.Area) Employee(jp.co.nexus.crm.db.Employee) Expression(org.apache.cayenne.exp.Expression) NCCustomer(jp.co.nexus.crm.db.NCCustomer) CustomerListBean(jp.co.nexus.crm.bean.CustomerListBean) List(java.util.List) ObjectContext(org.apache.cayenne.ObjectContext)

Example 14 with ServerRuntime

use of org.apache.cayenne.configuration.server.ServerRuntime in project CRMWebApp by jshioya0506.

the class DBDataSetExecutor method main.

public static void main(String[] args) {
    try {
        // DBの設定情報を取得
        ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-NexusCRM.xml");
        ObjectContext context = cayenneRuntime.getContext();
        // エリアテーブル
        Map<Integer, Area> areaMap = createAreaMap(context);
        // 職員テーブル
        Map<Integer, Employee> employeeMap = createEmployeeMap(context, areaMap);
        // 顧客管理テーブル
        Map<Integer, NCCustomer> customerMap = createCustomerMap(context, areaMap, employeeMap);
        // 担当テーブル
        Map<Integer, NCPerson> personMap = createPersonMap(context, areaMap, employeeMap);
        // 部署テーブル
        Map<Integer, NCDivision> divisionMap = createDivisionMap(context, areaMap, employeeMap);
        // 訪問記録テーブル
        Map<Integer, NCCalldoc> callDocMap = createCallDocMap(context, areaMap, employeeMap);
        // 各テーブルにデータ登録
        context.commitChanges();
    } catch (IOException e) {
        LOGGER.error("エラーが発生しました。[" + e.getMessage() + "]");
        e.printStackTrace();
    }
}
Also used : NCDivision(jp.co.nexus.crm.db.NCDivision) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) IOException(java.io.IOException) NCPerson(jp.co.nexus.crm.db.NCPerson) NCCalldoc(jp.co.nexus.crm.db.NCCalldoc) Area(jp.co.nexus.crm.db.Area) Employee(jp.co.nexus.crm.db.Employee) NCCustomer(jp.co.nexus.crm.db.NCCustomer) ObjectContext(org.apache.cayenne.ObjectContext)

Example 15 with ServerRuntime

use of org.apache.cayenne.configuration.server.ServerRuntime in project tutorials by eugenp.

the class CayenneOperationTests method setupTheCayenneContext.

@BeforeClass
public static void setupTheCayenneContext() {
    ServerRuntime cayenneRuntime = ServerRuntime.builder().addConfig("cayenne-project.xml").build();
    context = cayenneRuntime.newContext();
}
Also used : ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) BeforeClass(org.junit.BeforeClass)

Aggregations

ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)15 ObjectContext (org.apache.cayenne.ObjectContext)6 Employee (jp.co.nexus.crm.db.Employee)3 Module (org.apache.cayenne.di.Module)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 CustomerListBean (jp.co.nexus.crm.bean.CustomerListBean)2 Area (jp.co.nexus.crm.db.Area)2 NCCalldoc (jp.co.nexus.crm.db.NCCalldoc)2 NCCustomer (jp.co.nexus.crm.db.NCCustomer)2 NCDivision (jp.co.nexus.crm.db.NCDivision)2 NCPerson (jp.co.nexus.crm.db.NCPerson)2 ROPServerModule (org.apache.cayenne.configuration.rop.server.ROPServerModule)2 WebConfiguration (org.apache.cayenne.configuration.web.WebConfiguration)2 Expression (org.apache.cayenne.exp.Expression)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 RemoteService (org.apache.cayenne.remote.RemoteService)2