提交 4d9224bf 编写于 作者: M MaxKey

优化

上级 20c573be
......@@ -29,8 +29,6 @@ import org.apache.mybatis.jpa.dialect.Dialect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractStatementHandlerInterceptor implements Interceptor {
protected Logger _logger = LoggerFactory.getLogger(getClass());
......
......@@ -41,7 +41,6 @@ import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Intercepts({
@Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class ,Integer.class }),
@Signature(type = StatementHandler.class, method = "parameterize", args = { Statement.class }),
......
......@@ -27,7 +27,6 @@ import org.mybatis.spring.SqlSessionFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyBatisSessionFactoryBean extends SqlSessionFactoryBean {
protected Logger _logger = LoggerFactory.getLogger(MyBatisSessionFactoryBean.class);
private List<Interceptor> interceptors = Collections.emptyList();
......
......@@ -36,7 +36,6 @@ import org.apache.mybatis.jpa.persistence.JpaPagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Intercepts( {
@Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class ,Integer.class })})
public class StatementHandlerInterceptor extends AbstractStatementHandlerInterceptor implements Interceptor {
......
......@@ -21,8 +21,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.mybatis.jpa.persistence.JpaPagination;
public class DB2Dialect extends Dialect {
public DB2Dialect() {
......
......@@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.mybatis.jpa.persistence.JpaPagination;
public class DerbyDialect extends Dialect {
public DerbyDialect() {
......
......@@ -24,8 +24,6 @@ import org.apache.mybatis.jpa.persistence.JpaPagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* DB Access Dialect,inspiration from hibernate
*
......
......@@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.mybatis.jpa.persistence.JpaPagination;
public class HighgoDialect extends Dialect {
public HighgoDialect() {
......
......@@ -22,7 +22,6 @@ import java.sql.SQLException;
import org.apache.mybatis.jpa.persistence.JpaPagination;
public class MySQLDialect extends Dialect {
public MySQLDialect() {
......
......@@ -21,8 +21,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.mybatis.jpa.persistence.JpaPagination;
public class OracleDialect extends Dialect {
public OracleDialect() {
......
......@@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.mybatis.jpa.persistence.JpaPagination;
public class PostgreSQLDialect extends Dialect {
public PostgreSQLDialect() {
......
......@@ -22,12 +22,10 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.mybatis.jpa.persistence.JpaPagination;
public class SQLServerDialect extends Dialect {
public SQLServerDialect() {
super();
}
@Override
......
......@@ -124,5 +124,4 @@ public class SerialGenerator implements IdentifierGenerator{
getNodeNumber();
}
}
......@@ -14,12 +14,4 @@
* limitations under the License.
*/
/**
*
*/
/**
* @author Administrator
*
*/
package org.apache.mybatis.jpa.id;
......@@ -43,7 +43,6 @@ import jakarta.persistence.Transient;
* @author Crystal.Sea
*
*/
public class MapperMetadata <T extends JpaBaseEntity>{
private static final Logger _logger = LoggerFactory.getLogger(MapperMetadata.class);
......
......@@ -13,13 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
*/
/**
* @author user
*
*/
package org.apache.mybatis.jpa.persistence;
......@@ -21,7 +21,4 @@ public class SqlSyntax {
public static final String COUNT_ONE = "count(1)";
}
}
......@@ -19,8 +19,11 @@ package org.apache.mybatis.jpa.util;
import org.apache.commons.lang.SystemUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......@@ -29,21 +32,44 @@ import org.springframework.web.context.support.WebApplicationContextUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
/**
* Application Context
* Mybatis Jpa Context
*
* @author Crystal.Sea
* @since 1.6
* @since 3.0
*/
public final class MybatisJpaContext {
private static final Logger _logger = LoggerFactory.getLogger(MybatisJpaContext.class);
private static String VERSION = null;
public static StandardEnvironment properties;
private static StandardEnvironment properties;
public static ApplicationContext applicationContext = null;
private static ApplicationContext mybatisJpaContext = null;
/**
* init mybatisJpaContext and properties
*
* @param applicationContext
*/
public static void init(ApplicationContext applicationContext) {
mybatisJpaContext = applicationContext;
if (mybatisJpaContext.containsBean("propertySourcesPlaceholderConfigurer")) {
_logger.trace("init MybatisJpaContext properties");
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =
((PropertySourcesPlaceholderConfigurer) applicationContext
.getBean("propertySourcesPlaceholderConfigurer"));
properties = (StandardEnvironment) propertySourcesPlaceholderConfigurer
.getAppliedPropertySources()
.get(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME)
.getSource();
}
}
/**
* get ApplicationContext from web ServletContext configuration
......@@ -59,18 +85,18 @@ public final class MybatisJpaContext {
* @return Object
*/
public static Object getBean(String id){
if(applicationContext == null) {
if(mybatisJpaContext == null) {
return getApplicationContext().getBean(id);
}else {
return applicationContext.getBean(id);
return mybatisJpaContext.getBean(id);
}
}
public static <T> T getBean(String name, Class<T> requiredType) throws BeansException{
if(applicationContext == null) {
if(mybatisJpaContext == null) {
return getApplicationContext().getBean(name,requiredType);
}else {
return applicationContext.getBean(name,requiredType);
return mybatisJpaContext.getBean(name,requiredType);
}
};
......@@ -91,6 +117,14 @@ public final class MybatisJpaContext {
return getRequest().getSession();
}
public static StandardEnvironment getProperties() {
return properties;
}
public static ApplicationContext getMybatisJpaContext() {
return mybatisJpaContext;
}
public static String version() {
if(VERSION == null) {
StringBuffer version =
......
......@@ -13,13 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
*/
/**
* @author user
*
*/
package org.apache.mybatis.jpa.util;
......@@ -60,7 +60,7 @@ public class MybatisJpaApplication implements ApplicationRunner{
@Override
public void run(ApplicationArguments args) throws Exception {
MybatisJpaContext.applicationContext=applicationContext;
MybatisJpaContext.init(applicationContext);
_logger.info("queryPageResults by mapperId...");
Students student=new Students();
......
......@@ -43,11 +43,10 @@ public class MybatisJpaApplicationTest{
@Autowired
private ApplicationContext applicationContext;
@BeforeEach
public void before() {
_logger.info("---------------- before");
MybatisJpaContext.applicationContext = applicationContext;
MybatisJpaContext.init(applicationContext);
}
......@@ -78,7 +77,6 @@ public class MybatisJpaApplicationTest{
}
@Test
public void remove() throws Exception{
......@@ -105,9 +103,7 @@ public class MybatisJpaApplicationTest{
_logger.info("queryPageResults...");
Students student=new Students();
//student.setId("af04d610-6092-481e-9558-30bd63ef783c");
student.setStdGender("M");
//student.setStdMajor(政治");
student.setPageSize(10);
student.setPageNumber(2);
List<Students> allListStudents =
......@@ -123,7 +119,6 @@ public class MybatisJpaApplicationTest{
_logger.info("queryPageResults by mapperId...");
Students student=new Students();
student.setStdGender("M");
//student.setStdMajor(政治");
student.setPageSize(10);
student.setPageNumber(2);
......@@ -145,6 +140,5 @@ public class MybatisJpaApplicationTest{
_logger.info("Students "+s);
}
}
}
......@@ -83,6 +83,7 @@ import org.springframework.util.StringUtils;
* @author Josh Long
* @author Kazuki Shimizu
* @author Eduardo Macarrón
* @author Crystal.Sea
*/
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ SqlSessionFactory.class, SqlSessionFactoryBean.class })
......
......@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
......@@ -25,12 +24,11 @@ import java.util.List;
import org.apache.mybatis.jpa.persistence.IJpaBaseMapper;
import org.apache.mybatis.jpa.test.entity.Students;
/**
* @author Crystal.Sea
*
*/
public interface StudentsMapper extends IJpaBaseMapper<Students> {
public interface StudentsMapper extends IJpaBaseMapper<Students> {
public List<Students> queryPageResults1(Students entity);
}
......@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.mybatis.jpa.test.dao.service;
......@@ -22,7 +21,6 @@ import org.apache.mybatis.jpa.test.dao.persistence.StudentsMapper;
import org.apache.mybatis.jpa.test.entity.Students;
import org.springframework.stereotype.Service;
@Service
public class StudentsService extends JpaBaseService<Students> {
......@@ -31,14 +29,14 @@ public class StudentsService extends JpaBaseService<Students> {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.connsec.db.service.BaseService#getMapper()
*/
@Override
public StudentsMapper getMapper() {
return (StudentsMapper)super.getMapper();
return (StudentsMapper) super.getMapper();
}
}
......@@ -13,13 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.mybatis.jpa.test.entity;
import java.io.Serializable;
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
import jakarta.persistence.Column;
......@@ -29,8 +26,6 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
/*
ID varchar(40) not null,
NAME varchar(60) not null,
......@@ -46,18 +41,18 @@ import jakarta.persistence.Table;
*
*/
@Entity
@Table(name = "STUDENTS")
public class Students extends JpaBaseEntity implements Serializable{
@Table(name = "STUDENTS")
public class Students extends JpaBaseEntity implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6928570405840778151L;
@Id
@Column
@GeneratedValue(strategy=GenerationType.AUTO,generator="snowflakeid")
//@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SEQ_MYBATIS_STUD")
//@GeneratedValue(strategy=GenerationType.IDENTITY,generator="SEQ_MYBATIS_STUD")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid")
// @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SEQ_MYBATIS_STUD")
// @GeneratedValue(strategy=GenerationType.IDENTITY,generator="SEQ_MYBATIS_STUD")
private String id;
@Column
private String stdNo;
......@@ -71,11 +66,9 @@ public class Students extends JpaBaseEntity implements Serializable{
private String stdMajor;
@Column
private String stdClass;
@Column
private byte[] images;
public Students() {
super();
}
......@@ -88,90 +81,70 @@ public class Students extends JpaBaseEntity implements Serializable{
return stdNo;
}
public void setStdNo(String stdNo) {
this.stdNo = stdNo;
}
public String getStdName() {
return stdName;
}
public void setStdName(String stdName) {
this.stdName = stdName;
}
public String getStdGender() {
return stdGender;
}
public void setStdGender(String stdGender) {
this.stdGender = stdGender;
}
public int getStdAge() {
return stdAge;
}
public void setStdAge(int stdAge) {
this.stdAge = stdAge;
}
public String getStdMajor() {
return stdMajor;
}
public void setStdMajor(String stdMajor) {
this.stdMajor = stdMajor;
}
public String getStdClass() {
return stdClass;
}
public void setStdClass(String stdClass) {
this.stdClass = stdClass;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public byte[] getImages() {
return images;
}
public void setImages(byte[] images) {
this.images = images;
}
@Override
public String toString() {
return "Students [id=" + id + ", stdNo=" + stdNo + ", stdName=" + stdName + ", stdGender=" + stdGender
+ ", stdAge=" + stdAge + ", stdMajor=" + stdMajor + ", stdClass=" + stdClass + "]";
}
}
......@@ -35,7 +35,6 @@ public class CurdTestRunner {
public void insert() throws Exception{
_logger.info("insert...");
Students student=new Students();
//student.setId("10024");
student.setStdNo("10024");
student.setStdGender("M");
student.setStdName("司马昭");
......@@ -46,14 +45,12 @@ public class CurdTestRunner {
Thread.sleep(1000);
_logger.info("insert id " + student.getId());
//service.remove(student.getId());
}
@Test
public void merge() throws Exception{
_logger.info("merge...");
Students student=new Students();
//student.setId("10024");
student.setStdNo("10024");
student.setStdGender("M");
student.setStdName("司马昭");
......@@ -64,7 +61,6 @@ public class CurdTestRunner {
Thread.sleep(1000);
_logger.info("insert id " + student.getId());
//service.remove(student.getId());
}
......
......@@ -22,8 +22,8 @@ public class InitContext {
_logger.info("-- --Init Start at {}" , startTime);
_logger.info("Application dir "+System.getProperty("user.dir"));
context = new ClassPathXmlApplicationContext(new String[] {"spring/applicationContext.xml"});
MybatisJpaContext.applicationContext=context;
MybatisJpaContext.init(context);
StudentsService service =(StudentsService)MybatisJpaContext.getBean("studentsService");
return service;
}
......
......@@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PageResultsTestRunner {
private static final Logger _logger = LoggerFactory.getLogger(PageResultsTestRunner.class);
public static StudentsService service;
......@@ -37,10 +36,7 @@ public class PageResultsTestRunner {
_logger.info("queryPageResults...");
Students student=new Students();
//student.setStdGender("M");
//student.setStdMajor(政治");
student.setPageSize(10);
//student.setPageNumber(2);
student.calculate(21);
JpaPageResults<Students> results = service.queryPageResults(student);
List<Students> rowsStudents = results.getRows();
......@@ -84,6 +80,5 @@ public class PageResultsTestRunner {
if(InitContext.context!=null) return;
service = new InitContext().init();
}
}
\ No newline at end of file
......@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.mybatis.jpa.test;
......
......@@ -33,4 +33,4 @@ public class SnowFlakeIdGeneratorTest {
_logger.info("length {}",conditionString.length());
}
}
}
\ No newline at end of file
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* 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.
*/
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册