@@ -143,7 +143,9 @@ public DataSourceConfig copy() {
143143 copy .clientInfo = new Properties ();
144144 copy .clientInfo .putAll (clientInfo );
145145 }
146- copy .initSql = initSql ;
146+ if (initSql != null ) {
147+ copy .initSql = new ArrayList <>(initSql );
148+ }
147149 copy .alert = alert ;
148150 copy .listener = listener ;
149151 copy .enforceCleanClose = enforceCleanClose ;
@@ -194,10 +196,23 @@ public DataSourceConfig setDefaults(DataSourceBuilder builder) {
194196 }
195197 if (customProperties == null ) {
196198 var otherCustomProps = other .getCustomProperties ();
197- if (otherCustomProps != null ) {
199+ if (otherCustomProps != null && ! otherCustomProps . isEmpty () ) {
198200 customProperties = new LinkedHashMap <>(otherCustomProps );
199201 }
200202 }
203+ if (clientInfo == null ) {
204+ var otherClientInfo = other .getClientInfo ();
205+ if (otherClientInfo != null && !otherClientInfo .isEmpty ()) {
206+ clientInfo = new Properties ();
207+ clientInfo .putAll (otherClientInfo );
208+ }
209+ }
210+ if (initSql == null ) {
211+ var otherInitSql = other .getInitSql ();
212+ if (otherInitSql != null && !otherInitSql .isEmpty ()) {
213+ initSql = new ArrayList <>(otherInitSql );
214+ }
215+ }
201216 return this ;
202217 }
203218
@@ -809,49 +824,58 @@ private void loadSettings(ConfigPropertiesHelper properties) {
809824
810825 String isoLevel = properties .get ("isolationLevel" , _isolationLevel (isolationLevel ));
811826 this .isolationLevel = _isolationLevel (isoLevel );
812- this .initSql = parseSql (properties .get ("initSql" , null ));
827+ String sql = properties .get ("initSql" , null );
828+ if (sql != null && !sql .isEmpty ()) {
829+ if (this .initSql == null ) {
830+ this .initSql = new ArrayList <>();
831+ }
832+ parseSql (sql , this .initSql );
833+ }
813834 this .failOnStart = properties .getBoolean ("failOnStart" , failOnStart );
814835
815836 String customProperties = properties .get ("customProperties" , null );
816837 if (customProperties != null && !customProperties .isEmpty ()) {
817- this .customProperties = parseCustom (customProperties );
838+ if (this .customProperties == null ) {
839+ this .customProperties = new LinkedHashMap <>();
840+ }
841+ parseCustom (customProperties , this .customProperties );
818842 }
819843 String infoProperties = properties .get ("clientInfo" , null );
820844 if (infoProperties != null && !infoProperties .isEmpty ()) {
821- Map <String , String > pairs = parseCustom (infoProperties );
822- if (!pairs .isEmpty ()) {
845+ if (this .clientInfo == null ) {
823846 this .clientInfo = new Properties ();
824- for (Map .Entry <String , String > entry : pairs .entrySet ()) {
825- this .clientInfo .setProperty (entry .getKey (), entry .getValue ());
826- }
827847 }
848+ parseCustom (infoProperties , this .clientInfo );
828849 }
829850 }
830851
831- private List <String > parseSql (String sql ) {
832- List <String > ret = new ArrayList <>();
852+ void parseSql (String sql , List <String > target ) {
833853 if (sql != null ) {
834- String [] queries = sql .split (";" );
854+ String splitter = ";" ;
855+ if (sql .toLowerCase ().startsWith ("delimiter $$" )) {
856+ sql = sql .substring ("delimiter $$" .length ());
857+ splitter = "\\ $\\ $" ;
858+ }
859+ String [] queries = sql .split (splitter );
835860 for (String query : queries ) {
836861 query = query .trim ();
837862 if (!query .isEmpty ()) {
838- ret .add (query );
863+ target .add (query );
839864 }
840865 }
841866 }
842- return ret ;
843867 }
844868
845- Map <String , String > parseCustom (String customProperties ) {
846- Map <String , String > propertyMap = new LinkedHashMap <>();
869+ @ SuppressWarnings ("unchecked" )
870+ // we use raw map type here, so that we can also accept Properties as target
871+ void parseCustom (String customProperties , Map target ) {
847872 String [] pairs = customProperties .split (";" );
848873 for (String pair : pairs ) {
849874 String [] split = pair .split ("=" );
850875 if (split .length == 2 ) {
851- propertyMap .put (split [0 ], split [1 ]);
876+ target .put (split [0 ], split [1 ]);
852877 }
853878 }
854- return propertyMap ;
855879 }
856880
857881 @ Override
0 commit comments