protectedfinalvoidparseWhere(final ShardingRule shardingRule, final SelectStatement selectStatement, final List<SelectItem> items){ selectClauseParserFacade.getWhereClauseParser().parse(shardingRule, selectStatement, items); }
publicvoidparse(final ShardingRule shardingRule, final SQLStatement sqlStatement, final List<SelectItem> items){ //AliasClauseParser 别名解析器,分析过了 aliasClauseParser.parse(); //Where if (lexerEngine.skipIfEqual(DefaultKeyword.WHERE)) { parseConditions(shardingRule, sqlStatement, items); } }
1 2 3 4 5 6 7
privatevoidparseConditions(final ShardingRule shardingRule, final SQLStatement sqlStatement, final List<SelectItem> items){ do { parseComparisonCondition(shardingRule, sqlStatement, items); } while (lexerEngine.skipIfEqual(DefaultKeyword.AND)); //不支持OR,3.X支持了。。。我这里源码是2.x的所以没有 lexerEngine.unsupportedIfEqual(DefaultKeyword.OR); }
@Override // TODO insert SQL need parse gen key public SQLRouteResult route(final String logicSQL, final List<Object> parameters, final SQLStatement sqlStatement){ //SQL路由结果 SQLRouteResult result = new SQLRouteResult(sqlStatement); //路由 RoutingResult routingResult = new DatabaseHintRoutingEngine(shardingRule.getDataSourceMap(), (HintShardingStrategy) shardingRule.getDefaultDatabaseShardingStrategy()).route(); for (TableUnit each : routingResult.getTableUnits().getTableUnits()) { result.getExecutionUnits().add(new SQLExecutionUnit(each.getDataSourceName(), logicSQL)); } //打印sql if (showSQL) { SQLLogger.logSQL(logicSQL, sqlStatement, result.getExecutionUnits(), parameters); } return result; }
@Getter publicclassMasterSlaveDataSourceextendsAbstractDataSourceAdapter{ //数据源映射 private Map<String, DataSource> dataSourceMap; private MasterSlaveRule masterSlaveRule; publicMasterSlaveDataSource(final Map<String, DataSource> dataSourceMap, final MasterSlaveRuleConfiguration masterSlaveRuleConfig, final Map<String, Object> configMap)throws SQLException { super(getAllDataSources(dataSourceMap, masterSlaveRuleConfig.getMasterDataSourceName(), masterSlaveRuleConfig.getSlaveDataSourceNames())); this.dataSourceMap = dataSourceMap; this.masterSlaveRule = new MasterSlaveRule(masterSlaveRuleConfig); if (!configMap.isEmpty()) { ConfigMapContext.getInstance().getMasterSlaveConfig().putAll(configMap); } } privatestatic Collection<DataSource> getAllDataSources(final Map<String, DataSource> dataSourceMap, final String masterDataSourceName, final Collection<String> slaveDataSourceNames){ Collection<DataSource> result = new LinkedList<>(); result.add(dataSourceMap.get(masterDataSourceName)); for (String each : slaveDataSourceNames) { result.add(dataSourceMap.get(each)); } return result; } /** * Get map of all actual data source name and all actual data sources. * * @return map of all actual data source name and all actual data sources */ public Map<String, DataSource> getAllDataSources(){ Map<String, DataSource> result = new HashMap<>(masterSlaveRule.getSlaveDataSourceNames().size() + 1, 1); result.put(masterSlaveRule.getMasterDataSourceName(), dataSourceMap.get(masterSlaveRule.getMasterDataSourceName())); for (String each : masterSlaveRule.getSlaveDataSourceNames()) { result.put(each, dataSourceMap.get(each)); } return result; } /** * Renew master-slave data source. * * @param dataSourceMap data source map * @param masterSlaveRuleConfig new master-slave rule configuration */ publicvoidrenew(final Map<String, DataSource> dataSourceMap, final MasterSlaveRuleConfiguration masterSlaveRuleConfig){ this.dataSourceMap = dataSourceMap; this.masterSlaveRule = new MasterSlaveRule(masterSlaveRuleConfig); } @Override public MasterSlaveConnection getConnection(){ returnnew MasterSlaveConnection(this); } }
/** * The constant indicating that the current <code>ResultSet</code> object * should be closed when calling <code>getMoreResults</code>. * * @since 1.4 */ int CLOSE_CURRENT_RESULT = 1;
/** * The constant indicating that the current <code>ResultSet</code> object * should not be closed when calling <code>getMoreResults</code>. * * @since 1.4 */ int KEEP_CURRENT_RESULT = 2;
/** * The constant indicating that all <code>ResultSet</code> objects that * have previously been kept open should be closed when calling * <code>getMoreResults</code>. * * @since 1.4 */ int CLOSE_ALL_RESULTS = 3;
/** * The constant indicating that a batch statement executed successfully * but that no count of the number of rows it affected is available. * * @since 1.4 */ int SUCCESS_NO_INFO = -2;
/** * The constant indicating that an error occurred while executing a * batch statement. * * @since 1.4 */ int EXECUTE_FAILED = -3;
/** * The constant indicating that generated keys should be made * available for retrieval. * * @since 1.4 */ int RETURN_GENERATED_KEYS = 1;
/** * The constant indicating that generated keys should not be made * available for retrieval. * * @since 1.4 */ int NO_GENERATED_KEYS = 2;
publicclassDubboNamespaceHandlerextendsNamespaceHandlerSupport{ publicvoidinit(){ registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true)); registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true)); registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true)); registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true)); registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true)); registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true)); registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true)); registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true)); registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false)); registerBeanDefinitionParser("annotation", new AnnotationBeanDefinitionParser()); }
/** * This method is called when the owning appender starts or whenever output * needs to be directed to a new OutputStream, for instance as a result of a * rollover. */ voidinit(OutputStream os)throws IOException;
/** * Encode and write an event to the appropriate {@link OutputStream}. * Implementations are free to defer writing out of the encoded event and * instead write in batches. */ voiddoEncode(E event)throws IOException;
/** * This method is called prior to the closing of the underling * {@link OutputStream}. Implementations MUST not close the underlying * {@link OutputStream} which is the responsibility of the owning appender. */ voidclose()throws IOException; }
// BasicConfigurator replaced with PropertyConfigurator. PropertyConfigurator.configure(args[0]);
logger.info("Entering application."); Bar bar = new Bar(); bar.doIt(); logger.info("Exiting application."); } }
屏蔽日志
1 2 3 4 5 6 7 8 9
log4j.rootLogger=DEBUG, A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout # Print the date in ISO 8601 format log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n # Print only messages of level WARN or above in the package com.foo. log4j.logger.com.foo=WARN
2000-09-07 14:07:41,508 [main] INFO MyApp - Entering application. 2000-09-07 14:07:41,529 [main] INFO MyApp - Exiting application.
多个appender
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n