Skip to content

Commit

Permalink
数据库建表
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 30, 2012
1 parent c7270b2 commit d9c1b36
Show file tree
Hide file tree
Showing 12 changed files with 717 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,5 @@ pip-log.txt

# Mac crap
.DS_Store
!/src/main/resources/local.properties
/target/
2 changes: 0 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Request features/Report bugs: https://github.com/b3log/b3log-symphony/issues/new
QQ Qun: 13139268

B3log Index: http://b3log.org
B3log Team: https://github.com/b3log/b3log-solo/wiki/About_us
Join B3log Team: https://github.com/b3log/b3log-solo/wiki/Join_us

====
平等,自由,奔放
Expand Down
86 changes: 46 additions & 40 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<testng.version>6.1.1</testng.version>
<!-- -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
</properties>

<organization>
Expand Down Expand Up @@ -120,54 +121,59 @@
</plugins>
</reporting>

<dependencyManagement>
<dependencies>
<dependencies>

<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke</artifactId>
<version>${org.b3log.latke.version}</version>
</dependency>
<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke</artifactId>
<version>${org.b3log.latke.version}</version>
</dependency>

<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke-gae</artifactId>
<version>${org.b3log.latke-gae.version}</version>
</dependency>
<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke-gae</artifactId>
<version>${org.b3log.latke-gae.version}</version>
</dependency>

<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke-repository-mysql</artifactId>
<version>${org.b3log.latke-repository-mysql.version}</version>
</dependency>
<dependency>
<groupId>org.b3log</groupId>
<artifactId>latke-repository-mysql</artifactId>
<version>${org.b3log.latke-repository-mysql.version}</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
</dependency>

<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker-gae</artifactId>
<version>${freemarker-gae.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker-gae</artifactId>
<version>${freemarker-gae.version}</version>
</dependency>

<dependency>
<groupId>org.tautua.markdownpapers</groupId>
<artifactId>markdownpapers-core</artifactId>
<version>${markdownpapers-core.version}</version>
</dependency>
<dependency>
<groupId>org.tautua.markdownpapers</groupId>
<artifactId>markdownpapers-core</artifactId>
<version>${markdownpapers-core.version}</version>
</dependency>

</dependencies>
</dependencyManagement>
</dependencies>

<build>
<plugins>
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/org/b3log/symphony/SymphonyServletListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.symphony;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletRequestEvent;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSessionEvent;
import org.b3log.latke.Keys;
import org.b3log.latke.servlet.AbstractServletListener;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.latke.util.Strings;
import org.b3log.latke.util.Requests;

/**
* B3log Symphony servlet listener.
*
* @author <a href="mailto:[email protected]">Liang Ding</a>
* @version 1.0.0.0, Jul 30, 2011
* @since 0.2.0
*/
public final class SymphonyServletListener extends AbstractServletListener {

/**
* B3log Symphony version.
*/
public static final String VERSION = "0.2.0";
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(SymphonyServletListener.class.getName());
/**
* JSONO print indent factor.
*/
public static final int JSON_PRINT_INDENT_FACTOR = 4;
/**
* B3log Rhythm address.
*/
public static final String B3LOG_RHYTHM_ADDRESS = "http://rhythm.b3log.org:80";

@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
Stopwatchs.start("Context Initialized");

super.contextInitialized(servletContextEvent);

LOGGER.info("Initialized the context");

Stopwatchs.end();
LOGGER.log(Level.FINE, "Stopwatch: {0}{1}", new Object[]{Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat()});
}

@Override
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
super.contextDestroyed(servletContextEvent);

LOGGER.info("Destroyed the context");
}

@Override
public void sessionCreated(final HttpSessionEvent httpSessionEvent) {
}

// Note: This method will never invoked on GAE production environment
@Override
public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) {
}

@Override
public void requestInitialized(final ServletRequestEvent servletRequestEvent) {
final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest();
final String requestURI = httpServletRequest.getRequestURI();
Stopwatchs.start("Request Initialized[requestURI=" + requestURI + "]");

if (Requests.searchEngineBotRequest(httpServletRequest)) {
LOGGER.log(Level.FINER, "Request made from a search engine[User-Agent={0}]", httpServletRequest.getHeader("User-Agent"));
httpServletRequest.setAttribute(Keys.HttpRequest.IS_SEARCH_ENGINE_BOT, true);
}
}

@Override
public void requestDestroyed(final ServletRequestEvent servletRequestEvent) {
Stopwatchs.end();

LOGGER.log(Level.FINE, "Stopwatch: {0}{1}", new Object[]{Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat()});
Stopwatchs.release();

super.requestDestroyed(servletRequestEvent);
}
}
73 changes: 73 additions & 0 deletions src/main/java/org/b3log/symphony/dev/InitProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.symphony.dev;

import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.b3log.latke.Latkes;
import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor;
import org.b3log.latke.repository.jdbc.util.JdbcRepositories;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.util.Stopwatchs;

/**
* Initializes database.
*
* @author <a href="mailto:[email protected]">Liang Ding</a>
* @version 1.0.0.0, Jul 30, 2012
* @since 0.2.0
*/
@RequestProcessor
public class InitProcessor {

/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(InitProcessor.class.getName());

/**
* Generates tables.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws IOException io exception
*/
@RequestProcessing(value = "/dev/db/table/gen", method = HTTPRequestMethod.GET)
public void genTables(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws IOException {
Stopwatchs.start("Gen Tables");

try {
LOGGER.log(Level.INFO, "Database [{0}], creates all tables", Latkes.getRuntimeDatabase());
final List<JdbcRepositories.CreateTableResult> createTableResults = JdbcRepositories.initAllTables();
for (final JdbcRepositories.CreateTableResult createTableResult : createTableResults) {
LOGGER.log(Level.INFO, "Creates table result[tableName={0}, isSuccess={1}]",
new Object[]{createTableResult.getName(), createTableResult.isSuccess()});
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Creates database tables failed", e);
}

Stopwatchs.end();
}
}
50 changes: 50 additions & 0 deletions src/main/resources/latke.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright (c) 2012, B3log Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Description: B3log Latke configurations. Configures the section "Server" carefully.
# Version: 1.0.0.0, Jul 30, 2012
# Author: Liang Ding
#

#### Server ####
# Configures the followings before deploy
serverScheme=http
serverHost=localhost
serverPort=8080
staticServerScheme=http
staticServerHost=localhost
staticServerPort=8080
# Note: The context path and static path should be "" if deploy app on ROOT. For other cases, starts with '/'
# and not ends with '/', for example, /blog
contextPath=
staticPath=

#### Runtime Environment ####
runtimeEnv=LOCAL
#runtimeEnv=GAE

#### Cache Implementation ####
# Note: If the runtime environment is LOCAL, the cache will be LOCAL always
cache=LOCAL
#cache=GAE

#### User Service Implementation ####
# userService=GAE
userService=LOCAL

#### Static resource version ####
staticResourceVersion=201207301345
35 changes: 35 additions & 0 deletions src/main/resources/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (c) 2012, B3log Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Description: B3log Symphony local environment configurations.
# Version: 1.0.0.0, Jul 30, 2012
# Author: Liang Ding
#

#### Runtime Database (RuntimeDatabase) ####
runtimeDatabase=MYSQL

#### JDBC database Configurations ####
jdbc.driver=com.mysql.jdbc.Driver
jdbc.URL=jdbc:mysql://localhost:3306/b3log-symphony?useUnicode=yes&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=
# The minConnCnt MUST larger or equal to 3
jdbc.minConnCnt=3
jdbc.maxConnCnt=10
# Be care to change the transaction isolation
jdbc.transactionIsolation=READ_COMMITTED
Loading

0 comments on commit d9c1b36

Please sign in to comment.