Skip to content

Commit

Permalink
add sample
Browse files Browse the repository at this point in the history
  • Loading branch information
fulan.zjf committed Mar 7, 2019
1 parent 138c0d1 commit 40dbe44
Show file tree
Hide file tree
Showing 177 changed files with 5,675 additions and 49 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<version>${version}</version>
<name>${artifactId}</name>
<dependencies>
<!-- SOFA Framework -->
<!-- COLA Framework -->
<dependency>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-core</artifactId>
Expand All @@ -20,11 +20,15 @@
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-test</artifactId>
</dependency>
<!-- SOFA Framework End-->
<!-- COLA Framework End-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- https://github.com/spring-projects/spring-boot/blob/v1.4.2.RELEASE/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml -->
<include resource="org/springframework/boot/logging/logback/defaults.xml" />

<property name="APP_NAME" value="${artifactId}" />
<property name="APP_NAME" value="${rootArtifactId}" />
<property name="LOG_PATH" value="${symbol_dollar}{user.home}/${symbol_dollar}{APP_NAME}/logs" />
<property name="LOG_FILE" value="${symbol_dollar}{LOG_PATH}/application.log" />

Expand Down Expand Up @@ -35,4 +35,4 @@
<appender-ref ref="CONSOLE" />
<appender-ref ref="APPLICATION" />
</root>
</configuration>
</configuration>
9 changes: 7 additions & 2 deletions cola-archetype/src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<version>${project.version}</version>
</dependency>
<!--Project modules End-->
<!--Pandora Boot-->
<!--Spring Boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
Expand All @@ -89,7 +89,7 @@
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-starter.version}</version>
</dependency>
<!--Pandora Boot End-->
<!--Spring Boot End-->
<!-- Spring Framework -->
<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -209,6 +209,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.55</version>
</dependency>
<!-- Misc End -->
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-test</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#set( $symbol_escape = '\' )
package ${package};

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

/**
* Spring Boot Starter
Expand All @@ -14,7 +14,8 @@
*
* @author Frank Zhang
*/
@SpringBootApplication(scanBasePackages = {"${package}"})
@SpringBootApplication(scanBasePackages = {"${package}","com.alibaba.cola"})
@MapperScan("${package}.tunnel.database")
public class Application {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- https://github.com/spring-projects/spring-boot/blob/v1.4.2.RELEASE/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml -->
<include resource="org/springframework/boot/logging/logback/defaults.xml" />

<property name="APP_NAME" value="${rootArtifactId}" />
<property name="LOG_PATH" value="${symbol_dollar}{user.home}/${symbol_dollar}{APP_NAME}/logs" />
<property name="LOG_FILE" value="${symbol_dollar}{LOG_PATH}/application.log" />

<appender name="APPLICATION"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${symbol_dollar}{LOG_FILE}</file>
<encoder>
<pattern>${symbol_dollar}{FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${symbol_dollar}{LOG_FILE}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>7</maxHistory>
<maxFileSize>50MB</maxFileSize>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
</appender>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${symbol_dollar}{CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="APPLICATION" />
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
import org.springframework.context.annotation.Configuration;

/**
* TestConfig, {@link com.alibaba.demo.config.ColaConfig}
* TestConfig, {@link ${package}.config.ColaConfig}
*
* @author Frank Zhang
* @date 2018-08-08 12:33 PM
*/
@Configuration
@ComponentScan(basePackages = {"com.alibaba.cola", "${package}"})
public class TestConfig {
Logger logger = LoggerFactory.getLogger(TestConfig.class);

public TestConfig() {
LoggerFactory.activateSysLogger();
Logger logger = LoggerFactory.getLogger(TestConfig.class);
logger.debug("Spring container is booting");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @author Frank Zhang
* @date 2019-01-02 10:14 AM
*/

public class Context<T> {

/**
Expand Down Expand Up @@ -45,4 +46,12 @@ public T getContent() {
public void setContent(T content) {
this.content = content;
}

@Override
public String toString() {
return "Context{" +
"bizCode='" + bizCode + '\'' +
", content=" + content +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
public class CommandRegister implements RegisterI {

@Autowired

private CommandHub commandHub;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ public class CommandBus implements CommandBusI{

@Override
public Response send(Command cmd) {
return commandHub.getCommandInvocation(cmd.getClass()).invoke(cmd);
return commandHub.getCommandInvocation(cmd.getClass()).invoke(cmd);
}

@Override
public Response send(Command cmd, Class<? extends CommandExecutorI> executorClz){
CommandInvocation commandInvocation = commandHub.getCommandInvocation(cmd.getClass());
if(!isEquals(executorClz, commandInvocation)){
throw new IllegalArgumentException(executorClz + " is not the same with "+commandInvocation.getCommandExecutor().getClass());
}
return send(cmd);
}

private boolean isEquals(Class<? extends CommandExecutorI> executorClz, CommandInvocation commandInvocation) {
return executorClz.equals(commandInvocation.getCommandExecutor().getClass());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ public interface CommandBusI {
/**
* Send command to CommandBus, then the command will be executed by CommandExecutor
*
* @param Command or Query
* @param cmd or qry
* @return Response
*/
public Response send(Command cmd);

/**
* Assign executor explicitly for easier maintenance.
*
* @param cmd command or query
* @param executorClz the command executor class
* @return Response
*/
public Response send(Command cmd, Class<? extends CommandExecutorI> executorClz);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
*
* @author fulan.zjf 2017年10月25日 下午4:04:43
*/
public interface CommandInterceptorI {
public interface CommandInterceptorI<T extends com.alibaba.cola.dto.Command> {

/**
* Pre-processing before command execution
* @param command
*/
default public void preIntercept(Command command){};
default public void preIntercept(T command){};

/**
* Post-processing after command execution
* @param command
* @param response, Note that response could be null, check it before use
*/
default public void postIntercept(Command command, Response response){};
default public void postIntercept(T command, Response response){};

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.alibaba.cola.logger.Logger;
import com.alibaba.cola.logger.LoggerFactory;
import com.google.common.collect.FluentIterable;
import lombok.Data;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
Expand All @@ -17,15 +18,13 @@

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Data
public class CommandInvocation{

private static Logger logger = LoggerFactory.getLogger(CommandInvocation.class);

@Setter
private CommandExecutorI commandExecutor;
@Setter
private Iterable<CommandInterceptorI> preInterceptors;
@Setter
private Iterable<CommandInterceptorI> postInterceptors;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@
*
* @author fulan.zjf on 2017/12/16.
*/
public interface ConvertorI<C, E, D> {

//Convert entity object to client object
default public C entityToClient(E entityObject){return null;}

//Convert entity object to data object
default public D entityToData(E entityObject){return null;}

//Convert data object to client object
default public C dataToClient(D dataObject){return null;}

//Convert data object to entity object
default public E dataToEntity(D dataObject){return null;}

//Convert client object to entity object
default public E clientToEntity(C clientObject){return null;}
public interface ConvertorI {
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class DomainFactory {

public static <T extends EntityObject> T create(Class<T> entityClz){
public static <T> T create(Class<T> entityClz){
return ApplicationContextHelper.getBean(entityClz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public static void isTrue(boolean expression) {

public static void notNull(Object object, ErrorCodeI errorCode, String message) {
if (object == null) {
throw new BizException(errorCode, message);
throw new SysException(errorCode, message);
}
}

public static void notNull(Object object, String message) {
notNull(object, BasicErrorCode.B_COMMON_ERROR, message);
notNull(object, BasicErrorCode.S_NPE, message);
}

public static void notNull(Object object){
notNull(object, BasicErrorCode.B_COMMON_ERROR, "[Assertion failed] - the argument "+object+" must not be null");
notNull(object, BasicErrorCode.S_NPE, "[Assertion failed] - the argument "+object+" must not be null");
}

public static void notEmpty(Collection<?> collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum BasicErrorCode implements ErrorCodeI{
* You can extend it by implementing ErrorCodeI in your Application
*/
S_COLA_ERROR("S_COLA_ERROR" , "COLA框架错误"),
S_NPE("S_NPE", "空指针错误"),
S_DB_ERROR("S_DB_ERROR", "数据库错误"),
S_RPC_ERROR("S_RPC_ERROR", "远程方法调用错误"),
S_UNKNOWN("S_UNKNOWN" , "未知的系统错误" );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.alibaba.cola.validator;

import org.apache.commons.lang3.ClassUtils;

import java.lang.reflect.Field;

/**
* AbstractValidationInterceptor
*
* @author Frank Zhang
* @date 2019-03-02 4:44 PM
*/
public abstract class AbstractValidationInterceptor {

/**
* Recursively do validation to the target if the field is not primitive or wrapped.
*
* @param target
*/
protected void validate(Object target){
doValidation(target);
Field[] fields = target.getClass().getDeclaredFields();
for (Field field : fields){
if(isChildField(field.getType())){
continue;
}
Object fieldValue = null;
try {
field.setAccessible(true);
fieldValue = field.get(target);
} catch (IllegalAccessException e) {
continue;
}

//Recursively validate
validate(fieldValue);
}
}

private boolean isChildField(Class type){
return type.equals(String.class) || ClassUtils.isPrimitiveOrWrapper(type);
}

abstract protected void doValidation(Object target);
}
Loading

0 comments on commit 40dbe44

Please sign in to comment.