17
17
18
18
package org .apache .shardingsphere .distsql .handler .executor .rql .resource ;
19
19
20
+ import com .sphereex .dbplusengine .SphereEx ;
21
+ import com .sphereex .dbplusengine .SphereEx .Type ;
22
+ import com .zaxxer .hikari .HikariDataSource ;
20
23
import lombok .Setter ;
21
24
import org .apache .shardingsphere .distsql .handler .aware .DistSQLExecutorDatabaseAware ;
22
25
import org .apache .shardingsphere .distsql .handler .engine .query .DistSQLQueryExecutor ;
23
26
import org .apache .shardingsphere .distsql .statement .rql .resource .ShowStorageUnitsStatement ;
24
27
import org .apache .shardingsphere .infra .database .core .connector .ConnectionProperties ;
25
- import org .apache .shardingsphere .infra .database .core .type .DatabaseTypeRegistry ;
26
28
import org .apache .shardingsphere .infra .datasource .pool .CatalogSwitchableDataSource ;
27
29
import org .apache .shardingsphere .infra .datasource .pool .props .creator .DataSourcePoolPropertiesCreator ;
28
30
import org .apache .shardingsphere .infra .datasource .pool .props .domain .DataSourcePoolProperties ;
@@ -51,26 +53,36 @@ public final class ShowStorageUnitExecutor implements DistSQLQueryExecutor<ShowS
51
53
52
54
private ShardingSphereDatabase database ;
53
55
56
+ @ SphereEx (Type .MODIFY )
54
57
@ Override
55
58
public Collection <String > getColumnNames (final ShowStorageUnitsStatement sqlStatement ) {
56
59
return Arrays .asList ("name" , "type" , "host" , "port" , "db" , "connection_timeout_milliseconds" , "idle_timeout_milliseconds" ,
57
- "max_lifetime_milliseconds" , "max_pool_size" , "min_pool_size" , "read_only" , "other_attributes" );
60
+ "max_lifetime_milliseconds" , "max_pool_size" , "min_pool_size" , "read_only" , "other_attributes" , "username" , "pool_name" , "actual_jdbc_url" );
58
61
}
59
62
63
+ @ SphereEx (Type .MODIFY )
60
64
@ Override
61
65
public Collection <LocalDataQueryResultRow > getRows (final ShowStorageUnitsStatement sqlStatement , final ContextManager contextManager ) {
62
66
return getStorageUnits (sqlStatement ).entrySet ().stream ().map (entry -> getRow (entry .getKey (), entry .getValue ())).collect (Collectors .toList ());
63
67
}
64
68
69
+ @ SphereEx (Type .MODIFY )
65
70
private LocalDataQueryResultRow getRow (final String name , final StorageUnit storageUnit ) {
66
71
ConnectionProperties connectionProps = storageUnit .getConnectionProperties ();
67
- DataSourcePoolProperties dataSourcePoolProps = getDataSourcePoolProperties (storageUnit );
72
+ DataSource actualDataSource = getActualDataSource (storageUnit .getDataSource ());
73
+ DataSourcePoolProperties dataSourcePoolProps = getDataSourcePoolProperties (actualDataSource );
68
74
Map <String , Object > poolProps = dataSourcePoolProps .getPoolPropertySynonyms ().getStandardProperties ();
69
75
Map <String , Object > customProps = getCustomProperties (dataSourcePoolProps .getCustomProperties ().getProperties (), connectionProps .getQueryProperties ());
70
76
return new LocalDataQueryResultRow (name , storageUnit .getStorageType ().getType (), connectionProps .getHostname (), connectionProps .getPort (), connectionProps .getCatalog (),
71
- getStandardProperty (poolProps , "connectionTimeoutMilliseconds" ), getStandardProperty (poolProps , "idleTimeoutMilliseconds" ),
72
- getStandardProperty (poolProps , "maxLifetimeMilliseconds" ), getStandardProperty (poolProps , "maxPoolSize" ), getStandardProperty (poolProps , "minPoolSize" ),
73
- getStandardProperty (poolProps , "readOnly" ), customProps );
77
+ getStandardProperty (poolProps , "connectionTimeoutMilliseconds" ),
78
+ getStandardProperty (poolProps , "idleTimeoutMilliseconds" ),
79
+ getStandardProperty (poolProps , "maxLifetimeMilliseconds" ),
80
+ getStandardProperty (poolProps , "maxPoolSize" ),
81
+ getStandardProperty (poolProps , "minPoolSize" ),
82
+ getStandardProperty (poolProps , "readOnly" ),
83
+ customProps ,
84
+ getUsername (actualDataSource , dataSourcePoolProps .getAllStandardProperties ()),
85
+ getPoolName (actualDataSource ), getActualURL (actualDataSource ));
74
86
}
75
87
76
88
private Map <String , StorageUnit > getStorageUnits (final ShowStorageUnitsStatement sqlStatement ) {
@@ -82,18 +94,9 @@ private Optional<Pattern> getLikePattern(final ShowStorageUnitsStatement sqlStat
82
94
return sqlStatement .getLikePattern ().map (optional -> Pattern .compile (RegexUtils .convertLikePatternToRegex (optional ), Pattern .CASE_INSENSITIVE ));
83
95
}
84
96
85
- private DataSourcePoolProperties getDataSourcePoolProperties (final StorageUnit storageUnit ) {
86
- DataSource dataSource = storageUnit .getDataSource ();
87
- DataSourcePoolProperties result = DataSourcePoolPropertiesCreator .create (
88
- dataSource instanceof CatalogSwitchableDataSource ? ((CatalogSwitchableDataSource ) dataSource ).getDataSource () : dataSource );
89
- if (new DatabaseTypeRegistry (storageUnit .getStorageType ()).getDialectDatabaseMetaData ().isInstanceConnectionAvailable ()) {
90
- for (Entry <String , Object > entry : storageUnit .getDataSourcePoolProperties ().getPoolPropertySynonyms ().getStandardProperties ().entrySet ()) {
91
- if (null != entry .getValue ()) {
92
- result .getPoolPropertySynonyms ().getStandardProperties ().put (entry .getKey (), entry .getValue ());
93
- }
94
- }
95
- }
96
- return result ;
97
+ @ SphereEx (Type .MODIFY )
98
+ private DataSourcePoolProperties getDataSourcePoolProperties (final DataSource actualDataSource ) {
99
+ return DataSourcePoolPropertiesCreator .create (actualDataSource );
97
100
}
98
101
99
102
private Map <String , Object > getCustomProperties (final Map <String , Object > customProps , final Properties queryProps ) {
@@ -109,6 +112,35 @@ private String getStandardProperty(final Map<String, Object> standardProps, fina
109
112
return standardProps .containsKey (key ) && null != standardProps .get (key ) ? standardProps .get (key ).toString () : "" ;
110
113
}
111
114
115
+ @ SphereEx
116
+ private DataSource getActualDataSource (final DataSource dataSource ) {
117
+ return dataSource instanceof CatalogSwitchableDataSource ? ((CatalogSwitchableDataSource ) dataSource ).getDataSource () : dataSource ;
118
+ }
119
+
120
+ @ SphereEx
121
+ private String getUsername (final DataSource actualDataSource , final Map <String , Object > standardProps ) {
122
+ if (actualDataSource instanceof HikariDataSource ) {
123
+ return ((HikariDataSource ) actualDataSource ).getUsername ();
124
+ }
125
+ return getStandardProperty (standardProps , "username" );
126
+ }
127
+
128
+ @ SphereEx
129
+ private String getPoolName (final DataSource actualDataSource ) {
130
+ if (actualDataSource instanceof HikariDataSource ) {
131
+ return ((HikariDataSource ) actualDataSource ).getPoolName ();
132
+ }
133
+ return "" ;
134
+ }
135
+
136
+ @ SphereEx
137
+ private String getActualURL (final DataSource actualDataSource ) {
138
+ if (actualDataSource instanceof HikariDataSource ) {
139
+ return ((HikariDataSource ) actualDataSource ).getJdbcUrl ();
140
+ }
141
+ return "" ;
142
+ }
143
+
112
144
@ Override
113
145
public Class <ShowStorageUnitsStatement > getType () {
114
146
return ShowStorageUnitsStatement .class ;
0 commit comments