Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
wangtao | 04a3145674 | |
wangtao | 192bff31fe | |
wangtao | 489737bb85 | |
wangtao | 77ce114bec |
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/main/assembly"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,2 @@
|
|||
/target/
|
||||
/log/*
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>hotwords</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -0,0 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
||||
<property name="basePackage" value="com.ossean.hotwords" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
|
||||
destroy-method="close">
|
||||
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
||||
<property name="url"
|
||||
value="jdbc:mysql://192.168.80.130:3306/ossean_production?characterEncoding=UTF-8" />
|
||||
<property name="username" value="trustie" />
|
||||
<property name="password" value="1234" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:annotation-config/>
|
||||
|
||||
<context:component-scan base-package="com.ossean.hotwords"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="threshold" value="ERROR" />
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/error.log" />
|
||||
<param name="threshold" value="ERROR" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file_log" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/webmagic.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- 邮件(只有ERROR时才会发送!) -->
|
||||
<appender name="MAIL" class="org.apache.log4j.net.SMTPAppender">
|
||||
<param name="threshold" value="debug" />
|
||||
<!-- 日志的错误级别 <param name="threshold" value="fatal"/> -->
|
||||
<!-- 缓存文件大小,日志达到512K时发送Email -->
|
||||
<param name="BufferSize" value="1" />
|
||||
<!-- 单位K -->
|
||||
<param name="From" value="ossean_debug@163.com" />
|
||||
<param name="SMTPHost" value="smtp.163.com" />
|
||||
<param name="Subject" value="ossean-crawler-debug-log4jMessage" />
|
||||
<param name="To" value="gcm3651@126.com" />
|
||||
<param name="SMTPUsername" value="ossean_debug" />
|
||||
<param name="SMTPPassword" value="goodwell123" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss.SSS} [%p]-[%c] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- 数据库状态-->
|
||||
<appender name="DATABASE" class="org.apache.log4j.jdbc.JDBCAppender">
|
||||
<param name="URL" value="jdbc:mysql://127.0.0.1:3306/webmagic?characterEncoding=UTF-8"/>
|
||||
<param name="driver" value="com.mysql.jdbc.Driver"/>
|
||||
<param name="user" value="root"/>
|
||||
<param name="password" value="1234"/>
|
||||
<param name="sql" value="INSERT INTO log4j(stamp,thread,info_level,class,message,logger) VALUES ('%d{yyyy-MM-dd HH:mm:ss}','%t','%p','%c','%m','%l')"/>
|
||||
<!-- <layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="INSERT INTO log4j(stamp,thread,info_level,class,message,logger) VALUES ('%d{yyyy-MM-dd HH:mm:ss}','%t','%.50p','%.50c','%.1000m','%.50l')" />
|
||||
</layout>-->
|
||||
<!-- 过滤输出时Log内容,在这里,LevelMin是ERROR,LevelMax都 FATAL,所以输出DEBUG级别到FATAL级别的LOG数据-->
|
||||
<filter class="org.apache.log4j.varia.LevelRangeFilter">
|
||||
<param name="LevelMin" value="DEBUG"/>
|
||||
<param name="LevelMax" value="FATAL"/>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<logger name="org.apache" additivity="false">
|
||||
<level value="warn" />
|
||||
<appender-ref ref="stdout" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="info" />
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="file" />
|
||||
<appender-ref ref="file_log" />
|
||||
<!-- <appender-ref ref="MAIL" />-->
|
||||
<!-- <appender-ref ref="DATABASE" /> -->
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
find ./target/classes -name "*.properties"|xargs rm -f
|
||||
find ./target/classes -name "*.xml"|xargs rm -f
|
||||
find ./target/classes -name "*.dic"|xargs rm -f
|
||||
|
||||
#export CLASSPATH=$CURR_DIR/lib:$CURR_DIR:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
|
||||
|
||||
tmp='./target/classes':$tmp
|
||||
tmp='./target/hotwords-0.0.1-SNAPSHOT-jar-with-dependencies-without-resources/*':$tmp
|
||||
tmp='./bin/resources':$tmp
|
||||
CLASSPATH=$tmp:$CLASSPATH
|
||||
|
||||
|
||||
echo $CLASSPATH
|
||||
JVM_ARGS="-Xmn98m -Xmx512m -Xms512m -XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MaxTenuringThreshold=2"
|
||||
#echo JVM_ARGS=$JVM_ARGS
|
||||
#ulimit -n 400000
|
||||
#echo "" > nohup.out
|
||||
java $JVM_ARGS -classpath $CLASSPATH com.ossean.hotwords.Main >>log/info.log 2>&1 &
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,110 @@
|
|||
<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>ossean</groupId>
|
||||
<artifactId>hotwords</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<!-- m2eclipse wtp 0.12+ enabled to configure contextRoot, add by w.vela -->
|
||||
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
|
||||
<spring-version>3.1.1.RELEASE</spring-version>
|
||||
<spring-security-version>3.1.0.RELEASE</spring-security-version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib-nodep</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,25 @@
|
|||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<!-- TODO: a jarjar format would be better -->
|
||||
<id>jar-with-dependencies-without-resources</id>
|
||||
<formats>
|
||||
<format>dir</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<unpack>false</unpack>
|
||||
<scope>runtime</scope>
|
||||
</dependencySet>
|
||||
<dependencySet>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<unpack>false</unpack>
|
||||
<scope>system</scope>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
|
@ -0,0 +1,257 @@
|
|||
package com.ossean.hotwords;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ossean.hotwords.dao.OpenSourceProjectsDao;
|
||||
import com.ossean.hotwords.dao.PointersDao;
|
||||
import com.ossean.hotwords.dao.RelativeMemoToOpenSourceProjectsDao;
|
||||
import com.ossean.hotwords.dao.RelativeMemosDao;
|
||||
import com.ossean.hotwords.dao.TaggingsDao;
|
||||
import com.ossean.hotwords.dao.TagsDao;
|
||||
import com.ossean.hotwords.model.Hotwords;
|
||||
import com.ossean.hotwords.model.OpenSourceProjects;
|
||||
import com.ossean.hotwords.model.RelativeMemoToOpenSourceProjects;
|
||||
import com.ossean.hotwords.model.RelativeMemos;
|
||||
import com.ossean.hotwords.utils.InsertHotwords;
|
||||
import com.ossean.hotwords.utils.MapSort;
|
||||
import com.ossean.hotwords.utils.StringHandler;
|
||||
import com.ossean.hotwords.utils.UpdateTagsAndTaggings;
|
||||
|
||||
@Component
|
||||
public class Main {
|
||||
Logger logger = Logger.getLogger(this.getClass());
|
||||
@Resource
|
||||
private PointersDao pointersDao;
|
||||
@Resource
|
||||
private OpenSourceProjectsDao ospDao;
|
||||
@Resource
|
||||
private RelativeMemoToOpenSourceProjectsDao memoToOspDao;
|
||||
@Resource
|
||||
private TaggingsDao taggingsDao;
|
||||
@Resource
|
||||
private RelativeMemosDao memoDao;
|
||||
@Resource
|
||||
private TagsDao tagsDao;
|
||||
@Qualifier("updatetagsandtaggings")
|
||||
@Autowired
|
||||
private UpdateTagsAndTaggings updateClass;
|
||||
@Qualifier("inserthotwords")
|
||||
@Autowired
|
||||
private InsertHotwords insertClass;
|
||||
private static String sourceTableName = "open_source_projects";
|
||||
private static String targetTableName = "hot_words";
|
||||
|
||||
private static int batchSize = 10;// 一次处理项目数量
|
||||
public void start(){
|
||||
while(true){
|
||||
//读取断点位置
|
||||
int startId = 1;
|
||||
try {
|
||||
startId = pointersDao.readPointer(sourceTableName, targetTableName);
|
||||
} catch (Exception e){
|
||||
//表示还没有该记录
|
||||
pointersDao.insertPointer(sourceTableName, targetTableName);
|
||||
}
|
||||
//根据断点位置和批处理数量读取项目对象列表
|
||||
List<OpenSourceProjects> projects = ospDao.getProjectsByBatch(startId, batchSize);
|
||||
if(projects.size() == 0){
|
||||
//如果没有独处项目信息 表示没有需要处理的项目
|
||||
logger.info("no projects! Sleep 3600s");
|
||||
try {
|
||||
Thread.sleep(3600*1000L);
|
||||
continue;
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for(OpenSourceProjects project:projects){
|
||||
//循环处理所有的项目
|
||||
logger.info("匹配项目:" + project.getName() + " id:" + project.getId());
|
||||
//读取relative_memo_to_open_source_projects表中当前项目对应的帖子
|
||||
int prjId = project.getId();
|
||||
List<RelativeMemoToOpenSourceProjects> mtps = memoToOspDao.getRelativeMemosByOspId(prjId, getTargetTable(prjId));
|
||||
//定义存储标签name和标签权重的map 每个project一个map对象
|
||||
Map<String, Float> tagWeightMap = new LinkedHashMap<String,Float>();
|
||||
//定义存储标签name和标签词频的map 每个project一个map对象
|
||||
Map<String, Integer> tagCountMap = new HashMap<String, Integer>();
|
||||
//遍历每一个关联结果 即遍历每一个关联的帖子
|
||||
for(RelativeMemoToOpenSourceProjects item:mtps){
|
||||
//读取帖子id
|
||||
int memoId = item.getRelative_memo_id();
|
||||
//获取RelativeMemo对象
|
||||
RelativeMemos memo = memoDao.getById(memoId);
|
||||
//将RelativeMemos对象中的tags属性转换成List<String>
|
||||
List<String> memoTagList = new ArrayList<String>();
|
||||
try{
|
||||
memoTagList = StringHandler.changeTagsToTagList(memo.getTags());
|
||||
}catch(Exception e){
|
||||
//logger.info("没有找到对应的tags标签 memo_id:" + memoId);
|
||||
continue;
|
||||
}
|
||||
//循环遍历每个tagName 将对应的权重计算出来 得到最终的map
|
||||
for(String tagName:memoTagList){
|
||||
if(tagWeightMap.containsKey(tagName)){
|
||||
//表示map中已经存在该标签 需要将原来标签的权重取出并加上相应的taggings表中记录的匹配权重
|
||||
tagWeightMap.put(tagName, tagWeightMap.get(tagName) + item.getMatch_weight());
|
||||
tagCountMap.put(tagName, tagCountMap.get(tagName) + 1);
|
||||
}else{
|
||||
//表示map中没有该标签名
|
||||
tagWeightMap.put(tagName, item.getMatch_weight());
|
||||
tagCountMap.put(tagName,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//将map根据值从大到小排序
|
||||
tagWeightMap = MapSort.sort(tagWeightMap);
|
||||
//构造hotwords的List
|
||||
List<Hotwords> hotwordsList = new ArrayList<Hotwords>();
|
||||
Set<String> tagNames = tagWeightMap.keySet();
|
||||
Iterator<String> iterator = tagNames.iterator();
|
||||
int count_hotwords = 0;
|
||||
while(iterator.hasNext() && count_hotwords < 20){
|
||||
String tagName = iterator.next();//读取标签的名字
|
||||
Hotwords hotwords = new Hotwords();
|
||||
hotwords.setOsp_id(project.getId());
|
||||
hotwords.setName(tagName);
|
||||
hotwords.setWeight(tagWeightMap.get(tagName));
|
||||
count_hotwords++;
|
||||
hotwordsList.add(hotwords);
|
||||
}
|
||||
|
||||
//读取该项目的tags属性并转换成List
|
||||
List<String> projectTagList = StringHandler.changeTagsToTagList(project.getTags());
|
||||
//记录需要修改disagree_num的标签名
|
||||
List<String> updateDisagreeNumTagNameList = new ArrayList<String>();
|
||||
if(projectTagList.size() < 10){
|
||||
//表示如果项目标签数量小于10 向里面添加5填新的标签记录
|
||||
//遍历项目关联的所有标签
|
||||
Set<String> keys = tagWeightMap.keySet();
|
||||
Iterator<String> it = keys.iterator();
|
||||
int count = 0;//用于对新添加到项目中的标签进行计数
|
||||
//最多增加5个新的标签 最多增加到10个
|
||||
while(it.hasNext() && count < 5){
|
||||
String tagName = it.next();//取出标签的名字
|
||||
if(StringHandler.isTagExist(tagName, projectTagList)){
|
||||
//表示当前关联到的标签在项目标签中存在 需要对taggings表中disagree_num增加该标签出现的词频
|
||||
updateDisagreeNumTagNameList.add(tagName);//将需要修改的标签名先存储到列表中 在事物处理的时候统一处理
|
||||
continue;
|
||||
}else{
|
||||
//表示当前关联到的标签在项目原标签中不存在
|
||||
projectTagList.add(tagName);//将新标签添加到项目标签列表中
|
||||
count++;//每添加一个新标签 count计数器加1
|
||||
}
|
||||
}
|
||||
//如果count > 0 表示tags属性需要更新,taggings需要插入记录 同时需要向热词表中插入20条数据
|
||||
if(count > 0){
|
||||
String tagsNew = StringHandler.changeTagListToTags(projectTagList);
|
||||
logger.info("正在进行更新项目标签信息和taggings表信息操作,请勿中断程序");
|
||||
updateClass.update(project, projectTagList, tagsNew, count, sourceTableName, targetTableName, hotwordsList, updateDisagreeNumTagNameList, tagCountMap);
|
||||
}
|
||||
else{
|
||||
//表示没有新增的标签 只需要向热词表中添加20条热词
|
||||
insertClass.insert(hotwordsList, sourceTableName, targetTableName, project.getId() + 1, updateDisagreeNumTagNameList, tagCountMap, project);
|
||||
logger.info("当前项目" + project.getName() + "没有标签更新操作,只插入了热词和更新disagree_num标签");
|
||||
}
|
||||
}
|
||||
else{
|
||||
//表示项目已经存在10条记录 需要再添加3个标签 已经存在的标签不算在3个内
|
||||
//遍历项目关联的所有标签
|
||||
Set<String> keys = tagWeightMap.keySet();
|
||||
Iterator<String> it = keys.iterator();
|
||||
int count = 0;//用于对新添加到项目中的标签进行计数
|
||||
//最多增加5个新的标签 最多增加到10个
|
||||
while(it.hasNext() && count < 3){
|
||||
String tagName = it.next();//取出标签的名字
|
||||
if(StringHandler.isTagExist(tagName, projectTagList)){
|
||||
//表示当前关联到的标签在项目标签中存在 需要对taggings表中disagree_num增加该标签出现的词频
|
||||
updateDisagreeNumTagNameList.add(tagName);//将需要修改的标签名先存储到列表中 在事物处理的时候统一处理
|
||||
continue;
|
||||
}else{
|
||||
//表示当前关联到的标签在项目原标签中不存在
|
||||
projectTagList.add(tagName);//将新标签添加到项目标签列表中
|
||||
count++;//每添加一个新标签 count计数器加1
|
||||
}
|
||||
}
|
||||
//如果count > 0 表示tags属性需要更新,taggings需要插入记录 同时需要向热词表中插入20条数据
|
||||
if(count > 0){
|
||||
String tagsNew = StringHandler.changeTagListToTags(projectTagList);
|
||||
logger.info("正在进行更新项目标签信息和taggings表信息操作,请勿中断程序");
|
||||
updateClass.update(project, projectTagList, tagsNew, count, sourceTableName, targetTableName, hotwordsList, updateDisagreeNumTagNameList, tagCountMap);
|
||||
}
|
||||
else{
|
||||
//表示没有新增的标签 只需要向热词表中添加20条热词
|
||||
insertClass.insert(hotwordsList, sourceTableName, targetTableName, project.getId() + 1, updateDisagreeNumTagNameList, tagCountMap, project);
|
||||
logger.info("当前项目" + project.getName() + "只插入了热词和更新disagree_num标签");
|
||||
}
|
||||
insertClass.insert(hotwordsList, sourceTableName, targetTableName, project.getId() + 1, updateDisagreeNumTagNameList, tagCountMap, project);
|
||||
logger.info("当前项目" + project.getName() + "只插入了热词和更新disagree_num标签");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the match result table's name
|
||||
* @param osp_id
|
||||
* @return
|
||||
*/
|
||||
public static String getTargetTable(int osp_id){
|
||||
String targetTableName = "";
|
||||
if (osp_id < 500) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_1";
|
||||
}
|
||||
else if (osp_id >= 500 && osp_id < 1000) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_2";
|
||||
}
|
||||
else if (osp_id >= 1000 && osp_id < 1500) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_3";
|
||||
}
|
||||
else if (osp_id >= 1500 && osp_id < 2000) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_4";
|
||||
}
|
||||
else if (osp_id >= 2000 && osp_id < 3000) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_5";
|
||||
}
|
||||
else if (osp_id >= 3000 && osp_id < 5000) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_6";
|
||||
}
|
||||
else if (osp_id >= 5000 && osp_id < 7500) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_7";
|
||||
}
|
||||
else if (osp_id >= 7500 && osp_id < 10000) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_8";
|
||||
}
|
||||
else if (osp_id >= 10000 && osp_id < 310000) {
|
||||
int a = 7 + osp_id/5000;
|
||||
targetTableName = "relative_memo_to_open_source_projects_" + a;
|
||||
}
|
||||
else if (osp_id >= 310000) {
|
||||
targetTableName = "relative_memo_to_open_source_projects_70";
|
||||
}
|
||||
return targetTableName;
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/applicationContext*.xml");
|
||||
Main mainClass = applicationContext.getBean(Main.class);
|
||||
mainClass.start();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.ossean.hotwords.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import com.ossean.hotwords.model.Hotwords;
|
||||
|
||||
public interface HotwordsDao {
|
||||
|
||||
//向热词表中添加数据
|
||||
@Insert("insert into hot_words (`osp_id`,`name`,`weight`,`created_at`,`updated_at`) values (#{item.osp_id},#{item.name},#{item.weight},now(),now())")
|
||||
public void insertItem(@Param("item") Hotwords item);
|
||||
|
||||
|
||||
//查看是否存在osp_id和name对应的记录
|
||||
@Select("select * from hot_words where osp_id=#{item.osp_id} and name=#{item.name}")
|
||||
public List<Hotwords> findItem(@Param("item") Hotwords item);
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.ossean.hotwords.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.ossean.hotwords.model.OpenSourceProjects;
|
||||
|
||||
public interface OpenSourceProjectsDao {
|
||||
|
||||
//读取一定数量的项目信息
|
||||
@Select("select * from open_source_projects where id>=#{start} limit #{size}")
|
||||
public List<OpenSourceProjects> getProjectsByBatch(@Param("start") int start, @Param("size") int size);
|
||||
|
||||
|
||||
//对项目标签属性进行更新
|
||||
@Update("update open_source_projects set tags=#{tags} where id=#{id}")
|
||||
public void updateTagsOfProject(@Param("id") int id, @Param("tags") String tags);
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.ossean.hotwords.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
public interface PointersDao {
|
||||
|
||||
//读取pointers表中对应sourceTableName和targetTableNamed的指针
|
||||
@Select("select Pointer from pointers where SourceTableName=#{source} and TargetTableName=#{target}")
|
||||
public int readPointer(@Param("source") String source, @Param("target") String target);
|
||||
|
||||
//初始化指针 初始化大小为1
|
||||
@Insert("insert into pointers (SourceTableName, TargetTableName, Pointer) values (#{source}, #{target}, 1)")
|
||||
public void insertPointer(@Param("source") String source, @Param("target") String target);
|
||||
|
||||
|
||||
//更新指针
|
||||
@Update("update pointers set Pointer=#{pointer} where SourceTableName=#{source} and TargetTableName=#{target}")
|
||||
public void updatePointer(@Param("source") String source, @Param("target") String target, @Param("pointer") int pointer);
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.ossean.hotwords.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import com.ossean.hotwords.model.RelativeMemoToOpenSourceProjects;
|
||||
|
||||
public interface RelativeMemoToOpenSourceProjectsDao {
|
||||
|
||||
//读取项目id对应的所有关联的帖子
|
||||
@Select("select * from ${targetTableName} where osp_id = #{osp_id} and match_weight > 2")
|
||||
public List<RelativeMemoToOpenSourceProjects> getRelativeMemosByOspId(@Param("osp_id") int osp_id, @Param("targetTableName") String targetTableName);
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.ossean.hotwords.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import com.ossean.hotwords.model.RelativeMemos;
|
||||
|
||||
public interface RelativeMemosDao {
|
||||
|
||||
//根据帖子id获取帖子对象
|
||||
@Select("select * from relative_memos where id=#{id}")
|
||||
public RelativeMemos getById(@Param("id") int id);
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.ossean.hotwords.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.ossean.hotwords.model.Taggings;
|
||||
|
||||
public interface TaggingsDao {
|
||||
|
||||
//根据帖子id读取taggings表中与帖子相关联的taggings记录
|
||||
@Select("select * from taggings where taggable_id=#{memoId} and taggable_type='RelativeMemo'")
|
||||
public List<Taggings> getByMemoId(@Param("memoId") int memoId);
|
||||
|
||||
|
||||
//向taggings表中插入由匹配帖子标签得到的新项目标签
|
||||
@Insert("insert into taggings (tag_id,taggable_id,taggable_type,disagree_num,context,created_at,tag_source) values (#{item.tag_id},#{item.taggable_id},#{item.taggable_type},#{item.disagree_num},#{item.context},now(),#{item.tag_source})")
|
||||
public void insertTaggings(@Param("item") Taggings item);
|
||||
|
||||
|
||||
//查看taggings表中是否存在要查询的标签
|
||||
@Select("select * from taggings where tag_id=#{item.tag_id} and taggable_type=#{item.taggable_type} and taggable_id=#{item.taggable_id}")
|
||||
public List<Taggings> findTaggings(@Param("item") Taggings item);
|
||||
|
||||
//修改disagree_num值
|
||||
@Update("update taggings set disagree_num=#{value} where taggable_id=#{taggable_id} AND taggable_type=#{taggable_type} AND tag_id=#{tag_id} ")
|
||||
public void updateDisagreeNum(@Param("value") int value, @Param("taggable_id") int taggable_id, @Param("taggable_type") String taggable_type, @Param("tag_id") int tag_id);
|
||||
|
||||
|
||||
//获取disagree_num值
|
||||
@Select("select disagree_num from taggings where tag_id=#{tag_id} and taggable_id=#{taggable_id} and taggable_type=#{taggable_type}")
|
||||
public int getDisagreeNum(@Param("tag_id") int tag_id, @Param("taggable_id") int taggable_id, @Param("taggable_type") String taggable_type);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.ossean.hotwords.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
public interface TagsDao {
|
||||
|
||||
//根据标签名 取出标签id
|
||||
@Select("select id from tags where name=#{name}")
|
||||
public List<Integer> getIdByName(@Param("name") String name);
|
||||
|
||||
|
||||
//向tags表插入数据
|
||||
@Insert("insert into tags (name) values (#{name})")
|
||||
public void insertTag(@Param("name") String name);
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.ossean.hotwords.model;
|
||||
|
||||
public class Hotwords {
|
||||
|
||||
private int id;
|
||||
private int osp_id;
|
||||
private String name;
|
||||
private float weight;
|
||||
private String created_at;
|
||||
private String updated_at;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public int getOsp_id() {
|
||||
return osp_id;
|
||||
}
|
||||
public void setOsp_id(int osp_id) {
|
||||
this.osp_id = osp_id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public float getWeight() {
|
||||
return weight;
|
||||
}
|
||||
public void setWeight(float weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
public String getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
public String getUpdated_at() {
|
||||
return updated_at;
|
||||
}
|
||||
public void setUpdated_at(String updated_at) {
|
||||
this.updated_at = updated_at;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
package com.ossean.hotwords.model;
|
||||
|
||||
public class OpenSourceProjects {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String description;
|
||||
private int followers_num;
|
||||
private String url;
|
||||
private String language;
|
||||
private int download_num;
|
||||
private int view_num_crawled;
|
||||
private String category;
|
||||
private String crawled_time;
|
||||
private String source;
|
||||
private int view_num_local;
|
||||
private String created_at;
|
||||
private String updated_at;
|
||||
private int ossean_score;
|
||||
private int relative_memos_num;
|
||||
private String created_time;
|
||||
private String updated_time;
|
||||
private String tags;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public int getFollowers_num() {
|
||||
return followers_num;
|
||||
}
|
||||
public void setFollowers_num(int followers_num) {
|
||||
this.followers_num = followers_num;
|
||||
}
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
public int getDownload_num() {
|
||||
return download_num;
|
||||
}
|
||||
public void setDownload_num(int download_num) {
|
||||
this.download_num = download_num;
|
||||
}
|
||||
public int getView_num_crawled() {
|
||||
return view_num_crawled;
|
||||
}
|
||||
public void setView_num_crawled(int view_num_crawled) {
|
||||
this.view_num_crawled = view_num_crawled;
|
||||
}
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
public String getCrawled_time() {
|
||||
return crawled_time;
|
||||
}
|
||||
public void setCrawled_time(String crawled_time) {
|
||||
this.crawled_time = crawled_time;
|
||||
}
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
public int getView_num_local() {
|
||||
return view_num_local;
|
||||
}
|
||||
public void setView_num_local(int view_num_local) {
|
||||
this.view_num_local = view_num_local;
|
||||
}
|
||||
public String getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
public String getUpdated_at() {
|
||||
return updated_at;
|
||||
}
|
||||
public void setUpdated_at(String updated_at) {
|
||||
this.updated_at = updated_at;
|
||||
}
|
||||
public int getOssean_score() {
|
||||
return ossean_score;
|
||||
}
|
||||
public void setOssean_score(int ossean_score) {
|
||||
this.ossean_score = ossean_score;
|
||||
}
|
||||
public int getRelative_memos_num() {
|
||||
return relative_memos_num;
|
||||
}
|
||||
public void setRelative_memos_num(int relative_memos_num) {
|
||||
this.relative_memos_num = relative_memos_num;
|
||||
}
|
||||
public String getCreated_time() {
|
||||
return created_time;
|
||||
}
|
||||
public void setCreated_time(String created_time) {
|
||||
this.created_time = created_time;
|
||||
}
|
||||
public String getUpdated_time() {
|
||||
return updated_time;
|
||||
}
|
||||
public void setUpdated_time(String updated_time) {
|
||||
this.updated_time = updated_time;
|
||||
}
|
||||
public String getTags() {
|
||||
return tags;
|
||||
}
|
||||
public void setTags(String tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.ossean.hotwords.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RelativeMemoToOpenSourceProjects {
|
||||
|
||||
private int id;
|
||||
private int osp_id;
|
||||
private int relative_memo_id;
|
||||
private float match_weight;
|
||||
private String created_time;
|
||||
private List<Integer> tagIds;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public int getOsp_id() {
|
||||
return osp_id;
|
||||
}
|
||||
public void setOsp_id(int osp_id) {
|
||||
this.osp_id = osp_id;
|
||||
}
|
||||
public int getRelative_memo_id() {
|
||||
return relative_memo_id;
|
||||
}
|
||||
public void setRelative_memo_id(int relative_memo_id) {
|
||||
this.relative_memo_id = relative_memo_id;
|
||||
}
|
||||
public float getMatch_weight() {
|
||||
return match_weight;
|
||||
}
|
||||
public void setMatch_weight(float match_weight) {
|
||||
this.match_weight = match_weight;
|
||||
}
|
||||
public String getCreated_time() {
|
||||
return created_time;
|
||||
}
|
||||
public void setCreated_time(String created_time) {
|
||||
this.created_time = created_time;
|
||||
}
|
||||
public List<Integer> getTagIds() {
|
||||
return tagIds;
|
||||
}
|
||||
public void setTagIds(List<Integer> tagIds) {
|
||||
this.tagIds = tagIds;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
package com.ossean.hotwords.model;
|
||||
|
||||
public class RelativeMemos {
|
||||
|
||||
private int id;
|
||||
private int osp_id;
|
||||
private String subject;
|
||||
private String content;
|
||||
private String author;
|
||||
private int replies_num;
|
||||
private int lock;
|
||||
private int sticky;
|
||||
private String created_time;
|
||||
private String updated_time;
|
||||
private String url;
|
||||
private int view_num_crawled;
|
||||
private int vote_up_num;
|
||||
private int collection_num;
|
||||
private String abstractText;
|
||||
private String memo_type;
|
||||
private String source;
|
||||
private String category;
|
||||
private int view_num_trustie;
|
||||
private int author_id;
|
||||
private int parent_id;
|
||||
private int last_reply_id;
|
||||
private int is_quote;
|
||||
private String username;
|
||||
private String userhomeurl;
|
||||
private String crawled_time;
|
||||
private String author_url;
|
||||
private String url_md5;
|
||||
private String tags;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public int getOsp_id() {
|
||||
return osp_id;
|
||||
}
|
||||
public void setOsp_id(int osp_id) {
|
||||
this.osp_id = osp_id;
|
||||
}
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
public int getReplies_num() {
|
||||
return replies_num;
|
||||
}
|
||||
public void setReplies_num(int replies_num) {
|
||||
this.replies_num = replies_num;
|
||||
}
|
||||
public int getLock() {
|
||||
return lock;
|
||||
}
|
||||
public void setLock(int lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
public int getSticky() {
|
||||
return sticky;
|
||||
}
|
||||
public void setSticky(int sticky) {
|
||||
this.sticky = sticky;
|
||||
}
|
||||
public String getCreated_time() {
|
||||
return created_time;
|
||||
}
|
||||
public void setCreated_time(String created_time) {
|
||||
this.created_time = created_time;
|
||||
}
|
||||
public String getUpdated_time() {
|
||||
return updated_time;
|
||||
}
|
||||
public void setUpdated_time(String updated_time) {
|
||||
this.updated_time = updated_time;
|
||||
}
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
public int getView_num_crawled() {
|
||||
return view_num_crawled;
|
||||
}
|
||||
public void setView_num_crawled(int view_num_crawled) {
|
||||
this.view_num_crawled = view_num_crawled;
|
||||
}
|
||||
public int getVote_up_num() {
|
||||
return vote_up_num;
|
||||
}
|
||||
public void setVote_up_num(int vote_up_num) {
|
||||
this.vote_up_num = vote_up_num;
|
||||
}
|
||||
public int getCollection_num() {
|
||||
return collection_num;
|
||||
}
|
||||
public void setCollection_num(int collection_num) {
|
||||
this.collection_num = collection_num;
|
||||
}
|
||||
public String getAbstractText() {
|
||||
return abstractText;
|
||||
}
|
||||
public void setAbstractText(String abstractText) {
|
||||
this.abstractText = abstractText;
|
||||
}
|
||||
public String getMemo_type() {
|
||||
return memo_type;
|
||||
}
|
||||
public void setMemo_type(String memo_type) {
|
||||
this.memo_type = memo_type;
|
||||
}
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
public int getView_num_trustie() {
|
||||
return view_num_trustie;
|
||||
}
|
||||
public void setView_num_trustie(int view_num_trustie) {
|
||||
this.view_num_trustie = view_num_trustie;
|
||||
}
|
||||
public int getAuthor_id() {
|
||||
return author_id;
|
||||
}
|
||||
public void setAuthor_id(int author_id) {
|
||||
this.author_id = author_id;
|
||||
}
|
||||
public int getParent_id() {
|
||||
return parent_id;
|
||||
}
|
||||
public void setParent_id(int parent_id) {
|
||||
this.parent_id = parent_id;
|
||||
}
|
||||
public int getLast_reply_id() {
|
||||
return last_reply_id;
|
||||
}
|
||||
public void setLast_reply_id(int last_reply_id) {
|
||||
this.last_reply_id = last_reply_id;
|
||||
}
|
||||
public int getIs_quote() {
|
||||
return is_quote;
|
||||
}
|
||||
public void setIs_quote(int is_quote) {
|
||||
this.is_quote = is_quote;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getUserhomeurl() {
|
||||
return userhomeurl;
|
||||
}
|
||||
public void setUserhomeurl(String userhomeurl) {
|
||||
this.userhomeurl = userhomeurl;
|
||||
}
|
||||
public String getCrawled_time() {
|
||||
return crawled_time;
|
||||
}
|
||||
public void setCrawled_time(String crawled_time) {
|
||||
this.crawled_time = crawled_time;
|
||||
}
|
||||
public String getAuthor_url() {
|
||||
return author_url;
|
||||
}
|
||||
public void setAuthor_url(String author_url) {
|
||||
this.author_url = author_url;
|
||||
}
|
||||
public String getUrl_md5() {
|
||||
return url_md5;
|
||||
}
|
||||
public void setUrl_md5(String url_md5) {
|
||||
this.url_md5 = url_md5;
|
||||
}
|
||||
public String getTags() {
|
||||
return tags;
|
||||
}
|
||||
public void setTags(String tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.ossean.hotwords.model;
|
||||
|
||||
public class Taggings {
|
||||
private int id;
|
||||
private int tag_id;
|
||||
private int taggable_id;
|
||||
private String taggable_type;
|
||||
private int tagger_id;
|
||||
private String tagger_type;
|
||||
private String context;
|
||||
private String created_at;
|
||||
private int disagree_num;
|
||||
private String tag_source;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public int getTag_id() {
|
||||
return tag_id;
|
||||
}
|
||||
public void setTag_id(int tag_id) {
|
||||
this.tag_id = tag_id;
|
||||
}
|
||||
public int getTaggable_id() {
|
||||
return taggable_id;
|
||||
}
|
||||
public void setTaggable_id(int taggable_id) {
|
||||
this.taggable_id = taggable_id;
|
||||
}
|
||||
public String getTaggable_type() {
|
||||
return taggable_type;
|
||||
}
|
||||
public void setTaggable_type(String taggable_type) {
|
||||
this.taggable_type = taggable_type;
|
||||
}
|
||||
public int getTagger_id() {
|
||||
return tagger_id;
|
||||
}
|
||||
public void setTagger_id(int tagger_id) {
|
||||
this.tagger_id = tagger_id;
|
||||
}
|
||||
public String getTagger_type() {
|
||||
return tagger_type;
|
||||
}
|
||||
public void setTagger_type(String tagger_type) {
|
||||
this.tagger_type = tagger_type;
|
||||
}
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
public void setContext(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
public String getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
public int getDisagree_num() {
|
||||
return disagree_num;
|
||||
}
|
||||
public void setDisagree_num(int disagree_num) {
|
||||
this.disagree_num = disagree_num;
|
||||
}
|
||||
public String getTag_source() {
|
||||
return tag_source;
|
||||
}
|
||||
public void setTag_source(String tag_source) {
|
||||
this.tag_source = tag_source;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.ossean.hotwords.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.ossean.hotwords.dao.HotwordsDao;
|
||||
import com.ossean.hotwords.dao.PointersDao;
|
||||
import com.ossean.hotwords.dao.TaggingsDao;
|
||||
import com.ossean.hotwords.dao.TagsDao;
|
||||
import com.ossean.hotwords.model.Hotwords;
|
||||
import com.ossean.hotwords.model.OpenSourceProjects;
|
||||
|
||||
@Component("inserthotwords")
|
||||
public class InsertHotwords {
|
||||
|
||||
@Resource
|
||||
private HotwordsDao hotwordsDao;
|
||||
@Resource
|
||||
private PointersDao pointersDao;
|
||||
@Resource
|
||||
private TagsDao tagsDao;
|
||||
@Resource
|
||||
private TaggingsDao taggingsDao;
|
||||
|
||||
@Transactional(propagation=Propagation.REQUIRES_NEW)
|
||||
public void insert(List<Hotwords> hotwordsList, String sourceTableName, String targetTableName, int pointer, List<String> updateDisagreeNumTagNameList, Map<String, Integer> tagCountMap, OpenSourceProjects project){
|
||||
int count = 0;//用于纪录插入了多少个热词
|
||||
for(int i = 0; i < hotwordsList.size() && count < 20; i++){
|
||||
Hotwords hotwords = hotwordsList.get(i);
|
||||
//首先检查该osp_id和name的hotwords记录是否存在
|
||||
List<Hotwords> tmp = hotwordsDao.findItem(hotwords);
|
||||
if(tmp.size() != 0){
|
||||
//表示当前的记录存在
|
||||
continue;
|
||||
}
|
||||
//循环插入每一个hotwords对象
|
||||
hotwordsDao.insertItem(hotwords);
|
||||
count++;
|
||||
}
|
||||
|
||||
//修改需要增加disagree_num的词频
|
||||
for(int i = 0; i < updateDisagreeNumTagNameList.size(); i++){
|
||||
String tagName = updateDisagreeNumTagNameList.get(i);
|
||||
//根据tagName查找tagId
|
||||
List<Integer> ids = tagsDao.getIdByName(tagName);
|
||||
if(ids.size() == 0){
|
||||
//表示并不存在该标签 需要在tags表中增加这条记录
|
||||
tagsDao.insertTag(tagName);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
int tag_id = ids.get(0);
|
||||
int taggable_id = project.getId();
|
||||
String taggable_type = "OpenSourceProject";
|
||||
int value = taggingsDao.getDisagreeNum(tag_id, taggable_id, taggable_type);
|
||||
value = value + tagCountMap.get(tagName);//增加标签在帖子中出现的次数
|
||||
taggingsDao.updateDisagreeNum(value, taggable_id, taggable_type, tag_id);
|
||||
}
|
||||
|
||||
pointersDao.updatePointer(sourceTableName, targetTableName, pointer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.ossean.hotwords.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class MapSort {
|
||||
|
||||
public static Map<String, Float> sort(Map<String, Float> oldMap){
|
||||
ArrayList<Map.Entry<String, Float>> list = new ArrayList<Map.Entry<String, Float>>(oldMap.entrySet());
|
||||
Collections.sort(list, new Comparator<Map.Entry<String, Float>>() {
|
||||
|
||||
public int compare(Entry<String, Float> arg0,
|
||||
Entry<String, Float> arg1) {
|
||||
if(arg0.getValue() - arg1.getValue() > 0)
|
||||
return -1;
|
||||
else if(arg0.getValue() - arg1.getValue() < 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
Map<String,Float> newMap = new LinkedHashMap<String,Float>();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
newMap.put(list.get(i).getKey(), list.get(i).getValue());
|
||||
}
|
||||
return newMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.ossean.hotwords.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StringHandler {
|
||||
|
||||
//将tags字符串转换成List<String>
|
||||
public static List<String> changeTagsToTagList(String tags){
|
||||
List<String> result = new ArrayList<String>();
|
||||
if(tags != null && !"".equals(tags)){
|
||||
String[] strings = tags.split(",");
|
||||
for(String str:strings){
|
||||
int index1 = str.indexOf("<");
|
||||
int index2 = str.indexOf(">");
|
||||
if(index2 > index1 && index1 >= 0){
|
||||
//读取当前的标签
|
||||
String tag = str.substring(index1 + 1, index2);
|
||||
if(!"".equals(tag) )
|
||||
result.add(tag);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//将tagList转换成字符串
|
||||
public static String changeTagListToTags(List<String> tagList){
|
||||
String result = "";
|
||||
for(String tag:tagList){
|
||||
result += "<" + tag + ">,";
|
||||
}
|
||||
if(!"".equals(result)){
|
||||
//表示需要转换的标签数量不为0
|
||||
result = result.substring(0, result.length() - 1);
|
||||
}else{
|
||||
//表示没有需要转换的标签
|
||||
result = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//判断标签在List中是否存在
|
||||
public static boolean isTagExist(String tag, List<String> tags){
|
||||
for(int i = 0; i < tags.size(); i++){
|
||||
String tagName = tags.get(i);
|
||||
if(tagName.equals(tag)){
|
||||
//表示存在相同的标签
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;//遍历完还没有返回true 就表示没有相同名称的标签
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package com.ossean.hotwords.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.ossean.hotwords.dao.OpenSourceProjectsDao;
|
||||
import com.ossean.hotwords.dao.PointersDao;
|
||||
import com.ossean.hotwords.dao.TaggingsDao;
|
||||
import com.ossean.hotwords.dao.TagsDao;
|
||||
import com.ossean.hotwords.model.Hotwords;
|
||||
import com.ossean.hotwords.model.OpenSourceProjects;
|
||||
import com.ossean.hotwords.model.Taggings;
|
||||
|
||||
@Component("updatetagsandtaggings")
|
||||
public class UpdateTagsAndTaggings {
|
||||
Logger logger = Logger.getLogger(this.getClass());
|
||||
|
||||
@Resource
|
||||
private TaggingsDao taggingsDao;
|
||||
@Resource
|
||||
private OpenSourceProjectsDao ospDao;
|
||||
@Resource
|
||||
private TagsDao tagsDao;
|
||||
@Resource
|
||||
private PointersDao pointersDao;
|
||||
@Qualifier("inserthotwords")
|
||||
@Autowired
|
||||
private InsertHotwords insertClass;
|
||||
|
||||
@Transactional(propagation=Propagation.REQUIRES_NEW)
|
||||
public void update(OpenSourceProjects project, List<String> projectTagList, String tagsNew, int count, String sourceTableName, String targetTableName, List<Hotwords> hotwordsList, List<String> updateDisagreeNumTagNameList, Map<String, Integer> tagCountMap){
|
||||
//对新的项目标签(tags)属性进行更新
|
||||
ospDao.updateTagsOfProject(project.getId(), tagsNew);
|
||||
//对新加的标签进行遍历
|
||||
for(int i = projectTagList.size() - 1; i >= projectTagList.size() - count; i--){
|
||||
String tagName = projectTagList.get(i);
|
||||
//取出相应tagName的标签
|
||||
List<Integer> tagIds = tagsDao.getIdByName(tagName);
|
||||
if(tagIds.size() == 0){
|
||||
//表示tag不存在
|
||||
logger.fatal("tag: " + tagName + " doesn't exist! We will insert one");
|
||||
tagsDao.insertTag(tagName);
|
||||
i++;
|
||||
continue;
|
||||
}else{
|
||||
//表示标签存在
|
||||
int tagId = tagIds.get(0);
|
||||
//构造taggings对象
|
||||
Taggings taggings = new Taggings();
|
||||
taggings.setTag_id(tagId);
|
||||
taggings.setTaggable_id(project.getId());
|
||||
taggings.setDisagree_num(0);//初始化的disagree_num为0
|
||||
taggings.setTaggable_type("OpenSourceProject");
|
||||
taggings.setContext("tags");
|
||||
taggings.setTag_source("FromRelativeMemo");
|
||||
List<Taggings> tmp = taggingsDao.findTaggings(taggings);
|
||||
if(tmp.size() != 0){
|
||||
//表示已经存在相应的taggings记录
|
||||
continue;
|
||||
}else{
|
||||
//将新记录插入taggings表中
|
||||
taggingsDao.insertTaggings(taggings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//将项目对应的热词插入hotwords表 在insert函数中进行指针的更新 同时更新已经存在在项目标签属性中的标签disagree_num值
|
||||
insertClass.insert(hotwordsList, sourceTableName, targetTableName, project.getId() + 1, updateDisagreeNumTagNameList, tagCountMap, project);
|
||||
|
||||
logger.info("当前项目" + project.getName() + "的更新操作完成");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
|
||||
|
||||
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
||||
<property name="basePackage" value="com.ossean.hotwords" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
|
||||
destroy-method="close">
|
||||
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
||||
<property name="url"
|
||||
value="jdbc:mysql://localhost:3306/oss_dev?characterEncoding=UTF-8" />
|
||||
<property name="username" value="root" />
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven transaction-manager="transactionManager"/>
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:annotation-config/>
|
||||
|
||||
<context:component-scan base-package="com.ossean.hotwords"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="threshold" value="ERROR" />
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/error.log" />
|
||||
<param name="threshold" value="ERROR" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file_log" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/webmagic.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- 邮件(只有ERROR时才会发送!) -->
|
||||
<appender name="MAIL" class="org.apache.log4j.net.SMTPAppender">
|
||||
<param name="threshold" value="debug" />
|
||||
<!-- 日志的错误级别 <param name="threshold" value="fatal"/> -->
|
||||
<!-- 缓存文件大小,日志达到512K时发送Email -->
|
||||
<param name="BufferSize" value="1" />
|
||||
<!-- 单位K -->
|
||||
<param name="From" value="ossean_debug@163.com" />
|
||||
<param name="SMTPHost" value="smtp.163.com" />
|
||||
<param name="Subject" value="ossean-crawler-debug-log4jMessage" />
|
||||
<param name="To" value="gcm3651@126.com" />
|
||||
<param name="SMTPUsername" value="ossean_debug" />
|
||||
<param name="SMTPPassword" value="goodwell123" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss.SSS} [%p]-[%c] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- 数据库状态-->
|
||||
<appender name="DATABASE" class="org.apache.log4j.jdbc.JDBCAppender">
|
||||
<param name="URL" value="jdbc:mysql://127.0.0.1:3306/webmagic?characterEncoding=UTF-8"/>
|
||||
<param name="driver" value="com.mysql.jdbc.Driver"/>
|
||||
<param name="user" value="root"/>
|
||||
<param name="password" value="1234"/>
|
||||
<param name="sql" value="INSERT INTO log4j(stamp,thread,info_level,class,message,logger) VALUES ('%d{yyyy-MM-dd HH:mm:ss}','%t','%p','%c','%m','%l')"/>
|
||||
<!-- <layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="INSERT INTO log4j(stamp,thread,info_level,class,message,logger) VALUES ('%d{yyyy-MM-dd HH:mm:ss}','%t','%.50p','%.50c','%.1000m','%.50l')" />
|
||||
</layout>-->
|
||||
<!-- 过滤输出时Log内容,在这里,LevelMin是ERROR,LevelMax都 FATAL,所以输出DEBUG级别到FATAL级别的LOG数据-->
|
||||
<filter class="org.apache.log4j.varia.LevelRangeFilter">
|
||||
<param name="LevelMin" value="DEBUG"/>
|
||||
<param name="LevelMax" value="FATAL"/>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<logger name="org.apache" additivity="false">
|
||||
<level value="warn" />
|
||||
<appender-ref ref="stdout" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="info" />
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="file" />
|
||||
<appender-ref ref="file_log" />
|
||||
<!-- <appender-ref ref="MAIL" />-->
|
||||
<!-- <appender-ref ref="DATABASE" /> -->
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,41 @@
|
|||
package hotwords;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.ossean.hotwords.dao.HotwordsDao;
|
||||
import com.ossean.hotwords.model.Hotwords;
|
||||
import com.ossean.hotwords.utils.MapSort;
|
||||
import com.ossean.hotwords.utils.StringHandler;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args){
|
||||
// String str = "<tag1>,<tag2>,<tag3>";
|
||||
// List<String> result = StringHandler.changeTagsToTagList(str);
|
||||
// System.out.println("..." + result.get(0));
|
||||
// Map<String, Float> map = new HashMap<String, Float>();
|
||||
// map.put("tag1", (float) 15.30);
|
||||
// map.put("tag2", (float) 10.33);
|
||||
// map.put("tag3", (float) 20.66);
|
||||
// Map<String, Float> result = MapSort.sort(map);
|
||||
// System.out.println("afdsfdsf");
|
||||
// List<String> tagList = new ArrayList<String>();
|
||||
// tagList.add("tag1");
|
||||
// tagList.add("tag2");
|
||||
// tagList.add("tag3");
|
||||
// String tags = StringHandler.changeTagListToTags(tagList);
|
||||
// System.out.println(tags);
|
||||
Hotwords hotwords = new Hotwords();
|
||||
hotwords.setOsp_id(1);
|
||||
hotwords.setName("Nigel");
|
||||
hotwords.setWeight(20.0f);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="threshold" value="ERROR" />
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/error.log" />
|
||||
<param name="threshold" value="ERROR" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file_log" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/webmagic.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- 邮件(只有ERROR时才会发送!) -->
|
||||
<appender name="MAIL" class="org.apache.log4j.net.SMTPAppender">
|
||||
<param name="threshold" value="debug" />
|
||||
<!-- 日志的错误级别 <param name="threshold" value="fatal"/> -->
|
||||
<!-- 缓存文件大小,日志达到512K时发送Email -->
|
||||
<param name="BufferSize" value="1" />
|
||||
<!-- 单位K -->
|
||||
<param name="From" value="ossean_debug@163.com" />
|
||||
<param name="SMTPHost" value="smtp.163.com" />
|
||||
<param name="Subject" value="ossean-crawler-debug-log4jMessage" />
|
||||
<param name="To" value="gcm3651@126.com" />
|
||||
<param name="SMTPUsername" value="ossean_debug" />
|
||||
<param name="SMTPPassword" value="goodwell123" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss.SSS} [%p]-[%c] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- 数据库状态-->
|
||||
<appender name="DATABASE" class="org.apache.log4j.jdbc.JDBCAppender">
|
||||
<param name="URL" value="jdbc:mysql://127.0.0.1:3306/webmagic?characterEncoding=UTF-8"/>
|
||||
<param name="driver" value="com.mysql.jdbc.Driver"/>
|
||||
<param name="user" value="root"/>
|
||||
<param name="password" value="1234"/>
|
||||
<param name="sql" value="INSERT INTO log4j(stamp,thread,info_level,class,message,logger) VALUES ('%d{yyyy-MM-dd HH:mm:ss}','%t','%p','%c','%m','%l')"/>
|
||||
<!-- <layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="INSERT INTO log4j(stamp,thread,info_level,class,message,logger) VALUES ('%d{yyyy-MM-dd HH:mm:ss}','%t','%.50p','%.50c','%.1000m','%.50l')" />
|
||||
</layout>-->
|
||||
<!-- 过滤输出时Log内容,在这里,LevelMin是ERROR,LevelMax都 FATAL,所以输出DEBUG级别到FATAL级别的LOG数据-->
|
||||
<filter class="org.apache.log4j.varia.LevelRangeFilter">
|
||||
<param name="LevelMin" value="DEBUG"/>
|
||||
<param name="LevelMax" value="FATAL"/>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<logger name="org.apache" additivity="false">
|
||||
<level value="warn" />
|
||||
<appender-ref ref="stdout" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="info" />
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="file" />
|
||||
<appender-ref ref="file_log" />
|
||||
<!-- <appender-ref ref="MAIL" />-->
|
||||
<!-- <appender-ref ref="DATABASE" /> -->
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/assembly"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,6 @@
|
|||
/target/
|
||||
#.project
|
||||
#/.settings
|
||||
/lib/
|
||||
/procedure_for_tag
|
||||
/log/*
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>procedure_for_tag</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:annotation-config />
|
||||
|
||||
<!-- c3p0连接池配置 -->
|
||||
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
|
||||
<!-- 用户名 -->
|
||||
<property name="user" value="influx" />
|
||||
<!-- 用户密码 -->
|
||||
<property name="password" value="influx1234" />
|
||||
<property name="driverClass" value="com.mysql.jdbc.Driver" />
|
||||
<property name="jdbcUrl"
|
||||
value="jdbc:mysql://192.168.80.104:3306/buffer_test?useUnicode=true&characterEncoding=utf-8" />
|
||||
|
||||
<!--连接池中保留的最大连接数。默认值: 15 -->
|
||||
<property name="maxPoolSize" value="20" />
|
||||
<!-- 连接池中保留的最小连接数,默认为:3 -->
|
||||
<property name="minPoolSize" value="2" />
|
||||
<!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3 -->
|
||||
<property name="initialPoolSize" value="5" />
|
||||
|
||||
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。默认值: 0 -->
|
||||
<property name="maxIdleTime" value='60' />
|
||||
<property name="maxStatements" value='100' />
|
||||
<property name="maxStatementsPerConnection" value='20' />
|
||||
</bean>
|
||||
<!--context:component-scan base-package="net.trustie.webmagic.dao"/ -->
|
||||
</beans>
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="MAIL" class="org.apache.log4j.net.SMTPAppender">
|
||||
<param name="threshold" value="info" />
|
||||
<param name="BufferSize" value="512" />
|
||||
<param name="From" value="gcm365111@126.com" />
|
||||
<param name="SMTPHost" value="SMTP.126.com" />
|
||||
<param name="Subject" value="this is test" />
|
||||
<param name="SMTPUsername" value="gcm365111@126.com" />
|
||||
<param name="SMTPPassword" value="03023651gcm" />
|
||||
<param name="to" value="gcm3651@126.com" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/info.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
<root>
|
||||
<level value="info" />
|
||||
<appender-ref ref="file" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
find ./target/classes -name "*.properties"|xargs rm -f
|
||||
find ./target/classes -name "*.xml"|xargs rm -f
|
||||
find ./target/classes -name "*.dic"|xargs rm -f
|
||||
|
||||
#export CLASSPATH=$CURR_DIR/lib:$CURR_DIR:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
|
||||
|
||||
tmp='./bin/resources'
|
||||
tmp='./target/classes':$tmp
|
||||
tmp='./target/procedure_for_tag-0.0.1-SNAPSHOT-jar-with-dependencies-without-resources.jar':$tmp
|
||||
|
||||
CLASSPATH=$tmp:$CLASSPATH
|
||||
|
||||
|
||||
echo $CLASSPATH
|
||||
#JVM_ARGS="-Xms:512m -XX:MinPermSize=128m"
|
||||
#echo JVM_ARGS=$JVM_ARGS
|
||||
#ulimit -n 400000
|
||||
#echo "" > nohup.out
|
||||
java -classpath $CLASSPATH com.alan.myfunction.ProcedureTag>>info.log 2>&1 &
|
|
@ -0,0 +1,98 @@
|
|||
<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">
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.kg</groupId>
|
||||
<artifactId>procedure_for_tag</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>procedure_for_tag</name>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>*.xml</exclude>
|
||||
<exclude>*.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.alan.myfunction.ProcedureTag</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>4.1.2.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>c3p0</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
<version>0.9.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.0</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>1.8.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.30</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,19 @@
|
|||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<!-- TODO: a jarjar format would be better -->
|
||||
<id>jar-with-dependencies-without-resources</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<unpack>true</unpack>
|
||||
<scope>runtime</scope>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
|
@ -0,0 +1,223 @@
|
|||
package com.alan.myfunction;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GenerateTags {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
public final static int batchSize = 5000;
|
||||
SQLConnection sqlconn = null;
|
||||
String tableName = "";
|
||||
String colName = "";
|
||||
|
||||
public GenerateTags(String tableName, String colName) {
|
||||
this.sqlconn = SQLConnection.getInstance();
|
||||
this.tableName = tableName;
|
||||
this.colName = colName;
|
||||
|
||||
this.initRecord(this.tableName);
|
||||
|
||||
// this.initRecord(this.ospHlpTable);
|
||||
}
|
||||
|
||||
public void extract() {
|
||||
// tagMatchRelativeMemo();
|
||||
extractFromTKnowledge();
|
||||
// tagMatchOSP();
|
||||
}
|
||||
|
||||
// 从t_knowledge中抽取
|
||||
private void extractFromTKnowledge() {
|
||||
Connection conn = this.sqlconn.getConnection();
|
||||
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
int maxId = getMaxId(conn, this.tableName);
|
||||
int minId = getMinId(conn, this.tableName);
|
||||
// int offset = 0;
|
||||
ResultSet rs = null;
|
||||
int lower = minId;
|
||||
int upper = minId + GenerateTags.batchSize;
|
||||
while (lower < maxId) {
|
||||
rs = getBatch(conn, this.tableName, this.colName, lower, upper);
|
||||
lower = lower + TagMatch.batchSize;
|
||||
upper = upper + TagMatch.batchSize;
|
||||
|
||||
if (rs != null) {
|
||||
batchExtract(rs, conn, this.tableName);
|
||||
}
|
||||
logger.info("extracted tags from t_knowledge: " + lower + "-->"
|
||||
+ upper);
|
||||
}
|
||||
|
||||
// type: 0-->osp, 1-->memo
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 取得要匹配的最大id
|
||||
private int getMaxId(Connection conn, String tableName) {
|
||||
int rt = 0;
|
||||
String sql = "SELECT MAX(id) AS num FROM " + tableName;
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
// pst.setString(1, type);
|
||||
// pst.set
|
||||
ResultSet rs = pst.executeQuery();
|
||||
rs.next();
|
||||
rt = rs.getInt("num");
|
||||
pst.close();
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
// 取得需要匹配的最小id
|
||||
private int getMinId(Connection conn, String tableName) {
|
||||
int rt = 0;
|
||||
String recordName = tableName + "_for_tag";
|
||||
String sql = "SELECT insert_id from t_records WHERE insert_table = ?";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
pst.setString(1, recordName);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
rs.next();
|
||||
rt = rs.getInt("insert_id");
|
||||
pst.close();
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
// 取得一批需要匹配的条目
|
||||
private ResultSet getBatch(Connection conn, String tableName,
|
||||
String colName, int lower, int upper) {
|
||||
ResultSet rt = null;
|
||||
String sql = "SELECT id, " + colName + " AS tags from " + tableName
|
||||
+ " WHERE id > ? AND id <= ?";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
// pst.setString(1, col);
|
||||
// pst.setString(2, table);
|
||||
pst.setInt(1, lower);
|
||||
pst.setInt(2, upper);
|
||||
rt = pst.executeQuery();
|
||||
// pst.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
// 匹配一批 条目
|
||||
private void batchExtract(ResultSet rs, Connection conn, String tableName) {
|
||||
String rawTags = "";
|
||||
int cursor = 0;
|
||||
int itemId = 0;
|
||||
String sql = "INSERT IGNORE INTO tags (name) VALUES " + "(?)";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
while (rs.next()) {
|
||||
cursor = rs.getInt("id");
|
||||
rawTags = rs.getString("tags");
|
||||
// System.out.println(rawTags);
|
||||
|
||||
String regx = "<(.*?)>";
|
||||
Pattern pattern = Pattern.compile(regx);
|
||||
Matcher matcher;
|
||||
|
||||
if ((rawTags != null)
|
||||
&& !("".equals(rawTags == null ? null : rawTags.trim()))) {
|
||||
// resultTags = resultTags.replace(" ", "");
|
||||
matcher = pattern.matcher(rawTags);
|
||||
while (matcher.find()) {
|
||||
if (matcher.group(1) != "") {
|
||||
pst.setString(1,
|
||||
matcher.group(1).trim().replace(" ", "")
|
||||
.toLowerCase());
|
||||
|
||||
pst.addBatch();
|
||||
}
|
||||
}
|
||||
// System.out.println(rs.getString(1));
|
||||
}
|
||||
}
|
||||
pst.executeBatch();
|
||||
conn.commit();
|
||||
|
||||
String recordName = tableName + "_for_tag";
|
||||
String updateSql = "UPDATE t_records SET insert_id = ? WHERE insert_table = ?";
|
||||
pst = conn.prepareStatement(updateSql);
|
||||
pst.setInt(1, cursor);
|
||||
pst.setString(2, recordName);
|
||||
pst.executeUpdate();
|
||||
conn.commit();
|
||||
pst.close();
|
||||
System.out.println(recordName + ": " + cursor);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化记录指针表
|
||||
private void initRecord(String table) {
|
||||
Connection conn = this.sqlconn.getConnection();
|
||||
String recordName = table + "_for_tag";
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * from t_records where insert_table = ?";
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
pst.setString(1, recordName);
|
||||
rs = pst.executeQuery();
|
||||
if (!rs.next()) {
|
||||
String initSql = "INSERT INTO t_records (insert_table, insert_id) VALUES (?, ?)";
|
||||
pst = conn.prepareStatement(initSql);
|
||||
pst.setString(1, recordName);
|
||||
pst.setInt(2, 0);
|
||||
pst.executeUpdate();
|
||||
}
|
||||
conn.commit();
|
||||
pst.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.alan.myfunction;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
public class ProcedureTag {
|
||||
public static void main(String[] args) throws SQLException {
|
||||
|
||||
|
||||
while (true) {
|
||||
//MyJDBC.myexcute("t_knowledge");
|
||||
//GenerateTags gt = new GenerateTags("relative_memo_info_help", "tags");
|
||||
GenerateTags gt = new GenerateTags("t_knowledge", "tags");
|
||||
//从t_knowledge中分离中tag来存到tags中
|
||||
gt.extract();
|
||||
|
||||
|
||||
TagMatch tm = new TagMatch("relative_memo_info_help", "rm_id", "open_source_project_help", "osp_id");
|
||||
// 从relative_memo_info_help中取出记录与tags中 的记录匹配
|
||||
tm.match();
|
||||
|
||||
try {
|
||||
Thread.sleep(60000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.alan.myfunction;
|
||||
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
|
||||
public class SQLConnection {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private static SQLConnection dbcputils = null;
|
||||
private ComboPooledDataSource cpds = null;
|
||||
|
||||
private SQLConnection() {
|
||||
if (cpds == null) {
|
||||
// ApplicationContext applicationContext = new
|
||||
// ClassPathXmlApplicationContext("applicationContext.xml");
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"classpath:applicationContext.xml");
|
||||
this.cpds = (ComboPooledDataSource) applicationContext
|
||||
.getBean("dataSource");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static SQLConnection getInstance() {
|
||||
if (dbcputils == null)
|
||||
dbcputils = new SQLConnection();
|
||||
return dbcputils;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
Connection con = null;
|
||||
try {
|
||||
con = cpds.getConnection();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
return con;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws SQLException {
|
||||
Connection con = null;
|
||||
long begin = System.currentTimeMillis();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
con = SQLConnection.getInstance().getConnection();
|
||||
con.close();
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("<EFBFBD><EFBFBD>ʱΪ:" + (end - begin) + "ms");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,325 @@
|
|||
package com.alan.myfunction;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TagMatch {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
public final static int batchSize = 5000;
|
||||
SQLConnection sqlconn = null;
|
||||
String memoHlpTable = "";
|
||||
String memoHlpColName = "";
|
||||
String ospHlpTable = "";
|
||||
String ospHlpColName = "";
|
||||
Map<String, Integer> tags = new HashMap<String, Integer>();
|
||||
|
||||
public TagMatch(String memoTable, String memoColName, String ospTable,
|
||||
String ospColName) {
|
||||
this.sqlconn = SQLConnection.getInstance();
|
||||
this.memoHlpTable = memoTable;
|
||||
this.memoHlpColName = memoColName;
|
||||
this.ospHlpTable = ospTable;
|
||||
this.ospHlpColName = ospColName;
|
||||
this.initTags();
|
||||
this.initRecord(this.memoHlpTable);
|
||||
// this.initRecord(this.ospHlpTable);
|
||||
}
|
||||
|
||||
public void match() {
|
||||
tagMatchRelativeMemo();
|
||||
// tagMatchOSP();
|
||||
}
|
||||
|
||||
// 分离帖子标签
|
||||
private void tagMatchRelativeMemo() {
|
||||
Connection conn = this.sqlconn.getConnection();
|
||||
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
int maxId = getMaxId(conn, this.memoHlpTable);
|
||||
int minId = getMinId(conn, this.memoHlpTable);
|
||||
// int offset = 0;
|
||||
ResultSet rs = null;
|
||||
int lower = minId;
|
||||
int upper = minId + TagMatch.batchSize;
|
||||
while (lower < maxId) {
|
||||
rs = getBatch(conn, this.memoHlpTable, this.memoHlpColName, lower,
|
||||
upper);
|
||||
lower = lower + TagMatch.batchSize;
|
||||
upper = upper + TagMatch.batchSize;
|
||||
|
||||
// type: 0-->osp, 1-->memo
|
||||
if (rs != null) {
|
||||
batchMatch(rs, conn, this.memoHlpTable);
|
||||
|
||||
}
|
||||
logger.info("matched tags from relative_memo_help: " + lower
|
||||
+ "-->" + upper);
|
||||
}
|
||||
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 分离项目标签
|
||||
private void tagMatchOSP() {
|
||||
Connection conn = this.sqlconn.getConnection();
|
||||
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
int maxId = getMaxId(conn, this.ospHlpTable);
|
||||
int minId = getMinId(conn, this.ospHlpTable);
|
||||
int offset = 0;
|
||||
ResultSet rs = null;
|
||||
int lower = minId;
|
||||
int upper = minId + TagMatch.batchSize;
|
||||
while (lower < maxId) {
|
||||
rs = getBatch(conn, this.ospHlpTable, this.ospHlpColName, lower,
|
||||
upper);
|
||||
lower = lower + TagMatch.batchSize;
|
||||
upper = upper + TagMatch.batchSize;
|
||||
|
||||
if (rs != null) {
|
||||
batchMatch(rs, conn, this.ospHlpTable);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 取得要匹配的最大id
|
||||
private int getMaxId(Connection conn, String type) {
|
||||
int rt = 0;
|
||||
String sql = "SELECT MAX(id) AS num FROM " + type;
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
// pst.setString(1, type);
|
||||
// pst.set
|
||||
ResultSet rs = pst.executeQuery();
|
||||
rs.next();
|
||||
rt = rs.getInt("num");
|
||||
pst.close();
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
// 取得需要匹配的最小id
|
||||
private int getMinId(Connection conn, String type) {
|
||||
int rt = 0;
|
||||
String sql = "SELECT insert_id from t_records WHERE insert_table = ?";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
pst.setString(1, type);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
rs.next();
|
||||
rt = rs.getInt("insert_id");
|
||||
pst.close();
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
// 取得一批需要匹配的条目
|
||||
private ResultSet getBatch(Connection conn, String table, String col,
|
||||
int lower, int upper) {
|
||||
ResultSet rt = null;
|
||||
String sql = "SELECT id, " + col + " AS item_id, tags from " + table
|
||||
+ " WHERE id > ? AND id <= ?";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
// pst.setString(1, col);
|
||||
// pst.setString(2, table);
|
||||
pst.setInt(1, lower);
|
||||
pst.setInt(2, upper);
|
||||
rt = pst.executeQuery();
|
||||
// pst.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
// 匹配一批 条目
|
||||
private void batchMatch(ResultSet rs, Connection conn, String table) {
|
||||
String rawTag = "";
|
||||
int cursor = 0;
|
||||
int itemId = 0;
|
||||
String sql = "INSERT IGNORE INTO taggings (tag_id, taggable_id, taggable_type, context, created_at) VALUES "
|
||||
+ "(?, ?, ?, 'tags', ?)";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
// pst.setString(4, "tags");
|
||||
pst.setDate(4, new java.sql.Date(new java.util.Date().getTime()));
|
||||
if ("relative_memo_info_help".equals(table)) {
|
||||
pst.setString(3, "RelativeMemo");
|
||||
} else if ("open_source_project".equals(table)) {
|
||||
pst.setString(3, "OpenSourceProject");
|
||||
} else {
|
||||
pst.setString(3, "Other");
|
||||
}
|
||||
|
||||
while (rs.next()) {
|
||||
cursor = rs.getInt("id");
|
||||
rawTag = rs.getString("tags");
|
||||
if (rawTag != null) {
|
||||
rawTag = rawTag.toLowerCase();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
itemId = rs.getInt("item_id");
|
||||
pst.setInt(2, itemId);
|
||||
List<String> tagList = toList(rawTag);
|
||||
Iterator<String> it = tagList.iterator();
|
||||
while (it.hasNext()) {
|
||||
String tag = it.next();
|
||||
tag = tag.replace("'", "\\'");
|
||||
int tagId = 0;
|
||||
if (this.tags.containsKey(tag)) {
|
||||
tagId = this.tags.get(tag);
|
||||
}
|
||||
pst.setInt(1, tagId);
|
||||
pst.addBatch();
|
||||
}
|
||||
}
|
||||
|
||||
pst.executeBatch();
|
||||
conn.commit();
|
||||
|
||||
String updateSql = "UPDATE t_records SET insert_id = ? WHERE insert_table = ?";
|
||||
pst = conn.prepareStatement(updateSql);
|
||||
pst.setInt(1, cursor);
|
||||
pst.setString(2, table);
|
||||
pst.executeUpdate();
|
||||
conn.commit();
|
||||
pst.close();
|
||||
System.out.println(table + ": " + cursor);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 字符串标签变链表
|
||||
private List<String> toList(String tags) {
|
||||
List<String> rt = new ArrayList<String>();
|
||||
|
||||
String regx = "<(.*?)>";
|
||||
Pattern pattern = Pattern.compile(regx);
|
||||
Matcher matcher;
|
||||
|
||||
// resultTags = resultTags.replace(" ", "");
|
||||
matcher = pattern.matcher(tags);
|
||||
while (matcher.find()) {
|
||||
if (matcher.group(1) != "") {
|
||||
rt.add(matcher.group(1).trim().replace(" ", ""));
|
||||
}
|
||||
}
|
||||
// System.out.println(rs.getString(1));
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
// 初始化标签,将标签读到内存中
|
||||
private void initTags() {
|
||||
Connection conn = this.sqlconn.getConnection();
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT id, name from tags";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
Integer id = rs.getInt("id");
|
||||
this.tags.put(name, id);
|
||||
}
|
||||
pst.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化记录指针表
|
||||
private void initRecord(String table) {
|
||||
Connection conn = this.sqlconn.getConnection();
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * from t_records where insert_table = ?";
|
||||
try {
|
||||
PreparedStatement pst = conn.prepareStatement(sql);
|
||||
pst.setString(1, table);
|
||||
rs = pst.executeQuery();
|
||||
if (!rs.next()) {
|
||||
String initSql = "INSERT INTO t_records (insert_table, insert_id) VALUES (?, ?)";
|
||||
pst = conn.prepareStatement(initSql);
|
||||
pst.setString(1, table);
|
||||
pst.setInt(2, 0);
|
||||
pst.executeUpdate();
|
||||
}
|
||||
pst.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.info(e.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:annotation-config />
|
||||
|
||||
<!-- c3p0连接池配置 -->
|
||||
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
|
||||
<!-- 用户名 -->
|
||||
<property name="user" value="ossean" />
|
||||
<!-- 用户密码 -->
|
||||
<property name="password" value="1234" />
|
||||
<property name="driverClass" value="com.mysql.jdbc.Driver" />
|
||||
<property name="jdbcUrl"
|
||||
value="jdbc:mysql://192.168.120.129:3306/buffer_fix?useUnicode=true&characterEncoding=utf-8" />
|
||||
|
||||
<!--连接池中保留的最大连接数。默认值: 15 -->
|
||||
<property name="maxPoolSize" value="20" />
|
||||
<!-- 连接池中保留的最小连接数,默认为:3 -->
|
||||
<property name="minPoolSize" value="2" />
|
||||
<!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3 -->
|
||||
<property name="initialPoolSize" value="5" />
|
||||
|
||||
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。默认值: 0 -->
|
||||
<property name="maxIdleTime" value='60' />
|
||||
<property name="maxStatements" value='200' />
|
||||
<property name="maxStatementsPerConnection" value='30' />
|
||||
</bean>
|
||||
<!--context:component-scan base-package="net.trustie.webmagic.dao"/ -->
|
||||
</beans>
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="MAIL" class="org.apache.log4j.net.SMTPAppender">
|
||||
<param name="threshold" value="info" />
|
||||
<param name="BufferSize" value="512" />
|
||||
<param name="From" value="gcm365111@126.com" />
|
||||
<param name="SMTPHost" value="SMTP.126.com" />
|
||||
<param name="Subject" value="this is test" />
|
||||
<param name="SMTPUsername" value="gcm365111@126.com" />
|
||||
<param name="SMTPPassword" value="03023651gcm" />
|
||||
<param name="to" value="gcm3651@126.com" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="./log/info.log" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{yy-MM-dd HH:mm:ss,SSS} %-5p %c(%F:%L) ## %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
||||
|
||||
<root>
|
||||
<level value="info" />
|
||||
<appender-ref ref="file" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
|
@ -0,0 +1,18 @@
|
|||
package procedure_for_tag;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
|
||||
public class ApplicationContextTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"applicationContext.xml");
|
||||
ComboPooledDataSource cpds = (ComboPooledDataSource) applicationContext
|
||||
.getBean("dataSource");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package procedure_for_tag;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
public class Sl4jTest {
|
||||
//private final Log logger = LogFactory.getLog(getClass());
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public void test(){
|
||||
logger.info("info2");
|
||||
logger.error("error2");
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
Sl4jTest st = new Sl4jTest();
|
||||
st.test();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue