├── .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/#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 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/class-use/Name.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/class-use/Skip.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |See: Description
79 |Class | 87 |Description | 88 |
---|---|
StringToUUID | 92 |
93 | A converter which converts string to UUIDs.
94 | |
95 |
Copyright © 2021. All rights reserved.
155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
138 | 139 | 140 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/data/support/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/database/class-use/Mystral.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/database/class-use/PreparedStatementUtils.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/database/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/datasource/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
148 | 149 | 150 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/exceptions/class-use/ConnectionRetrieveException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/exceptions/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |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 |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 |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 |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 |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 |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 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/impl/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/com/glyart/mystral/sql/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Modifier and Type | 90 |Constant Field | 91 |Value | 92 |
---|---|---|
96 |
97 | public static final String |
98 | TEMPLATE_URL |
99 | "jdbc:%s://%s:%s/%s" |
100 |
Copyright © 2021. All rights reserved.
154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |Copyright © 2021. All rights reserved.
125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/overview-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Package | 81 |Description | 82 |
---|---|
com.glyart.mystral.data | 86 |
87 | Contains classes for: auto object mappings, better data management and type conversions.
88 | |
89 |
com.glyart.mystral.data.support | 92 |
93 | Contains implementations for fast type conversions.
94 | |
95 |
com.glyart.mystral.database | 98 |
99 | Contains the implementations of the main functionalities of this library.
100 | |
101 |
com.glyart.mystral.datasource | 104 |
105 | Contains some utilities for managing
106 | DataSource objects. |
107 |
com.glyart.mystral.exceptions | 110 |
111 | Contains exceptions thrown by this library.
112 | |
113 |
com.glyart.mystral.sql | 116 |
117 | Contains interfaces used by
118 | DataOperations and AsyncDataOperations implementations. |
119 |
com.glyart.mystral.sql.impl | 122 |
123 | Contains basic implementations of the
124 | com.glyart.mystral.sql package. |
125 |
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 |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 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 Knowing this, implementations must call {@link #newDataSource()} when it's all set. This interface can be used to create any datasource which supports a property-based configuration. 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 Using {@link SqlProvider} is highly suggested. This allows the exception to communicate the sql that issued the problem. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. This interface is internally used by Database and, like {@link ResultSetRowMapper}, it's reusable.
18 | * A default implementation called DefaultExtractor is already provided. 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. This interface can be used for query methods or for other custom implementations. Represents an interface to be implemented by objects which can provide SQL strings. 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. Use of this interface is suggested in application code (if possible). 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. 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.
12 | *
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
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
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 | *
7 | *
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 | *
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
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 | *