Skip to content

Commit

Permalink
Merge branch 'master' into rxsocks
Browse files Browse the repository at this point in the history
  • Loading branch information
RockyLOMO committed Feb 21, 2024
2 parents 6e735ec + e73498f commit e9a2c00
Show file tree
Hide file tree
Showing 38 changed files with 2,280 additions and 60 deletions.
12 changes: 3 additions & 9 deletions agent/pom.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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>
<parent>
<groupId>com.github.rockylomo</groupId>
<artifactId>rx</artifactId>
<version>2.19.10</version>
<version>2.19.13-SNAPSHOT</version>
</parent>
<artifactId>agent</artifactId>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<lombok.version>1.18.26</lombok.version>
</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.rockylomo</groupId>
<artifactId>rxlib</artifactId>
Expand Down
33 changes: 30 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.rockylomo</groupId>
<artifactId>rx</artifactId>
<version>2.19.13-SNAPSHOT</version>
<version>2.20.1-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
Expand All @@ -12,9 +12,10 @@
<version>9</version>
</parent>
<modules>
<module>rxlib</module>
<module>agent</module>
<module>daemon</module>
<module>agent</module>
<module>rxlib</module>
<module>rxlib-x</module>
</modules>

<name>rx</name>
Expand Down Expand Up @@ -54,8 +55,34 @@
<java.version>1.8</java.version>
<shallow>true</shallow>
<gpg.skip>false</gpg.skip>

<lombok.version>1.18.30</lombok.version>
<junit.version>5.9.1</junit.version>
<jmh.version>1.36</jmh.version>
</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
49 changes: 49 additions & 0 deletions rxlib-x/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>com.github.rockylomo</groupId>
<artifactId>rx</artifactId>
<version>2.20.1-SNAPSHOT</version>
</parent>
<artifactId>rxlib-x</artifactId>
<packaging>jar</packaging>
<name>rxlib-x</name>
<description>A set of utilities for Java</description>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lombok.version>1.18.30</lombok.version>
</properties>

<dependencies>
<dependency>
<groupId>com.github.rockylomo</groupId>
<artifactId>rxlib</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.21</version>
</dependency>
</dependencies>
</project>
13 changes: 13 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/ConnectionPoolKind.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.rx.jdbc;

/**
* Created by IntelliJ IDEA.
*
* @author wangxiaoming
* Date: 2019/12/10
*/
public enum ConnectionPoolKind {
NONE,
HikariCP,
Druid
}
25 changes: 25 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/ConnectionPoolMXBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.rx.jdbc;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* Created by IntelliJ IDEA.
*
* @author wangxiaoming
* Date: 2019/12/10
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ConnectionPoolMXBean implements Serializable {
private static final long serialVersionUID = -8774671998907063174L;
private String name;
private int idleConnections;
private int activeConnections;
private int totalConnections;
private int threadsAwaitingConnection;
}
16 changes: 16 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/DataSourceConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.rx.jdbc;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class DataSourceConfig implements Serializable {
private static final long serialVersionUID = 8722778295417630020L;
String jdbcUrl;
String username, password;
}
45 changes: 45 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/DriverClassFlag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.rx.jdbc;

import lombok.Getter;
import org.rx.bean.NEnum;
import org.rx.core.Arrays;
import org.rx.core.Linq;
import org.rx.core.Strings;
import org.rx.exception.InvalidException;

import java.util.Collections;
import java.util.List;

/**
* Created by IntelliJ IDEA.
*
* @author wangxiaoming
* Date: 2019/9/2
*/
@Getter
public enum DriverClassFlag implements NEnum<DriverClassFlag> {
MySQL(1, "com.mysql.jdbc.Driver", "jdbc:mysql:"),
PostgreSQL(2, "org.postgresql.Driver", "jdbc:postgresql:"),
Oracle(3, "oracle.jdbc.driver.OracleDriver", "jdbc:oracle:"),
SQLServer(4, "com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver:", "jdbc:microsoft:sqlserver:"),
H2(5, "org.h2.Driver", "jdbc:h2:"),
MongoDB(6, "com.xdbc.jdbc.mongodb.MongoDriver", "jdbc:mongodb:");

private final int value;
private final String driverClassName;
private final List<String> urlPrefixes;

DriverClassFlag(int value, String driverClassName, String... urlPrefixes) {
this.value = value;
this.driverClassName = driverClassName;
this.urlPrefixes = Collections.unmodifiableList(Arrays.toList(urlPrefixes));
}

public static DriverClassFlag recognize(String jdbcUrl) {
DriverClassFlag flag = Linq.from(DriverClassFlag.values()).firstOrDefault(p -> Linq.from(p.urlPrefixes).any(x -> Strings.startsWithIgnoreCase(jdbcUrl, x)));
if (flag == null) {
throw new InvalidException("Recognize url {} fail", jdbcUrl);
}
return flag;
}
}
69 changes: 69 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/JdbcConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.rx.jdbc;

import lombok.*;
import org.rx.net.Sockets;

import java.net.InetSocketAddress;

@Data
@EqualsAndHashCode(callSuper = true)
public class JdbcConfig extends DataSourceConfig {
private static final long serialVersionUID = 2890340670027176789L;

private long connectionTimeoutMillis = 30000;
private long idleTimeoutMillis = 60000;
private long maxLifetimeMillis = 1800000;
private int minPoolSize = 10;
private int maxPoolSize = 10;
private ConnectionPoolKind poolKind = ConnectionPoolKind.HikariCP;

private String poolName;
private boolean enableStreamingResults;
private long executeTimeoutMillis = 30000;
private boolean interruptTimeoutExecution = false;

@Getter(AccessLevel.PRIVATE)
@Setter(AccessLevel.PRIVATE)
private InetSocketAddress endpoint;
@Getter(AccessLevel.PRIVATE)
@Setter(AccessLevel.PRIVATE)
private String databaseName;

public void setUrl(String url) {
jdbcUrl = url;
endpoint = null;
databaseName = null;
}

public InetSocketAddress getEndpointFromUrl() {
if (endpoint == null) {
endpoint = getEndpointFromUrl(jdbcUrl);
}
return endpoint;
}

public String getDatabaseNameFromUrl() {
if (databaseName == null) {
databaseName = getDatabaseNameFromUrl(jdbcUrl);
}
return databaseName;
}

public static InetSocketAddress getEndpointFromUrl(String url) {
return Sockets.parseEndpoint(findChars(url, "://", "/", 0));
}

public static String getDatabaseNameFromUrl(String url) {
return findChars(url, "/", "?", url.indexOf("://") + 3);
}

private static String findChars(String url, String begin, String end, int startIndex) {
int s = url.indexOf(begin, startIndex);
if (s == -1) {
// throw new InvalidOperationException("begin flag not found");
return null;
}
int offset = s + begin.length(), e = url.indexOf(end, offset);
return e == -1 ? url.substring(offset) : url.substring(offset, e);
}
}
50 changes: 50 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.rx.jdbc;

import lombok.NonNull;
import org.rx.bean.$;
import org.rx.util.function.BiFunc;

import java.sql.ResultSet;
import java.util.List;

public interface JdbcExecutable {
ResultSet executeQuery(String sql, Object[] params);

ResultSet executeQuery(String sql, Object[] params, long executeTimeoutMillis);

<T> T executeQuery(String sql, Object[] params, BiFunc<ResultSet, T> func);

<T> T executeQuery(String sql, Object[] params, BiFunc<ResultSet, T> func, long executeTimeoutMillis);

int execute(String sql, Object[] params);

int execute(String sql, Object[] params, long executeTimeoutMillis);

int execute(String sql, Object[] params, int generatedKeys, $<Long> lastInsertId);

int execute(String sql, Object[] params, long executeTimeoutMillis, int generatedKeys, $<Long> lastInsertId);

int[] executeBatch(String sql, List<Object[]> batchParams);

int[] executeBatch(String sql, @NonNull List<Object[]> batchParams, long executeTimeoutMillis);

ResultSet executeQuery(String sql);

ResultSet executeQuery(String sql, long executeTimeoutMillis);

<T> T executeQuery(String sql, BiFunc<ResultSet, T> func);

<T> T executeQuery(String sql, BiFunc<ResultSet, T> func, long executeTimeoutMillis);

int execute(String sql);

int execute(String sql, long executeTimeoutMillis);

int execute(String sql, int generatedKeys, $<Long> lastInsertId);

int execute(String sql, long executeTimeoutMillis, int generatedKeys, $<Long> lastInsertId);

int[] executeBatch(List<String> batchSql);

int[] executeBatch(@NonNull List<String> batchSql, long executeTimeoutMillis);
}
Loading

0 comments on commit e9a2c00

Please sign in to comment.