Skip to content

Commit

Permalink
change sofa to cola
Browse files Browse the repository at this point in the history
  • Loading branch information
fulan.zjf committed Jan 4, 2019
1 parent 6a00153 commit 07e34ad
Show file tree
Hide file tree
Showing 301 changed files with 2,748 additions and 2,861 deletions.
105 changes: 12 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# SOFA
> SOFA是Simple Object-Oriented and Flexible Architecture的缩写,是轻量级的企业应用框架,可以有效的降低业务系统复杂度。
# COLA
> COLA是Clean Object-oriented & Layered Architecture的缩写,是轻量级的企业应用框架,可以有效的降低业务系统复杂度。
![image.png](http://ata2-img.cn-hangzhou.img-pub.aliyun-inc.com/26321403c9123efc269cb6013c55555f.png)

关于架构和设计的详细内容,请查看:https://www.atatech.org/articles/96063

# 项目说明
SOFA框架包括两个Project,一个是sofa-framework里面是框架的核心代码,另一个是sofa-archetype是用来生成新应用的Maven Archetype源码。
## sofa-framework Project
该Project包含3个Module,sofa-core, sofa-common, sofa-test
### sofa-core
COLA框架包括两个Project,一个是cola-framework里面是框架的核心代码,另一个是cola-archetype是用来生成新应用的Maven Archetype源码。
## cola-framework Project
该Project包含3个Module,cola-core, cola-common, cola-test
### cola-core
该Module是整个框架的核心,里面的主要功能和Package如下:
```
com
└── alibaba
└── sofa
└── cola
├── assembler \\提供Assembler标准
├── boot \\这是框架的核心启动包,负责框架组件的注册、发现
├── command \\提供Command标准
Expand All @@ -31,95 +31,14 @@ com
│   └── ruleengine
└── validator \\提供Validator标准和执行
```
### sofa-common
### cola-common
该Module提供了框架中Client Object, Entity Object和Data Object的定义,二方库会依赖该Module。
### sofa-test
### cola-test
该Module主要是提供一些开发测试的工具,可以使用TDD来进行开发。

## sofa-archetype Project
## cola-archetype Project
该Project下面是Archetype的源码,先执行`mvn install`,然后就可以用下面的命令来创建新应用了:
```
mvn archetype:generate -DgroupId=com.alibaba.crm -DartifactId=demo -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.crm.demo -DarchetypeArtifactId=sofa-framework-archetype -DarchetypeGroupId=com.alibaba.sofa -DarchetypeVersion=1.0.0-SNAPSHOT
```
生成的应用主要包括demo-app, demo-domain, demo-tunnel, demo-config, demo-client和Start五个Module,分别代表不同层次(Tier)和用途。
```
├── demo-app \\这个是Application层
│   └── src
│   └── main
│   └── java
│   └── com
│   └── alibaba
│   └── crm
│   └── demo
│   ├── assembler
│   ├── command
│   │   ├── extension
│   │   ├── extensionpoint
│   │   └── query
│   ├── event
│   │   └── handler
│   ├── interceptor
│   ├── service
│   └── validator
│   ├── extension
│   └── extensionpoint
├── demo-client \\这个是二方库,提供给Consumer做RPC调用用的
│   └── src
│   └── main
│   └── java
│   └── com
│   └── alibaba
│   └── crm
│   └── demo
│   ├── api
│   └── dto
│   └── clientobject
├── demo-config \\这个是应用的配置
│   └── src
│   └── main
│   └── java
│   └── com
│   └── alibaba
│   └── crm
│   └── demo
│   └── config
├── demo-domain \\这个是Domain层,所有的业务逻辑都应该在这个Module里面
│   └── src
│   └── main
│   └── java
│   └── com
│   └── alibaba
│   └── crm
│   └── demo
│   └── domain
│   └── customer
│   ├── convertor
│   │   ├── extension
│   │   └── extensionpoint
│   ├── entity
│   ├── factory
│   ├── repository
│   ├── rule
│   │   ├── extension
│   │   └── extensionpoint
│   └── valueobject
├── demo-tunnel \\这个是Tunnel层,也就是仓储层,所有和DB或者其它通道的数据交互都在这一层处理
│   └── src
│   └── main
│   └── java
│   └── com
│   └── alibaba
│   └── crm
│   └── demo
│   ├── dataobject
│   └── datatunnel
│   └── impl
└── start \\这个是应用的启动Module,通常是用SpringBoot,如果是阿里系的话,通常是PandoraBoot
└── src
└── main
└── java
└── com
└── alibaba
└── crm
└── demo
mvn archetype:generate -DgroupId=com.alibaba.demo -DartifactId=sample -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.demo -DarchetypeArtifactId=cola-framework-archetype -DarchetypeGroupId=com.alibaba.cola -DarchetypeVersion=1.0.0-SNAPSHOT
```
生成的应用主要包括demo-app, demo-domain, demo-tunnel, demo-config, demo-client和Start五个Module,分别代表不同层次(layer)和用途。
File renamed without changes.
8 changes: 4 additions & 4 deletions sofa-archetype/pom.xml → cola-archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.alibaba.sofa</groupId>
<artifactId>sofa-framework-archetype</artifactId>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-framework-archetype</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>sofa framework archetype</name>
<description>sofa framework archetype</description>
<name>cola framework archetype</name>
<description>cola framework archetype</description>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>bin</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.project</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>bin/src</directory>
<includes>
<include>**/*.class</include>
</includes>
</fileSet>
</fileSets>
</module>
<module id="${rootArtifactId}-app" dir="__rootArtifactId__-app" name="${rootArtifactId}-app">
Expand All @@ -38,6 +25,7 @@
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
Expand Down Expand Up @@ -94,6 +82,7 @@
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
Expand All @@ -106,6 +95,7 @@
<fileSet filtered="true" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
Expand All @@ -122,6 +112,7 @@
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
Expand All @@ -134,6 +125,7 @@
<fileSet filtered="true" encoding="UTF-8">
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</fileSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}.all</artifactId>
<version>${version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
Expand Down Expand Up @@ -34,8 +35,8 @@
<!-- JSR 303 Validation End-->
<!-- Test -->
<dependency>
<groupId>com.alibaba.sofa</groupId>
<artifactId>sofa-test</artifactId>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-test</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -63,5 +64,5 @@
</plugin>
</plugins>
</pluginManagement>
</build>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@
#set( $symbol_escape = '\' )
package ${package}.command;

import ${package}.domain.customer.convertor.extensionpoint.CustomerConvertorExtPt;
import ${package}.domain.customer.entity.CustomerE;
import com.alibaba.sofa.extension.ExtensionExecutor;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.sofa.command.Command;
import com.alibaba.sofa.command.CommandExecutorI;
import com.alibaba.sofa.dto.Response;
import com.alibaba.cola.extension.ExtensionExecutor;
import com.alibaba.cola.command.Command;
import com.alibaba.cola.command.CommandExecutorI;
import com.alibaba.cola.dto.Response;

import ${package}.dto.CustomerAddCmd;
import ${package}.validator.extensionpoint.CustomerAddValidatorExtPt;
import com.alibaba.sofa.validator.ValidatorExecutor;
import ${package}.convertor.extensionpoint.CustomerConvertorExtPt;
import ${package}.domain.customer.entity.CustomerE;
import org.springframework.beans.factory.annotation.Autowired;


@Command
public class CustomerAddCmdExe implements CommandExecutorI<Response, CustomerAddCmd>{

@Autowired
private ValidatorExecutor validatorExecutor;

@Autowired
private ExtensionExecutor extensionExecutor;

@Override
public Response execute(CustomerAddCmd cmd) {
//1, validation
validatorExecutor.validate(CustomerAddValidatorExtPt.class, cmd);
extensionExecutor.executeVoid(CustomerAddValidatorExtPt.class, cmd.getContext(), validator -> validator.validate(cmd));

//2, invoke domain service or directly operate domain to do business logic process
CustomerE customerEntity = extensionExecutor.execute(CustomerConvertorExtPt.class, extension -> extension.clientToEntity(cmd.getCustomer()));
customerEntity.addNewCustomer();
CustomerE customerE = extensionExecutor.execute(CustomerConvertorExtPt.class, cmd.getContext(), convertor -> convertor.clientToEntity(cmd.getCustomerCO(), cmd.getContext()));
customerE.addNewCustomer();

//3, notify by sending message out
//3, response
return Response.buildSuccess();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#set( $symbol_escape = '\' )
package ${package}.command.query;

import ${package}.domain.customer.convertor.CustomerConvertor;
import ${package}.tunnel.dataobject.CustomerDO;
import ${package}.tunnel.datatunnel.CustomerTunnelI;
import ${package}.convertor.CustomerConvertor;
import ${package}.tunnel.database.dataobject.CustomerDO;
import ${package}.tunnel.database.CustomerDBTunnel;
import ${package}.dto.CustomerFindByCriteriaQry;
import ${package}.dto.clientobject.CustomerCO;
import com.alibaba.sofa.command.Command;
import com.alibaba.sofa.command.QueryExecutorI;
import com.alibaba.sofa.dto.MultiResponse;
import com.alibaba.cola.command.Command;
import com.alibaba.cola.command.QueryExecutorI;
import com.alibaba.cola.dto.MultiResponse;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
Expand All @@ -20,10 +20,10 @@
public class CustomerFindByCriteriaQueryExe implements QueryExecutorI<MultiResponse<CustomerCO>, CustomerFindByCriteriaQry> {

@Autowired
CustomerTunnelI customerDBTunnel;
private CustomerDBTunnel customerDBTunnel;

@Autowired
CustomerConvertor customerConvertor;
private CustomerConvertor customerConvertor;

@Override
public MultiResponse<CustomerCO> execute(CustomerFindByCriteriaQry cmd) {
Expand All @@ -32,10 +32,4 @@ public MultiResponse<CustomerCO> execute(CustomerFindByCriteriaQry cmd) {
customerCos.add(customerConvertor.dataToClient(customerDO));
return MultiResponse.of(customerCos, customerCos.size());
}


public CustomerDO get(String id) {
CustomerDO customerDO = customerDBTunnel.get("123");
return customerDO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.convertor;

import com.alibaba.cola.context.Context;
import com.alibaba.cola.domain.DomainFactory;
import com.alibaba.cola.convertor.ConvertorI;
import ${package}.dto.clientobject.CustomerCO;
import ${package}.domain.customer.entity.CustomerE;
import ${package}.tunnel.database.dataobject.CustomerDO;
import org.springframework.stereotype.Component;
/**
* General CustomerConvertor, the difference is implemented by Extension mechanism
*
* @author Frank Zhang
* @date 2018-01-07 3:08 AM
*/
@Component
public class CustomerConvertor implements ConvertorI {

public CustomerE clientToEntity(CustomerCO customerCO, Context context){
CustomerE customerE = DomainFactory.create(CustomerE.class);
customerE.setCompanyName(customerCO.getCompanyName());
customerE.setContext(context);
return customerE;
}

public CustomerCO dataToClient(CustomerDO dataObject) {
CustomerCO customerCO = new CustomerCO();
customerCO.setCustomerName(dataObject.getCompanyName());
customerCO.setCustomerType(dataObject.getCompanyType());
customerCO.setMemberId(dataObject.getMemberId());
customerCO.setCustomerId(dataObject.getCustomerId());
return customerCO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.convertor.extension;

import com.alibaba.cola.context.Context;
import com.alibaba.cola.extension.Extension;
import ${package}.common.BizCode;
import ${package}.convertor.CustomerConvertor;
import ${package}.convertor.extensionpoint.CustomerConvertorExtPt;
import ${package}.domain.customer.entity.CustomerE;
import ${package}.domain.customer.valueobject.SourceType;
import ${package}.dto.clientobject.CustomerCO;
import org.springframework.beans.factory.annotation.Autowired;

@Extension(bizCode = BizCode.BIZ_ONE)
public class CustomerBizOneConvertorExt implements CustomerConvertorExtPt{

@Autowired
private CustomerConvertor customerConvertor;

@Override
public CustomerE clientToEntity(CustomerCO customerCO, Context context) {
CustomerE customerE = customerConvertor.clientToEntity(customerCO, context);
customerE.setSourceType(SourceType.BIZ_ONE);
return customerE;
}
}
Loading

0 comments on commit 07e34ad

Please sign in to comment.