├── .gitignore ├── LICENSE ├── README.md ├── docs ├── allclasses-frame.html ├── allclasses-noframe.html ├── com │ └── glyart │ │ └── mystral │ │ ├── data │ │ ├── ClassMapper.html │ │ ├── Converter.html │ │ ├── DataUtils.html │ │ ├── MapWith.html │ │ ├── Name.html │ │ ├── Skip.html │ │ ├── class-use │ │ │ ├── ClassMapper.html │ │ │ ├── Converter.html │ │ │ ├── DataUtils.html │ │ │ ├── MapWith.html │ │ │ ├── Name.html │ │ │ └── Skip.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ ├── package-use.html │ │ └── support │ │ │ ├── StringToUUID.html │ │ │ ├── class-use │ │ │ └── StringToUUID.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ ├── database │ │ ├── AsyncDatabase.html │ │ ├── Credentials.CredentialsBuilder.html │ │ ├── Credentials.html │ │ ├── Database.html │ │ ├── DatabaseAccessor.html │ │ ├── Mystral.html │ │ ├── PreparedStatementUtils.html │ │ ├── class-use │ │ │ ├── AsyncDatabase.html │ │ │ ├── Credentials.CredentialsBuilder.html │ │ │ ├── Credentials.html │ │ │ ├── Database.html │ │ │ ├── DatabaseAccessor.html │ │ │ ├── Mystral.html │ │ │ └── PreparedStatementUtils.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ ├── datasource │ │ ├── DataSourceFactory.html │ │ ├── DataSourceSupplier.html │ │ ├── DataSourceUtils.html │ │ ├── HikariFactory.html │ │ ├── class-use │ │ │ ├── DataSourceFactory.html │ │ │ ├── DataSourceSupplier.html │ │ │ ├── DataSourceUtils.html │ │ │ └── HikariFactory.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ ├── exceptions │ │ ├── ConnectionRetrieveException.html │ │ ├── ConversionException.html │ │ ├── DataAccessException.html │ │ ├── DataSourceInitException.html │ │ ├── IncorrectDataSizeException.html │ │ ├── TypeMismatchException.html │ │ ├── class-use │ │ │ ├── ConnectionRetrieveException.html │ │ │ ├── ConversionException.html │ │ │ ├── DataAccessException.html │ │ │ ├── DataSourceInitException.html │ │ │ ├── IncorrectDataSizeException.html │ │ │ └── TypeMismatchException.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ └── sql │ │ ├── AsyncDataOperations.html │ │ ├── BatchSetter.html │ │ ├── DataOperations.html │ │ ├── ParametrizedBatchSetter.html │ │ ├── PreparedStatementCreator.html │ │ ├── PreparedStatementFunction.html │ │ ├── PreparedStatementSetter.html │ │ ├── ResultSetExtractor.html │ │ ├── ResultSetRowMapper.html │ │ ├── SqlProvider.html │ │ ├── StatementFunction.html │ │ ├── class-use │ │ ├── AsyncDataOperations.html │ │ ├── BatchSetter.html │ │ ├── DataOperations.html │ │ ├── ParametrizedBatchSetter.html │ │ ├── PreparedStatementCreator.html │ │ ├── PreparedStatementFunction.html │ │ ├── PreparedStatementSetter.html │ │ ├── ResultSetExtractor.html │ │ ├── ResultSetRowMapper.html │ │ ├── SqlProvider.html │ │ └── StatementFunction.html │ │ ├── impl │ │ ├── DefaultBatchSetter.html │ │ ├── DefaultCreator.html │ │ ├── DefaultExtractor.html │ │ ├── DefaultSetter.html │ │ ├── DefaultSetterUnknownType.html │ │ ├── QueryStatementFunction.html │ │ ├── SimpleUpdateStatementFunction.html │ │ ├── class-use │ │ │ ├── DefaultBatchSetter.html │ │ │ ├── DefaultCreator.html │ │ │ ├── DefaultExtractor.html │ │ │ ├── DefaultSetter.html │ │ │ ├── DefaultSetterUnknownType.html │ │ │ ├── QueryStatementFunction.html │ │ │ └── SimpleUpdateStatementFunction.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-all.html ├── index.html ├── overview-frame.html ├── overview-summary.html ├── overview-tree.html ├── package-list ├── script.js ├── serialized-form.html └── stylesheet.css ├── pom.xml └── src └── main └── java └── com └── glyart └── mystral ├── data ├── ClassMapper.java ├── Converter.java ├── DataUtils.java ├── MapWith.java ├── Name.java ├── Skip.java ├── package-info.java └── support │ ├── StringToUUID.java │ └── package-info.java ├── database ├── AsyncDatabase.java ├── Credentials.java ├── Database.java ├── DatabaseAccessor.java ├── Mystral.java ├── PreparedStatementUtils.java └── package-info.java ├── datasource ├── DataSourceFactory.java ├── DataSourceSupplier.java ├── DataSourceUtils.java ├── HikariFactory.java └── package-info.java ├── exceptions ├── ConnectionRetrieveException.java ├── ConversionException.java ├── DataAccessException.java ├── DataSourceInitException.java ├── IncorrectDataSizeException.java ├── TypeMismatchException.java └── package-info.java └── sql ├── AsyncDataOperations.java ├── BatchSetter.java ├── DataOperations.java ├── ParametrizedBatchSetter.java ├── PreparedStatementCreator.java ├── PreparedStatementFunction.java ├── PreparedStatementSetter.java ├── ResultSetExtractor.java ├── ResultSetRowMapper.java ├── SqlProvider.java ├── StatementFunction.java ├── impl ├── DefaultBatchSetter.java ├── DefaultCreator.java ├── DefaultExtractor.java ├── DefaultSetter.java ├── DefaultSetterUnknownType.java ├── QueryStatementFunction.java ├── SimpleUpdateStatementFunction.java └── package-info.java └── package-info.java /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | 11 | # Compiled class file 12 | *.class 13 | 14 | # Log file 15 | *.log 16 | 17 | # BlueJ files 18 | *.ctxt 19 | 20 | # Package Files # 21 | *.jar 22 | *.war 23 | *.nar 24 | *.ear 25 | *.zip 26 | *.tar.gz 27 | *.rar 28 | 29 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 30 | hs_err_pid* 31 | 32 | *~ 33 | 34 | # temporary files which can be created if a process still has a handle open of a deleted file 35 | .fuse_hidden* 36 | 37 | # KDE directory preferences 38 | .directory 39 | 40 | # Linux trash folder which might appear on any partition or disk 41 | .Trash-* 42 | 43 | # .nfs files are created when an open file is removed but is still being accessed 44 | .nfs* 45 | 46 | # General 47 | .DS_Store 48 | .AppleDouble 49 | .LSOverride 50 | 51 | # Icon must end with two \r 52 | Icon 53 | 54 | # Thumbnails 55 | ._* 56 | 57 | # Files that might appear in the root of a volume 58 | .DocumentRevisions-V100 59 | .fseventsd 60 | .Spotlight-V100 61 | .TemporaryItems 62 | .Trashes 63 | .VolumeIcon.icns 64 | .com.apple.timemachine.donotpresent 65 | 66 | # Directories potentially created on remote AFP share 67 | .AppleDB 68 | .AppleDesktop 69 | Network Trash Folder 70 | Temporary Items 71 | .apdisk 72 | 73 | # Windows thumbnail cache files 74 | Thumbs.db 75 | Thumbs.db:encryptable 76 | ehthumbs.db 77 | ehthumbs_vista.db 78 | 79 | # Dump file 80 | *.stackdump 81 | 82 | # Folder config file 83 | [Dd]esktop.ini 84 | 85 | # Recycle Bin used on file shares 86 | $RECYCLE.BIN/ 87 | 88 | # Windows Installer files 89 | *.cab 90 | *.msi 91 | *.msix 92 | *.msm 93 | *.msp 94 | 95 | # Windows shortcuts 96 | *.lnk 97 | 98 | target/ 99 | 100 | pom.xml.tag 101 | pom.xml.releaseBackup 102 | pom.xml.versionsBackup 103 | pom.xml.next 104 | 105 | release.properties 106 | dependency-reduced-pom.xml 107 | buildNumber.properties 108 | .mvn/timing.properties 109 | .mvn/wrapper/maven-wrapper.jar 110 | .flattened-pom.xml 111 | 112 | # Common working directory 113 | run/ 114 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 David D'Amico and Glyart di Coletta Pierpaolo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mystral [![](https://jitpack.io/v/Glyart/Mystral.svg)](https://jitpack.io/#Glyart/Mystral) 2 | 3 | 4 | An efficient library to deal with relational databases quickly. 5 | 6 | A little request: read the [Javadoc](https://glyart.github.io/Mystral/) to understand how these elements work in deep. 7 | Wiki: [click here](https://github.com/Glyart/Mystral/wiki). 8 | -------------------------------------------------------------------------------- /docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

All Classes

14 |
15 | 59 |
60 | 61 | 62 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/class-use/DataUtils.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.data.DataUtils (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.data.DataUtils

75 |
76 |
No usage of com.glyart.mystral.data.DataUtils
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/class-use/Name.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.data.Name (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.data.Name

75 |
76 |
No usage of com.glyart.mystral.data.Name
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/class-use/Skip.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.data.Skip (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.data.Skip

75 |
76 |
No usage of com.glyart.mystral.data.Skip
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.data (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

com.glyart.mystral.data

14 |
15 |

Interfaces

16 | 19 |

Classes

20 | 24 |

Annotation Types

25 | 30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/class-use/StringToUUID.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.data.support.StringToUUID (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.data.support.StringToUUID

75 |
76 |
No usage of com.glyart.mystral.data.support.StringToUUID
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.data.support (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

com.glyart.mystral.data.support

14 |
15 |

Classes

16 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.data.support (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Package com.glyart.mystral.data.support

75 |
76 |
Contains implementations for fast type conversions.
77 |
78 |

See: Description

79 |
80 |
81 | 100 | 101 | 102 | 103 |

Package com.glyart.mystral.data.support Description

104 |
Contains implementations for fast type conversions. 105 | You can suggest your own implementations via pull request.
106 |
107 | 108 |
109 | 110 | 111 |
Skip navigation links
112 | 113 | 114 | 115 | 125 |
126 | 153 | 154 |

Copyright © 2021. All rights reserved.

155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.data.support Class Hierarchy (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Hierarchy For Package com.glyart.mystral.data.support

75 | Package Hierarchies: 76 | 79 |
80 |
81 |

Class Hierarchy

82 | 89 |
90 | 91 |
92 | 93 | 94 |
Skip navigation links
95 | 96 | 97 | 98 | 108 |
109 | 136 | 137 |

Copyright © 2021. All rights reserved.

138 | 139 | 140 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Package com.glyart.mystral.data.support (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Package
com.glyart.mystral.data.support

75 |
76 |
No usage of com.glyart.mystral.data.support
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/database/class-use/Mystral.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.database.Mystral (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.database.Mystral

75 |
76 |
No usage of com.glyart.mystral.database.Mystral
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/database/class-use/PreparedStatementUtils.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.database.PreparedStatementUtils (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.database.PreparedStatementUtils

75 |
76 |
No usage of com.glyart.mystral.database.PreparedStatementUtils
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/database/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.database (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

com.glyart.mystral.database

14 |
15 |

Classes

16 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/datasource/class-use/DataSourceUtils.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.datasource.DataSourceUtils (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.datasource.DataSourceUtils

75 |
76 |
No usage of com.glyart.mystral.datasource.DataSourceUtils
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/datasource/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.datasource (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

com.glyart.mystral.datasource

14 |
15 |

Interfaces

16 | 20 |

Classes

21 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/datasource/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.datasource Class Hierarchy (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Hierarchy For Package com.glyart.mystral.datasource

75 | Package Hierarchies: 76 | 79 |
80 |
81 |

Class Hierarchy

82 | 90 |

Interface Hierarchy

91 | 99 |
100 | 101 |
102 | 103 | 104 |
Skip navigation links
105 | 106 | 107 | 108 | 118 |
119 | 146 | 147 |

Copyright © 2021. All rights reserved.

148 | 149 | 150 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/exceptions/class-use/ConnectionRetrieveException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.exceptions.ConnectionRetrieveException (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.exceptions.ConnectionRetrieveException

75 |
76 |
No usage of com.glyart.mystral.exceptions.ConnectionRetrieveException
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/exceptions/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.exceptions (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

com.glyart.mystral.exceptions

14 |
15 |

Exceptions

16 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/class-use/DefaultBatchSetter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.sql.impl.DefaultBatchSetter (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.sql.impl.DefaultBatchSetter

75 |
76 |
No usage of com.glyart.mystral.sql.impl.DefaultBatchSetter
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/class-use/DefaultCreator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.sql.impl.DefaultCreator (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.sql.impl.DefaultCreator

75 |
76 |
No usage of com.glyart.mystral.sql.impl.DefaultCreator
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/class-use/DefaultExtractor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.sql.impl.DefaultExtractor (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.sql.impl.DefaultExtractor

75 |
76 |
No usage of com.glyart.mystral.sql.impl.DefaultExtractor
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/class-use/DefaultSetter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.sql.impl.DefaultSetter (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.sql.impl.DefaultSetter

75 |
76 |
No usage of com.glyart.mystral.sql.impl.DefaultSetter
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/class-use/DefaultSetterUnknownType.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.sql.impl.DefaultSetterUnknownType (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.sql.impl.DefaultSetterUnknownType

75 |
76 |
No usage of com.glyart.mystral.sql.impl.DefaultSetterUnknownType
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/class-use/QueryStatementFunction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.sql.impl.QueryStatementFunction (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.sql.impl.QueryStatementFunction

75 |
76 |
No usage of com.glyart.mystral.sql.impl.QueryStatementFunction
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/class-use/SimpleUpdateStatementFunction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.glyart.mystral.sql.impl.SimpleUpdateStatementFunction (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
com.glyart.mystral.sql.impl.SimpleUpdateStatementFunction

75 |
76 |
No usage of com.glyart.mystral.sql.impl.SimpleUpdateStatementFunction
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.sql.impl (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

com.glyart.mystral.sql.impl

14 |
15 |

Classes

16 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Package com.glyart.mystral.sql.impl (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Package
com.glyart.mystral.sql.impl

75 |
76 |
No usage of com.glyart.mystral.sql.impl
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.glyart.mystral.sql (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |

com.glyart.mystral.sql

14 |
15 |

Interfaces

16 | 29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Constant Field Values (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Constant Field Values

75 |

Contents

76 | 79 |
80 |
81 | 82 | 83 |

com.glyart.*

84 | 105 |
106 | 107 |
108 | 109 | 110 |
Skip navigation links
111 | 112 | 113 | 114 | 124 |
125 | 152 | 153 |

Copyright © 2021. All rights reserved.

154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Deprecated API

75 |

Contents

76 |
77 | 78 |
79 | 80 | 81 |
Skip navigation links
82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Mystral 1.4.5-SNAPSHOT API 8 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | <noscript> 70 | <div>JavaScript is disabled on your browser.</div> 71 | </noscript> 72 | <h2>Frame Alert</h2> 73 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /docs/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview List (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 |
All Classes
14 |
15 |

Packages

16 | 25 |
26 |

 

27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/overview-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview (Mystral 1.4.5-SNAPSHOT API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 |
Skip navigation links
31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Mystral 1.4.5-SNAPSHOT API

75 |
76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 91 | 92 | 95 | 96 | 97 | 98 | 101 | 102 | 103 | 104 | 107 | 108 | 109 | 110 | 113 | 114 | 115 | 116 | 119 | 120 | 121 | 122 | 125 | 126 | 127 |
Packages 
PackageDescription
com.glyart.mystral.data 87 |
Contains classes for: auto object mappings, better data management and type conversions.
88 |
com.glyart.mystral.data.support 93 |
Contains implementations for fast type conversions.
94 |
com.glyart.mystral.database 99 |
Contains the implementations of the main functionalities of this library.
100 |
com.glyart.mystral.datasource 105 |
Contains some utilities for managing DataSource objects.
106 |
com.glyart.mystral.exceptions 111 |
Contains exceptions thrown by this library.
112 |
com.glyart.mystral.sql 117 |
Contains interfaces used by DataOperations and AsyncDataOperations implementations.
118 |
com.glyart.mystral.sql.impl 123 |
Contains basic implementations of the com.glyart.mystral.sql package.
124 |
128 |
129 | 130 |
131 | 132 | 133 |
Skip navigation links
134 | 135 | 136 | 137 | 147 |
148 | 175 | 176 |

Copyright © 2021. All rights reserved.

177 | 178 | 179 | -------------------------------------------------------------------------------- /docs/package-list: -------------------------------------------------------------------------------- 1 | com.glyart.mystral.data 2 | com.glyart.mystral.data.support 3 | com.glyart.mystral.database 4 | com.glyart.mystral.datasource 5 | com.glyart.mystral.exceptions 6 | com.glyart.mystral.sql 7 | com.glyart.mystral.sql.impl 8 | -------------------------------------------------------------------------------- /docs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.glyart 8 | Mystral 9 | 1.4.5-SNAPSHOT 10 | 11 | Mystral 12 | 13 | Library that helps you avoiding JDBC code boilerplate. 14 | 15 | 16 | 17 | xQuickGlare 18 | 19 | GigaChad Developer 20 | 21 | 22 | 23 | Aerora 24 | 25 | Developer 26 | 27 | 28 | 29 | 30 | 31 | UTF-8 32 | 8 33 | ${java.version} 34 | ${java.version} 35 | ${encoding} 36 | ${encoding} 37 | 38 | 39 | 40 | ${project.name}-${project.version} 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 3.8.1 46 | 47 | ${java.version} 48 | ${java.version} 49 | 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-shade-plugin 55 | 3.2.4 56 | 57 | 58 | package 59 | 60 | shade 61 | 62 | 63 | false 64 | 65 | 66 | *:* 67 | 68 | META-INF/MANIFEST.MF 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-javadoc-plugin 80 | 3.2.0 81 | 82 | ${project.basedir} 83 | docs 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | org.jetbrains 92 | annotations 93 | 22.0.0 94 | compile 95 | 96 | 97 | 98 | com.google.guava 99 | guava 100 | 31.0.1-jre 101 | compile 102 | 103 | 104 | 105 | com.zaxxer 106 | HikariCP 107 | 4.0.3 108 | compile 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/Converter.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.data; 2 | 3 | import com.glyart.mystral.exceptions.ConversionException; 4 | 5 | import java.util.function.Function; 6 | 7 | /** 8 | * Represents a contract for data conversions. 9 | * Some types cannot be represented with SQL types (e.g. UUIDs. You can convert varchar to UUID, starting from their Java String representation). 10 | * With this interface, ClassMapper can invoke the setter methods of the objects to map, passing the correct values after they have been converted. 11 | * @param the type to convert 12 | * @param the desired type 13 | * @see com.glyart.mystral.data.support.StringToUUID 14 | */ 15 | @FunctionalInterface 16 | public interface Converter extends Function { 17 | 18 | /** 19 | * Applies the conversion to the given value, transforming the object in a new type. 20 | * @param object the value to convert 21 | * @return the new converted type 22 | * @throws ConversionException if something went wrong 23 | */ 24 | @Override 25 | R apply(T object) throws ConversionException; 26 | } -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/DataUtils.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.data; 2 | 3 | import com.glyart.mystral.exceptions.IncorrectDataSizeException; 4 | import org.jetbrains.annotations.Nullable; 5 | 6 | import java.util.Collection; 7 | 8 | public final class DataUtils { 9 | 10 | private DataUtils() {} 11 | 12 | /** 13 | * Return a single result object from the given Collection. 14 | *

Throws an exception if 0 or more than 1 element found. 15 | * @param results the result Collection (can be {@code null} 16 | * and is also expected to contain {@code null} elements) 17 | * @return the single result object 18 | * @throws IncorrectDataSizeException if the given collection doesn't contain exactly 1 element 19 | */ 20 | @Nullable 21 | public static T nullableSingleResult(@Nullable Collection results) throws IncorrectDataSizeException { 22 | if (results == null || results.isEmpty()) { 23 | throw new IncorrectDataSizeException(1, 0); 24 | } 25 | if (results.size() > 1) { 26 | throw new IncorrectDataSizeException(1, results.size()); 27 | } 28 | return results.iterator().next(); 29 | } 30 | 31 | /** 32 | * Return a single result object from the given Collection. 33 | *

Throws an exception if more than 1 element found. 34 | * @param results the result Collection (can be {@code null} 35 | * and is also expected to contain {@code null} elements) 36 | * @return the single (nullable) result object 37 | * @throws IncorrectDataSizeException if the given collection contains more than 1 element 38 | */ 39 | @Nullable 40 | public static T nullableEmptyResult(@Nullable Collection results) { 41 | if (results == null || results.isEmpty()) { 42 | return null; 43 | } 44 | if (results.size() > 1) { 45 | throw new IncorrectDataSizeException(1, results.size()); 46 | } 47 | return results.iterator().next(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/MapWith.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.data; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * This annotation specify what converter should be used before passing a value to a setter method. 12 | * @see Converter 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ElementType.PARAMETER}) 16 | public @interface MapWith { 17 | 18 | /** 19 | * Returns the converter class that will convert some value's type into the desired one. 20 | * @return the converter class 21 | */ 22 | @NotNull 23 | Class> value(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/Name.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.data; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Class fields and column names may differ from names. 12 | * To help mappings, this annotation links class fields which names are different from the table's ones. 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.METHOD) 16 | public @interface Name { 17 | 18 | /** 19 | * Represents the column name to link to the annotated setter. 20 | * @return the column name 21 | */ 22 | @NotNull 23 | String columnName(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/Skip.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.data; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Indicates that the field linked to this setter should be excluded from the automatic mapping. 10 | * A default value, depending on the field type, will be used instead. 11 | *

    12 | *
  • Object: null
  • 13 | *
  • Primitive type: primitive type default value
  • 14 | *
15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target({ElementType.PARAMETER}) 18 | public @interface Skip { } 19 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes for: auto object mappings, better data management and type conversions. 3 | */ 4 | package com.glyart.mystral.data; -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/support/StringToUUID.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.data.support; 2 | 3 | import com.glyart.mystral.data.Converter; 4 | import com.glyart.mystral.exceptions.ConversionException; 5 | import com.google.common.base.Preconditions; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.UUID; 9 | 10 | /** 11 | * A converter which converts string to UUIDs. 12 | */ 13 | public class StringToUUID implements Converter { 14 | 15 | /** 16 | * Converts a string to its UUID representation via {@link UUID#fromString(String)}. 17 | * @param object the string object to convert to UUID 18 | * @return a UUID from the specified string object 19 | * @throws ConversionException if something went wrong while trying to perform the convertion 20 | * @throws IllegalArgumentException if the parameter does not conform to the string representation as described in toString 21 | * @see UUID#fromString(String) 22 | */ 23 | @Override 24 | @NotNull 25 | public UUID apply(@NotNull String object) throws ConversionException, IllegalArgumentException { 26 | try { 27 | return UUID.fromString(Preconditions.checkNotNull(object)); 28 | } catch (IllegalArgumentException e) { 29 | throw new ConversionException(e); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/data/support/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains implementations for fast type conversions. 3 | * You can suggest your own implementations via pull request. 4 | */ 5 | package com.glyart.mystral.data.support; -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/database/Credentials.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.database; 2 | 3 | import com.google.common.base.Preconditions; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.util.concurrent.Executor; 8 | 9 | /** 10 | * Represents the credentials for a connection to a data source that supports connection pooling. 11 | * Multiple different connections can be established by creating other Credentials instances. 12 | */ 13 | public class Credentials { 14 | 15 | @NotNull 16 | private final String hostname; 17 | 18 | private int port; 19 | 20 | @NotNull 21 | private final String username; 22 | 23 | @Nullable 24 | private String password; 25 | 26 | @Nullable 27 | private String schema; 28 | 29 | @Nullable 30 | private String poolName; 31 | 32 | protected Credentials(@NotNull String hostname, @NotNull String username) { 33 | this.hostname = hostname; 34 | this.username = username; 35 | } 36 | /** 37 | * Creates a new builder for Credentials. 38 | * @return the builder 39 | */ 40 | @NotNull 41 | public static CredentialsBuilder builder() { 42 | return new CredentialsBuilder(); 43 | } 44 | 45 | /** 46 | * Gets the hostname for connecting to a data source. 47 | * @return the datasource 48 | */ 49 | @NotNull 50 | public String getHostname() { 51 | return hostname; 52 | } 53 | 54 | /** 55 | * Gets the port for connecting to a data source. 56 | * @return the port 57 | */ 58 | public int getPort() { 59 | return port; 60 | } 61 | 62 | /** 63 | * Gets the username for connecting to a data source. 64 | * @return the username 65 | */ 66 | @NotNull 67 | public String getUsername() { 68 | return username; 69 | } 70 | 71 | /** 72 | * Gets the password for connecting to a data source. 73 | * @return the password 74 | */ 75 | @Nullable 76 | public String getPassword() { 77 | return password; 78 | } 79 | 80 | /** 81 | * Gets the schema for connecting to a data source. 82 | * @return the schema 83 | */ 84 | @Nullable 85 | public String getSchema() { 86 | return schema; 87 | } 88 | 89 | /** 90 | * Gets the name of the connection pool. 91 | * @return the name of the pool 92 | */ 93 | @Nullable 94 | public String getPoolName() { 95 | return poolName; 96 | } 97 | 98 | /** 99 | * Represents a builder for creating {@link Credentials} objects. 100 | */ 101 | public static final class CredentialsBuilder { 102 | 103 | private String hostname; 104 | private int port; 105 | private String username; 106 | private String password; 107 | private String schema; 108 | private String poolName; 109 | 110 | private CredentialsBuilder() { 111 | this.port = 3306; 112 | } 113 | 114 | /** 115 | * Sets the hostname 116 | * @param hostName the hostname 117 | * @return this builder instance 118 | */ 119 | public CredentialsBuilder host(@NotNull String hostName) { 120 | Preconditions.checkArgument(!Preconditions.checkNotNull(hostName, "Hostname cannot be null.").isEmpty(), 121 | "Hostname cannot be empty."); 122 | this.hostname = hostName; 123 | return this; 124 | } 125 | 126 | /** 127 | * Sets the port for connecting to a data source. 128 | * @param port the port of the physical data source 129 | * @return this builder instance 130 | */ 131 | public CredentialsBuilder port(int port) { 132 | this.port = port; 133 | return this; 134 | } 135 | 136 | /** 137 | * Sets the username for connecting to a data source. 138 | * @param username the username 139 | * @return this builder instance 140 | */ 141 | public CredentialsBuilder user(@NotNull String username) { 142 | Preconditions.checkArgument(!Preconditions.checkNotNull(username, "Username cannot be null.").isEmpty(), 143 | "Username cannot be empty."); 144 | this.username = username; 145 | return this; 146 | } 147 | 148 | /** 149 | * Sets the password for connecting to a data source. 150 | * @param password the password 151 | * @return this builder instance 152 | */ 153 | public CredentialsBuilder password(@Nullable String password) { 154 | this.password = password; 155 | return this; 156 | } 157 | 158 | /** 159 | * Sets the initial schema to use after the connection to a data source is successfully established.
160 | * This will not provide the creation of the schema if it doesn't exist. 161 | * @param schema an existing database schema 162 | * @return this builder instance 163 | */ 164 | public CredentialsBuilder schema(@Nullable String schema) { 165 | this.schema = schema; 166 | return this; 167 | } 168 | 169 | /** 170 | * Sets the name of the data source connection pool. 171 | * @param poolName the name of the pool 172 | * @return this builder instance 173 | */ 174 | public CredentialsBuilder pool(@Nullable String poolName) { 175 | this.poolName = poolName; 176 | return this; 177 | } 178 | 179 | /** 180 | * Builds a {@link Credentials} object, ready to be passed to {@link Mystral#newDatabase(Credentials)}.
181 | * If you want async usage you may need {@link Mystral#newAsyncDatabase(Credentials, Executor)}. 182 | * @return a new instance of Credentials. 183 | * @see Mystral 184 | */ 185 | @NotNull 186 | public Credentials build() { 187 | Credentials credentials = new Credentials(hostname, username); 188 | 189 | credentials.port = port; 190 | credentials.password = password; 191 | credentials.schema = schema; 192 | credentials.poolName = poolName; 193 | 194 | return credentials; 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/database/DatabaseAccessor.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.database; 2 | 3 | import com.glyart.mystral.datasource.DataSourceSupplier; 4 | import com.google.common.base.Preconditions; 5 | import org.jetbrains.annotations.NotNull; 6 | import org.slf4j.Logger; 7 | 8 | import javax.sql.DataSource; 9 | 10 | /** 11 | * This class is used as base class for {@link Database} and for common properties. 12 | */ 13 | public abstract class DatabaseAccessor { 14 | 15 | protected final DataSource dataSource; 16 | protected Logger logger; 17 | 18 | protected DatabaseAccessor(@NotNull DataSource dataSource) { 19 | this.dataSource = checkDataSource(dataSource); 20 | } 21 | 22 | protected DatabaseAccessor(@NotNull DataSourceSupplier supplier) { 23 | Preconditions.checkNotNull(supplier, "The DataSourceSupplier cannot be null."); 24 | this.dataSource = checkDataSource(supplier.get()); 25 | } 26 | 27 | /** 28 | * Returns the {@link DataSource} used by {@link DatabaseAccessor}'s subclass. 29 | * @return the DataSource 30 | */ 31 | @NotNull 32 | public DataSource getDataSource() { 33 | return dataSource; 34 | } 35 | 36 | /** 37 | * Sets the logger used by {@link DatabaseAccessor}'s subclasses. 38 | * @param logger the logger 39 | */ 40 | public void setLogger(@NotNull Logger logger) { 41 | Preconditions.checkNotNull(logger, "The logger cannot be null."); 42 | this.logger = logger; 43 | } 44 | 45 | private DataSource checkDataSource(DataSource dataSource) { 46 | Preconditions.checkNotNull(dataSource, "The DataSource cannot be null."); 47 | return dataSource; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/database/Mystral.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.database; 2 | 3 | import com.glyart.mystral.datasource.DataSourceFactory; 4 | import com.glyart.mystral.datasource.DataSourceUtils; 5 | import com.glyart.mystral.exceptions.DataSourceInitException; 6 | import com.google.common.base.Preconditions; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import javax.sql.DataSource; 10 | import java.util.concurrent.Executor; 11 | 12 | /** 13 | * Utility class for fast instantiating {@link Database} and {@link AsyncDatabase} objects. 14 | */ 15 | public final class Mystral { 16 | 17 | private Mystral() {} 18 | 19 | /** 20 | * Creates a new Database with the given Credentials. 21 | * @param credentials the Credentials for creating a connection 22 | * @return the Database 23 | * @throws DataSourceInitException if something went wrong 24 | * @see Database 25 | * @see Credentials 26 | * @see DataSourceFactory#newDataSource() 27 | */ 28 | @NotNull 29 | public static Database newDatabase(@NotNull Credentials credentials) throws DataSourceInitException { 30 | return new Database(DataSourceUtils.newDataSource(credentials)); 31 | } 32 | 33 | /** 34 | * Creates a new Database with the given DataSourceFactory. 35 | * @param factory the factory 36 | * @param the DataSource Type 37 | * @return the Database 38 | * @throws DataSourceInitException if something went wrong 39 | * @see DataSourceFactory 40 | * @see DataSourceFactory#newDataSource() 41 | */ 42 | @NotNull 43 | public static Database newDatabase(@NotNull DataSourceFactory factory) throws DataSourceInitException { 44 | Preconditions.checkNotNull(factory, "The DataSourceFactory cannot be null."); 45 | try { 46 | return new Database(factory.newDataSource()); 47 | } catch (Exception e) { 48 | throw new DataSourceInitException("Cannot create the data source.", e); 49 | } 50 | } 51 | 52 | /** 53 | * Creates a new AsyncDatabase with the given Credentials and an Executor implementation. 54 | * @param credentials the credentials for creating a connection 55 | * @param executor the tasks executor 56 | * @return the AsyncDatabase 57 | * @throws DataSourceInitException if something went wrong 58 | * @see AsyncDatabase 59 | * @see Executor 60 | * @see DataSourceFactory#newDataSource() 61 | */ 62 | @NotNull 63 | public static AsyncDatabase newAsyncDatabase(@NotNull Credentials credentials, @NotNull Executor executor) throws DataSourceInitException { 64 | Preconditions.checkNotNull(executor, "The executor cannot be null."); 65 | return new AsyncDatabase(Mystral.newDatabase(credentials), executor); 66 | } 67 | 68 | /** 69 | * Creates a new AsyncDatabase with the given DataSourceFactory and an Executor implementation. 70 | * @param factory the factory 71 | * @param executor the tasks executor 72 | * @param the DataSource type 73 | * @return the AsyncDatabase 74 | * @throws DataSourceInitException if something went wrong 75 | * @see DataSourceFactory#newDataSource() 76 | */ 77 | @NotNull 78 | public static AsyncDatabase newAsyncDatabase(@NotNull DataSourceFactory factory, @NotNull Executor executor) throws DataSourceInitException { 79 | Preconditions.checkNotNull(executor, "The executor cannot be null."); 80 | return new AsyncDatabase(Mystral.newDatabase(factory), executor); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/database/PreparedStatementUtils.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.database; 2 | 3 | import com.google.common.base.Preconditions; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.io.StringReader; 8 | import java.io.StringWriter; 9 | import java.math.BigDecimal; 10 | import java.sql.PreparedStatement; 11 | import java.sql.SQLException; 12 | import java.sql.Types; 13 | import java.util.Calendar; 14 | 15 | /** 16 | * Utility class for {@link PreparedStatement} objects. 17 | */ 18 | public final class PreparedStatementUtils { 19 | 20 | private static final int CLOB_LENGTH = 4000; 21 | 22 | private PreparedStatementUtils() {} 23 | 24 | /** 25 | * Sets a value inside a {@link PreparedStatement} parameter. 26 | * @param statement a valid PreparedStatement 27 | * @param paramIndex the parameter index 28 | * @param sqlType the type of the parameter expressed as sql {@link Types} 29 | * @param value the parameter value 30 | * @throws SQLException if something went wrong 31 | */ 32 | public static void setValue(@NotNull PreparedStatement statement, int paramIndex, int sqlType, @Nullable Object value) throws SQLException { 33 | Preconditions.checkNotNull(statement, "The PreparedStatement cannot be null."); 34 | if (value == null) { 35 | statement.setNull(paramIndex, sqlType); 36 | return; 37 | } 38 | 39 | switch (sqlType) { 40 | case Types.VARCHAR: 41 | case Types.LONGVARCHAR: 42 | statement.setString(paramIndex, value.toString()); 43 | break; 44 | case Types.NVARCHAR: 45 | case Types.LONGNVARCHAR: 46 | statement.setNString(paramIndex, value.toString()); 47 | break; 48 | case Types.CLOB: 49 | case Types.NCLOB: 50 | if (isStringValue(value.getClass())) { 51 | String stringValue = value.toString(); 52 | if (stringValue.length() > CLOB_LENGTH) { 53 | if (sqlType == Types.NCLOB) { 54 | statement.setNClob(paramIndex, new StringReader(stringValue), stringValue.length()); 55 | } 56 | else { 57 | statement.setClob(paramIndex, new StringReader(stringValue), stringValue.length()); 58 | } 59 | } else { 60 | if (sqlType == Types.NCLOB) { 61 | statement.setNString(paramIndex, stringValue); 62 | } 63 | else { 64 | statement.setString(paramIndex, stringValue); 65 | } 66 | } 67 | } 68 | break; 69 | case Types.DECIMAL: 70 | case Types.NUMERIC: 71 | if (value instanceof BigDecimal) { 72 | statement.setBigDecimal(paramIndex, (BigDecimal) value); 73 | } 74 | else { 75 | statement.setObject(paramIndex, value, sqlType); 76 | } 77 | break; 78 | case Types.BOOLEAN: 79 | if (value instanceof Boolean) { 80 | statement.setBoolean(paramIndex, (Boolean) value); 81 | } 82 | else { 83 | statement.setObject(paramIndex, value, Types.BOOLEAN); 84 | } 85 | break; 86 | case Types.DATE: 87 | if (value instanceof java.util.Date) { 88 | if (value instanceof java.sql.Date) 89 | statement.setDate(paramIndex, (java.sql.Date) value); 90 | else 91 | statement.setDate(paramIndex, new java.sql.Date(((java.util.Date) value).getTime())); 92 | } 93 | else if (value instanceof Calendar) { 94 | Calendar cal = (Calendar) value; 95 | statement.setDate(paramIndex, new java.sql.Date(cal.getTime().getTime()), cal); 96 | } 97 | else { 98 | statement.setObject(paramIndex, value, Types.DATE); 99 | } 100 | break; 101 | case Types.TIME: 102 | if (value instanceof java.util.Date) { 103 | if (value instanceof java.sql.Time) { 104 | statement.setTime(paramIndex, (java.sql.Time) value); 105 | } 106 | else { 107 | statement.setTime(paramIndex, new java.sql.Time(((java.util.Date) value).getTime())); 108 | } 109 | } 110 | else if (value instanceof Calendar) { 111 | Calendar cal = (Calendar) value; 112 | statement.setTime(paramIndex, new java.sql.Time(cal.getTime().getTime()), cal); 113 | } 114 | else { 115 | statement.setObject(paramIndex, value, Types.TIME); 116 | } 117 | break; 118 | case Types.TIMESTAMP: 119 | if (value instanceof java.util.Date) { 120 | if (value instanceof java.sql.Timestamp) { 121 | statement.setTimestamp(paramIndex, (java.sql.Timestamp) value); 122 | } 123 | else { 124 | statement.setTimestamp(paramIndex, new java.sql.Timestamp(((java.util.Date) value).getTime())); 125 | } 126 | } 127 | else if (value instanceof Calendar) { 128 | Calendar cal = (Calendar) value; 129 | statement.setTimestamp(paramIndex, new java.sql.Timestamp(cal.getTime().getTime()), cal); 130 | } 131 | else { 132 | statement.setObject(paramIndex, value, Types.TIMESTAMP); 133 | } 134 | break; 135 | default: 136 | statement.setObject(paramIndex, value, sqlType); 137 | } 138 | } 139 | 140 | private static boolean isStringValue(Class valueType) { 141 | return (CharSequence.class.isAssignableFrom(valueType) || StringWriter.class.isAssignableFrom(valueType)); 142 | } 143 | } 144 | 145 | // I'm on a SugarCrash! -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/database/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains the implementations of the main functionalities of this library. 3 | */ 4 | package com.glyart.mystral.database; -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/datasource/DataSourceFactory.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.datasource; 2 | 3 | import com.glyart.mystral.database.Credentials; 4 | import com.glyart.mystral.database.Mystral; 5 | import com.glyart.mystral.exceptions.DataSourceInitException; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import javax.sql.DataSource; 9 | import java.util.concurrent.Executor; 10 | 11 | /** 12 | * Convenient interface for lazily creating {@link DataSource} objects. 13 | * This interface exposes the {@link #newDataSource()} method, which inits the DataSource. 14 | * 15 | *

Knowing this, implementations must call {@link #newDataSource()} when it's all set.

16 | *

This interface can be used to create any datasource which supports a property-based configuration.

17 | * @param the DataSource type 18 | * @see DataSource 19 | * @see HikariFactory 20 | */ 21 | @FunctionalInterface 22 | public interface DataSourceFactory { 23 | 24 | /** 25 | * Represents a basic template url for creating a jdbc url.
26 | * The structure is {@code jdbc:://:/}
27 | * More info here. 28 | */ 29 | String TEMPLATE_URL = "jdbc:%s://%s:%s/%s"; 30 | 31 | /** 32 | * If ready, a new DataSource is created with its configuration. 33 | * @return the DataSource 34 | * @throws DataSourceInitException if something went wrong.
35 | * This method doesn't need to throw a {@link java.sql.SQLException}.
36 | * Further explanations can be found here. 37 | */ 38 | @NotNull 39 | T newDataSource() throws DataSourceInitException; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/datasource/DataSourceSupplier.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.datasource; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import javax.sql.DataSource; 6 | import java.util.function.Supplier; 7 | 8 | /** 9 | * Represents a supplier of DataSource. 10 | * 11 | *

There is no requirement that a new or distinct DataSource be returned each 12 | * time the supplier is invoked. 13 | * 14 | * @see DataSource 15 | */ 16 | @FunctionalInterface 17 | public interface DataSourceSupplier extends Supplier { 18 | 19 | /** 20 | * Gets a DataSource. 21 | * @return a DataSource. 22 | */ 23 | @Override 24 | @NotNull 25 | DataSource get(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/datasource/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains some utilities for managing {@link javax.sql.DataSource} objects. 3 | */ 4 | package com.glyart.mystral.datasource; -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/exceptions/ConnectionRetrieveException.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.exceptions; 2 | 3 | import java.sql.SQLException; 4 | 5 | public class ConnectionRetrieveException extends RuntimeException { 6 | 7 | public ConnectionRetrieveException(String msg) { 8 | super(msg); 9 | } 10 | 11 | public ConnectionRetrieveException(String msg, SQLException e) { 12 | super(msg, e); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/exceptions/ConversionException.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.exceptions; 2 | 3 | /** 4 | * Represents an exception which describes a problem occurred while trying to convert a type to the desired one. 5 | */ 6 | public class ConversionException extends RuntimeException { 7 | 8 | public ConversionException(Throwable t) { 9 | this(t.getMessage(), t); 10 | } 11 | 12 | public ConversionException(String message) { 13 | super(message); 14 | } 15 | 16 | public ConversionException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/exceptions/DataAccessException.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.exceptions; 2 | 3 | import com.glyart.mystral.sql.AsyncDataOperations; 4 | import com.glyart.mystral.sql.DataOperations; 5 | import com.glyart.mystral.sql.SqlProvider; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import java.sql.SQLException; 9 | 10 | /** 11 | * Represents an exception that occurs when there is a problem during an operation issued by 12 | * implementations of {@link DataOperations} or {@link AsyncDataOperations}. 13 | * 14 | *

Using {@link SqlProvider} is highly suggested. This allows the exception to communicate the sql that issued the problem.

15 | */ 16 | public class DataAccessException extends RuntimeException { 17 | 18 | @Nullable 19 | private String sql; 20 | 21 | public DataAccessException(String msg) { 22 | super(msg); 23 | } 24 | 25 | public DataAccessException(String msg, SQLException e) { 26 | this(msg, null, e); 27 | } 28 | 29 | public DataAccessException(String msg, @Nullable String sql, SQLException e) { 30 | super(String.format("Custom Message: %s - SQL: %s - Exception message: %s (%d)", msg, (sql == null ? "" : sql), e.getMessage(), e.getErrorCode()), e); 31 | this.sql = sql; 32 | } 33 | 34 | /** 35 | * Gets the sql statement that provoked this exception. 36 | * @return the sql (if it is available) 37 | */ 38 | @Nullable 39 | public String getSql() { 40 | return this.sql; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/exceptions/DataSourceInitException.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.exceptions; 2 | 3 | import com.glyart.mystral.datasource.DataSourceFactory; 4 | 5 | /** 6 | * Describes a problem occurred while trying to create a DataSource. 7 | * @see DataSourceFactory 8 | */ 9 | public class DataSourceInitException extends RuntimeException { 10 | 11 | public DataSourceInitException(Exception e) { 12 | super(e); 13 | } 14 | 15 | /** 16 | * Construct a new DataSourceInitException with the given message and the offending exception. 17 | * @param msg the message 18 | * @param e the exception 19 | */ 20 | public DataSourceInitException(String msg, Exception e) { 21 | super(msg, e); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/exceptions/IncorrectDataSizeException.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.exceptions; 2 | 3 | import java.sql.SQLException; 4 | 5 | /** 6 | * Exception thrown when a result was not of the expected size, 7 | * for example when expecting a single row but getting 0 or more than 1 rows. 8 | */ 9 | public class IncorrectDataSizeException extends RuntimeException { 10 | 11 | private final int expectedSize; 12 | private final int actualSize; 13 | 14 | /** 15 | * Constructor for IncorrectResultSizeDataAccessException. 16 | * @param expectedSize the expected result size 17 | */ 18 | public IncorrectDataSizeException(int expectedSize) { 19 | super("Incorrect result size: expected " + expectedSize); 20 | this.expectedSize = expectedSize; 21 | this.actualSize = -1; 22 | } 23 | 24 | /** 25 | * Constructor for IncorrectResultSizeDataAccessException. 26 | * @param expectedSize the expected result size 27 | * @param actualSize the actual result size (or -1 if unknown) 28 | */ 29 | public IncorrectDataSizeException(int expectedSize, int actualSize) { 30 | super("Incorrect result size: expected " + expectedSize + ", actual " + actualSize); 31 | this.expectedSize = expectedSize; 32 | this.actualSize = actualSize; 33 | } 34 | 35 | /** 36 | * Constructor for IncorrectResultSizeDataAccessException. 37 | * @param msg the detail message 38 | * @param expectedSize the expected result size 39 | */ 40 | public IncorrectDataSizeException(String msg, int expectedSize) { 41 | super(msg); 42 | this.expectedSize = expectedSize; 43 | this.actualSize = -1; 44 | } 45 | 46 | /** 47 | * Constructor for IncorrectResultSizeDataAccessException. 48 | * @param msg the detail message 49 | * @param expectedSize the expected result size 50 | * @param ex the wrapped exception 51 | */ 52 | public IncorrectDataSizeException(String msg, int expectedSize, SQLException ex) { 53 | super(msg, ex); 54 | this.expectedSize = expectedSize; 55 | this.actualSize = -1; 56 | } 57 | 58 | /** 59 | * Constructor for IncorrectResultSizeDataAccessException. 60 | * @param msg the detail message 61 | * @param expectedSize the expected result size 62 | * @param actualSize the actual result size (or -1 if unknown) 63 | */ 64 | public IncorrectDataSizeException(String msg, int expectedSize, int actualSize) { 65 | super(msg); 66 | this.expectedSize = expectedSize; 67 | this.actualSize = actualSize; 68 | } 69 | 70 | /** 71 | * Constructor for IncorrectResultSizeDataAccessException. 72 | * @param msg the detail message 73 | * @param expectedSize the expected result size 74 | * @param actualSize the actual result size (or -1 if unknown) 75 | * @param ex the wrapped exception 76 | */ 77 | public IncorrectDataSizeException(String msg, int expectedSize, int actualSize, SQLException ex) { 78 | super(msg, ex); 79 | this.expectedSize = expectedSize; 80 | this.actualSize = actualSize; 81 | } 82 | 83 | /** 84 | * Return the expected result size. 85 | */ 86 | public int getExpectedSize() { 87 | return this.expectedSize; 88 | } 89 | 90 | /** 91 | * Return the actual result size (or -1 if unknown). 92 | */ 93 | public int getActualSize() { 94 | return this.actualSize; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/exceptions/TypeMismatchException.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.exceptions; 2 | 3 | /** 4 | * Threw when trying to auto-mapping rows with the {@link com.glyart.mystral.data.ClassMapper} class. 5 | * Describes 2 possible wrong scenarios: 6 | *
    7 | *
  • There was an attempt to set a null value for a primitive type (which is impossible, because primitive types have their own non-null default values);
  • 8 | *
  • An incompatible value was provided to the setter method
  • 9 | *
10 | */ 11 | public class TypeMismatchException extends RuntimeException { 12 | 13 | public TypeMismatchException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public TypeMismatchException(String message) { 18 | super(message); 19 | } 20 | 21 | public TypeMismatchException(String message, Throwable cause) { 22 | super(message, cause); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/exceptions/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains exceptions thrown by this library. Those classes can also be used in application code for further error customization. 3 | */ 4 | package com.glyart.mystral.exceptions; -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/BatchSetter.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import java.sql.PreparedStatement; 7 | import java.sql.SQLException; 8 | 9 | /** 10 | * Represents a batch update callback interface used by the {@link Database} class. 11 | * 12 | *

Implementations set values on a {@link PreparedStatement} provided by The Database class, for each 13 | * of a number of updates in a batch using the same SQL statement. 14 | * They are responsible for setting parameters: a SQL statement with placeholders (question marks) will already have been supplied.

15 | * 16 | *

Implementations don't need to worry about handling exceptions: 17 | * they will be handled internally by {@link DataOperations} implementations. 18 | * If the handling is done in async context then implementations should make the details available in some way. 19 | * {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

20 | */ 21 | public interface BatchSetter { 22 | 23 | /** 24 | * Sets parameter values on the given PreparedStatement. 25 | * @param preparedStatement an active PreparedStatement for invoking setter methods 26 | * @param i index of the statement inside the batch, starting from 0 27 | * @throws SQLException if an SQLException is encountered while trying to set values (no need to catch) 28 | */ 29 | void setValues(@NotNull PreparedStatement preparedStatement, int i) throws SQLException; 30 | 31 | /** 32 | * Gets the size of the batch. 33 | * @return the number of statements in the batch 34 | */ 35 | int getBatchSize(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/ParametrizedBatchSetter.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import java.sql.PreparedStatement; 7 | import java.sql.SQLException; 8 | import java.util.List; 9 | 10 | /** 11 | * Represents a callback interface used by the {@link Database} class for executing batch updates. 12 | * 13 | *

Implementations of this interface set values on a {@link PreparedStatement} provided by the Database class, for each 14 | * of a number of updates in a batch using the same SQL statement. 15 | * They are responsible for setting parameters: a SQL statement with placeholders (question marks) will already have been supplied.

16 | * 17 | *

Implementations don't need to worry about handling exceptions: 18 | * they will be handled internally by {@link DataOperations} implementations. 19 | * If the handling is done in async context then implementations should make the details available in some way. 20 | * {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

21 | * @param yhe argument type 22 | * @see Database#batchUpdate(String, List, ParametrizedBatchSetter) 23 | */ 24 | @FunctionalInterface 25 | public interface ParametrizedBatchSetter { 26 | 27 | /** 28 | * Sets the parameter values of the T argument inside the PreparedStatement 29 | * @param preparedStatement an active PreparedStatement 30 | * @param argument a generic object containing the values to set 31 | * @throws SQLException if an SQLException is encountered while trying to set values (no need to catch) 32 | */ 33 | void setValues(@NotNull PreparedStatement preparedStatement, T argument) throws SQLException; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/PreparedStatementCreator.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import java.sql.Connection; 7 | import java.sql.PreparedStatement; 8 | import java.sql.SQLException; 9 | /** 10 | * Represents a callback interface used by multiple methods of the {@link Database} class. 11 | * 12 | *

Implementations create a PreparedStatement with a given active Connection, provided by the Database class. Still, they 13 | * are responsible for providing the SQL statement and any necessary parameters.

14 | * 15 | *

Implementations don't need to worry about handling exceptions: 16 | * they will be handled internally by {@link DataOperations} implementations. 17 | * If the handling is done in async context then implementations should make the details available in some way. 18 | * {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

19 | */ 20 | @FunctionalInterface 21 | public interface PreparedStatementCreator { 22 | 23 | /** 24 | * Creates a PreparedStatement in this connection. There is no need to close the PreparedStatement: 25 | * the Database class will do that. 26 | * @param connection the connection for creating the PreparedStatement 27 | * @return a PreparedStatement object 28 | * @throws SQLException if something goes wrong during the PreparedStatement creation (no need to catch) 29 | */ 30 | @NotNull 31 | PreparedStatement create(@NotNull Connection connection) throws SQLException; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/PreparedStatementFunction.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.sql.PreparedStatement; 8 | import java.sql.SQLException; 9 | 10 | /** 11 | * Represents a callback interface for code that operates on a PreparedStatement. 12 | * This is internally used by the {@link Database} class but it's also useful for custom purposes. 13 | * 14 | *

Note: the passed-in PreparedStatement may have been created by {@link Database} or by a custom {@link PreparedStatementCreator} implementation. 15 | * However, the latter is hardly ever necessary, as most custom callback actions will perform updates 16 | * in which case a standard PreparedStatement is fine. Custom actions will 17 | * always set parameter values themselves, so that PreparedStatementCreator 18 | * capability is not needed either.

19 | * 20 | *

Implementations don't need to worry about handling exceptions: 21 | * they will be handled internally by {@link DataOperations} implementations. 22 | * If the handling is done in async context then implementations should make the details available in some way. 23 | * {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

24 | * @param the result type 25 | * @see Database#execute(String, PreparedStatementFunction) 26 | * @see Database#execute(PreparedStatementCreator, PreparedStatementFunction) 27 | */ 28 | @FunctionalInterface 29 | public interface PreparedStatementFunction { 30 | 31 | /** 32 | * Gets called by {@link Database#execute(String, PreparedStatementFunction)} 33 | * or {@link Database#execute(PreparedStatementCreator, PreparedStatementFunction)}. 34 | *

ATTENTION: any ResultSet should be closed within this callback implementation. 35 | * This method doesn't imply that the ResultSet (as other resources) will be closed. 36 | * Still, this method should grant (as shown in Database various implementations) that the statement will be closed at the end of the operations. 37 | * @param ps an active PreparedStatement 38 | * @return a result object or null if it's not available 39 | * @throws SQLException if thrown by a Database's method (no need to catch). 40 | */ 41 | @Nullable 42 | T apply(@NotNull PreparedStatement ps) throws SQLException; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/PreparedStatementSetter.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import java.sql.PreparedStatement; 7 | import java.sql.SQLException; 8 | 9 | /** 10 | * Represents a callback interface used by {@link Database}. 11 | * 12 | *

Implementations of this interface set values on a {@link PreparedStatement} provided by the Database class. 13 | * They are responsible for setting parameters: a SQL statement with placeholders (question marks) will already have been supplied.

14 | * 15 | *

Implementations don't need to worry about handling exceptions: 16 | * they will be handled internally by {@link DataOperations} implementations. 17 | * If the handling is done in async context then implementations should make the details available in some way. 18 | * {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

19 | */ 20 | @FunctionalInterface 21 | public interface PreparedStatementSetter { 22 | 23 | /** 24 | * Sets parameter values into the given active PreparedStatement. 25 | * @param ps the PreparedStatement to invoke setter methods on 26 | * @throws SQLException if an SQLException is encountered while trying to set values (no need to catch) 27 | */ 28 | void setValues(@NotNull PreparedStatement ps) throws SQLException; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/ResultSetExtractor.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import com.glyart.mystral.sql.impl.DefaultExtractor; 5 | import org.jetbrains.annotations.NotNull; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import java.sql.ResultSet; 9 | import java.sql.SQLException; 10 | 11 | /** 12 | * Represents a callback interface used by {@link Database}'s query methods. 13 | * 14 | *

Implementations of this interface extract results from a {@link ResultSet} and they 15 | * don't need to worry about handling exceptions: they will be handled internally by {@link DataOperations} implementations.If the handling is done in async context then implementations should make the details available in some way. {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

16 | * 17 | *

This interface is internally used by Database and, like {@link ResultSetRowMapper}, it's reusable. 18 | * A default implementation called DefaultExtractor is already provided.

19 | * @param the result type 20 | * @see DefaultExtractor 21 | */ 22 | @FunctionalInterface 23 | public interface ResultSetExtractor { 24 | 25 | /** 26 | * Implementations of this method must provide the processing logic (data extraction) of the entire ResultSet. 27 | * @param resultSet the ResultSet to extract data from. Implementations don't need to close this: it will be closed by Database 28 | * @return an object result or null if it's not available 29 | * @throws SQLException if an SQLException is encountered while trying to navigate the ResultSet 30 | */ 31 | @Nullable 32 | T extractData(@NotNull ResultSet resultSet) throws SQLException; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/ResultSetRowMapper.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.sql.ResultSet; 8 | import java.sql.SQLException; 9 | 10 | /** 11 | * Represents an interface used to map rows of a {@link ResultSet}. 12 | * 13 | *

Implementations don't need to worry about handling exceptions: 14 | * they will be handled internally by {@link DataOperations} implementations 15 | * If the handling is done in async context then implementations should make the details available in some way. 16 | * {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

17 | * 18 | *

This interface can be used for query methods or for other custom implementations.


19 | * A RowMapper object is reusable. Also, it's a convenient and fast way for implementing a row-mapping logic in a single spot. 20 | * @param the result type 21 | * @see Database#queryForList(String, ResultSetRowMapper) 22 | */ 23 | @FunctionalInterface 24 | public interface ResultSetRowMapper { 25 | 26 | /** 27 | * Implementations will tell how to map EACH row of the ResultSet.
28 | * {@link ResultSet#next()} call is not needed: this method should only map values of the current row. 29 | * @param resultSet the ResultSet, already initialized 30 | * @param rowNumber the number of the current row 31 | * @return a result object for the current row, or null if the result is not available 32 | * @throws SQLException if the implementation's trying to get column values in the wrong way 33 | */ 34 | @Nullable 35 | T map(@NotNull ResultSet resultSet, int rowNumber) throws SQLException; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/SqlProvider.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.exceptions.DataAccessException; 4 | import org.jetbrains.annotations.Nullable; 5 | 6 | /** 7 | *

Represents an interface to be implemented by objects which can provide SQL strings.

8 | * 9 | *

This interface is implemented alongside {@link StatementFunction}s and {@link PreparedStatementFunction}s. 10 | * This helps retrieving better contextual information in case of {@link DataAccessException} exceptions.

11 | *

Use of this interface is suggested in application code (if possible).

12 | */ 13 | @FunctionalInterface 14 | public interface SqlProvider { 15 | 16 | /** 17 | * Returns the sql statement related to this implementation. 18 | * @return the sql (if available) 19 | */ 20 | @Nullable 21 | String getSql(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/StatementFunction.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql; 2 | 3 | import com.glyart.mystral.database.Database; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | import java.sql.SQLException; 7 | import java.sql.Statement; 8 | 9 | /** 10 | * Represents a callback interface for SQL statements. 11 | * It can execute multiple operations on a single Statement. 12 | * @param The result type 13 | * @see Database#execute(StatementFunction) 14 | */ 15 | public interface StatementFunction { 16 | 17 | /** 18 | * Gets called by {@link Database#execute(StatementFunction)}. 19 | * 20 | *

Implementations don't need to worry about handling exceptions: 21 | * they will be handled internally by {@link DataOperations} implementations 22 | * If the handling is done in async context then implementations should make the details available in some way. 23 | * {@link AsyncDataOperations} may place these details inside a never null CompletableFuture object.

24 | * 25 | *

ATTENTION: any ResultSet should be closed within this callback implementation. This method doesn't imply 26 | * that the ResultSet (as other resources) will be closed. 27 | * Still, this method should grant (as shown in Database various implementations) that the statement 28 | * will be closed at the end of the operations.

29 | * @param statement an active statement 30 | * @return a result of the statement execution. Null if no results are available 31 | * @throws SQLException if a database error occured. If so, it will be properly handled by implementations 32 | * @see Database#update(String, boolean) 33 | * @see Database#query(String, ResultSetExtractor) 34 | */ 35 | T apply(@NotNull Statement statement) throws SQLException; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/DefaultBatchSetter.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql.impl; 2 | 3 | import com.glyart.mystral.database.PreparedStatementUtils; 4 | import com.glyart.mystral.sql.BatchSetter; 5 | import com.google.common.base.Preconditions; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.sql.PreparedStatement; 9 | import java.sql.SQLException; 10 | import java.util.List; 11 | 12 | public class DefaultBatchSetter implements BatchSetter { 13 | 14 | @NotNull 15 | private final List batchParams; 16 | private final int[] sqlTypes; 17 | 18 | public DefaultBatchSetter(@NotNull List batchParams, int[] sqlTypes) { 19 | this.batchParams = batchParams; 20 | this.sqlTypes = sqlTypes; 21 | } 22 | 23 | @Override 24 | public void setValues(@NotNull PreparedStatement ps, int i) throws SQLException { 25 | Preconditions.checkNotNull(ps, "PreparedStatement cannot be null."); 26 | Object[] objects = batchParams.get(i); 27 | for (int pos = 0; pos < objects.length; pos++) { 28 | Object object = objects[pos]; 29 | PreparedStatementUtils.setValue(ps, pos + 1, sqlTypes[pos], object); 30 | } 31 | } 32 | 33 | @Override 34 | public int getBatchSize() { 35 | return batchParams.size(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/DefaultCreator.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql.impl; 2 | 3 | import com.glyart.mystral.sql.PreparedStatementCreator; 4 | import com.glyart.mystral.sql.SqlProvider; 5 | import com.google.common.base.Preconditions; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.sql.Connection; 9 | import java.sql.PreparedStatement; 10 | import java.sql.SQLException; 11 | import java.sql.Statement; 12 | 13 | public class DefaultCreator implements PreparedStatementCreator, SqlProvider { 14 | 15 | @NotNull 16 | private final String sql; 17 | private final boolean getGeneratedKeys; 18 | 19 | public DefaultCreator(@NotNull String sql) { 20 | this(sql, false); 21 | } 22 | 23 | public DefaultCreator(@NotNull String sql, boolean getGeneratedKeys) { 24 | Preconditions.checkNotNull(sql, "Sql statement cannot be null."); 25 | Preconditions.checkArgument(!sql.isEmpty(), "Sql statement cannot be empty."); 26 | this.sql = sql; 27 | this.getGeneratedKeys = getGeneratedKeys; 28 | } 29 | 30 | @NotNull 31 | @Override 32 | public PreparedStatement create(@NotNull Connection connection) throws SQLException { 33 | Preconditions.checkNotNull(connection, "Connection cannot be null."); 34 | return connection.prepareStatement(sql, getGeneratedKeys ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS); 35 | } 36 | 37 | @NotNull 38 | @Override 39 | public String getSql() { 40 | return sql; 41 | } 42 | } -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/DefaultExtractor.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql.impl; 2 | 3 | import com.glyart.mystral.sql.ResultSetExtractor; 4 | import com.glyart.mystral.sql.ResultSetRowMapper; 5 | import com.google.common.base.Preconditions; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.sql.ResultSet; 10 | import java.sql.SQLException; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class DefaultExtractor implements ResultSetExtractor> { 15 | 16 | @NotNull 17 | private final ResultSetRowMapper mapper; 18 | private final int limit; 19 | 20 | public DefaultExtractor(@NotNull ResultSetRowMapper mapper) { 21 | this(mapper, 0); 22 | } 23 | 24 | public DefaultExtractor(@NotNull ResultSetRowMapper mapper, int limit) { 25 | Preconditions.checkNotNull(mapper, "ResultSetRowMapper cannot be null."); 26 | this.mapper = mapper; 27 | this.limit = Math.abs(limit); 28 | } 29 | 30 | @Nullable 31 | @Override 32 | public List extractData(@NotNull ResultSet rs) throws SQLException { 33 | if (!rs.next()) { 34 | return null; 35 | } 36 | List list = new ArrayList<>(); 37 | int rowNum = 0; 38 | list.add(mapper.map(rs, rowNum++)); 39 | if (rowNum == limit) { 40 | return list; 41 | } 42 | 43 | while (rs.next()) { 44 | if (rowNum == limit) { 45 | break; 46 | } 47 | list.add(mapper.map(rs, rowNum++)); 48 | } 49 | return list; 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/DefaultSetter.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql.impl; 2 | 3 | import com.glyart.mystral.database.PreparedStatementUtils; 4 | import com.glyart.mystral.sql.PreparedStatementSetter; 5 | import com.google.common.base.Preconditions; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.sql.PreparedStatement; 10 | import java.sql.SQLException; 11 | 12 | public class DefaultSetter implements PreparedStatementSetter { 13 | 14 | @Nullable 15 | private final Object[] params; 16 | private final int[] sqlTypes; 17 | 18 | public DefaultSetter(Object[] params, int[] sqlTypes) { 19 | this.params = params; 20 | this.sqlTypes = sqlTypes; 21 | } 22 | 23 | @Override 24 | public void setValues(@NotNull PreparedStatement ps) throws SQLException { 25 | Preconditions.checkNotNull(ps, "PreparedStatement cannot be null."); 26 | if (params == null) 27 | return; 28 | 29 | for (int i = 0; i < params.length; i++) { 30 | Object param = params[i]; 31 | PreparedStatementUtils.setValue(ps, i + 1, sqlTypes[i], param); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/DefaultSetterUnknownType.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql.impl; 2 | 3 | import com.glyart.mystral.database.PreparedStatementUtils; 4 | import com.glyart.mystral.sql.PreparedStatementSetter; 5 | import com.google.common.base.Preconditions; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.sql.PreparedStatement; 10 | import java.sql.SQLException; 11 | 12 | public class DefaultSetterUnknownType implements PreparedStatementSetter { 13 | 14 | @Nullable 15 | private final Object[] params; 16 | 17 | public DefaultSetterUnknownType(@Nullable Object[] params) { 18 | this.params = params; 19 | } 20 | 21 | @Override 22 | public void setValues(@NotNull PreparedStatement ps) throws SQLException { 23 | Preconditions.checkNotNull(ps, "PreparedStatement cannot be null."); 24 | if (params == null) 25 | return; 26 | 27 | for (int i = 0; i < params.length; i++) 28 | PreparedStatementUtils.setValue(ps, i + 1, Integer.MIN_VALUE, params[i]); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/QueryStatementFunction.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql.impl; 2 | 3 | import com.glyart.mystral.datasource.DataSourceUtils; 4 | import com.glyart.mystral.sql.ResultSetExtractor; 5 | import com.glyart.mystral.sql.SqlProvider; 6 | import com.glyart.mystral.sql.StatementFunction; 7 | import com.google.common.base.Preconditions; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.sql.ResultSet; 12 | import java.sql.SQLException; 13 | import java.sql.Statement; 14 | 15 | public class QueryStatementFunction implements StatementFunction, SqlProvider { 16 | 17 | @NotNull 18 | private final ResultSetExtractor extractor; 19 | 20 | @Nullable 21 | private final String sql; 22 | 23 | public QueryStatementFunction(@NotNull ResultSetExtractor extractor, @Nullable String sql) { 24 | Preconditions.checkNotNull(extractor, "ResultSetExtractor cannot be null."); 25 | this.extractor = extractor; 26 | this.sql = sql; 27 | } 28 | 29 | @Override 30 | public @Nullable T apply(@NotNull Statement statement) throws SQLException { 31 | ResultSet resultSet = null; 32 | T result; 33 | try { 34 | resultSet = statement.executeQuery(sql); 35 | result = extractor.extractData(resultSet); 36 | } finally { 37 | DataSourceUtils.closeResultSet(resultSet); 38 | } 39 | return result; 40 | } 41 | 42 | @Nullable 43 | @Override 44 | public String getSql() { 45 | return sql; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/SimpleUpdateStatementFunction.java: -------------------------------------------------------------------------------- 1 | package com.glyart.mystral.sql.impl; 2 | 3 | import com.glyart.mystral.sql.SqlProvider; 4 | import com.glyart.mystral.sql.StatementFunction; 5 | import org.jetbrains.annotations.NotNull; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import java.sql.SQLException; 9 | import java.sql.Statement; 10 | 11 | public class SimpleUpdateStatementFunction implements StatementFunction, SqlProvider { 12 | 13 | @Nullable 14 | private final String sql; 15 | 16 | public SimpleUpdateStatementFunction(@Nullable String sql) { 17 | this.sql = sql; 18 | } 19 | 20 | @Override 21 | public Integer apply(@NotNull Statement statement) throws SQLException { 22 | return statement.executeUpdate(sql); 23 | } 24 | 25 | @Nullable 26 | @Override 27 | public String getSql() { 28 | return sql; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains basic implementations of the {@link com.glyart.mystral.sql} package. 3 | */ 4 | package com.glyart.mystral.sql.impl; -------------------------------------------------------------------------------- /src/main/java/com/glyart/mystral/sql/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains interfaces used by {@link com.glyart.mystral.sql.DataOperations} and {@link com.glyart.mystral.sql.AsyncDataOperations} implementations.
3 | * These interfaces represent various operations: 4 | *
    5 | *
  • {@link java.sql.Connection} objects manipulation
  • 6 | *
  • Generic sql operations
  • 7 | *
  • Parametrized callbacks
  • 8 | *
  • Easy exception handling
  • 9 | *
10 | */ 11 | package com.glyart.mystral.sql; --------------------------------------------------------------------------------