-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0258f0b
Showing
42 changed files
with
3,553 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
.idea/ | ||
*.iml | ||
docs/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Change Log | ||
|
||
## Version 1.0.0 | ||
|
||
Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Proto4j | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Proto4j-Redis | ||
|
||
A type-safe framework to turn a java interface into a database worker. For more information please visit [the documentation](https://proto4j.github.io/proto4j-redis/). | ||
|
||
This repository contains the source code for the `Redis` module from `Proto4j`. It is considered to be a development repository where changes can be made and features can be requested. `SQLFactory` implementation modules are provided in the `factories` directory. Currently, only SQLite and MySQL are provided. | ||
|
||
# Example usage | ||
|
||
This framework is built to be user-friendly when working with generated service workers. The following example illustrates a simple user service: | ||
|
||
````java | ||
@SQL(SQLiteFactory.FACTORY) | ||
public interface UserDao { | ||
@SQL.Select("select * from {table};") | ||
public List<User> fetchUsers(@Param("table") String tableName); | ||
} | ||
|
||
public static void main(String[]args) { | ||
SQLiteConfiguration config = new SQLiteConfiguration("mydb"); | ||
UserDao userDao = Redis.create(UserDao.class, config); | ||
// fetch all user objects | ||
for (User user : userDao.fetchUsers("user_table1")) { | ||
// ... | ||
} | ||
} | ||
```` | ||
|
||
## Download | ||
|
||
Download the [latest JAR file](https://github.com/Proto4j/proto4j-redis/releases) from the releases tab and the `SQLFactory` implementation JAR file what you intend to use. This framework requires a minimum of Java 8+ for developing and running. | ||
|
||
## License | ||
|
||
MIT License | ||
|
||
Copyright (c) 2022 Proto4j | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
74 changes: 74 additions & 0 deletions
74
factories/redis-mysql/src/main/java/org/proto4j/redis/mysql/MySQLConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022 Proto4j | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.proto4j.redis.mysql; //@date 03.09.2022 | ||
|
||
import org.proto4j.redis.sql.SQLConfiguration; | ||
import org.proto4j.redis.sql.SQLPrincipal; | ||
|
||
import java.util.Objects; | ||
import java.util.Properties; | ||
|
||
public class MySQLConfiguration extends SQLConfiguration { | ||
|
||
private final String host; | ||
private final int port; | ||
private final String database; | ||
|
||
public MySQLConfiguration(String host, int port, String database) { | ||
this(null, host, port, database); | ||
} | ||
|
||
public MySQLConfiguration(SQLPrincipal principal, | ||
String host, int port, String database) { | ||
this(null, principal, host, port, database); | ||
} | ||
|
||
public MySQLConfiguration(Properties properties, SQLPrincipal principal, | ||
String host, int port, String database) { | ||
super(MySQLFactory.FACTORY, properties, principal); | ||
this.host = Objects.requireNonNull(host); | ||
this.port = port; | ||
this.database = Objects.requireNonNull(database); | ||
} | ||
|
||
|
||
@Override | ||
public String getQualifiedName() { | ||
String path = "//" + host + ':' + port + '/' + database; | ||
return String.join(":", "jdbc", getDriverType(), path); | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
public String getDatabase() { | ||
return database; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
factories/redis-mysql/src/main/java/org/proto4j/redis/mysql/MySQLContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022 Proto4j | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.proto4j.redis.mysql; //@date 03.09.2022 | ||
|
||
import org.proto4j.redis.sql.SQLContext; | ||
import org.proto4j.redis.sql.SQLSource; | ||
|
||
public class MySQLContext implements SQLContext { | ||
|
||
private final SQLSource source; | ||
|
||
private Class<?> parent; | ||
private Object reference; | ||
|
||
public MySQLContext(SQLSource source) {this.source = source;} | ||
|
||
@Override | ||
public SQLSource getSource() { | ||
return source; | ||
} | ||
|
||
@Override | ||
public Class<?> getAPIServiceType() { | ||
return MySQLService.class; | ||
} | ||
|
||
@Override | ||
public Object getReference() { | ||
return reference; | ||
} | ||
|
||
@Override | ||
public void setReference(Object reference) { | ||
this.reference = reference; | ||
} | ||
|
||
@Override | ||
public Class<?> getReferenceParent() { | ||
return parent; | ||
} | ||
|
||
@Override | ||
public void setReferenceParent(Class<?> cls) { | ||
this.parent = cls; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
factories/redis-mysql/src/main/java/org/proto4j/redis/mysql/MySQLFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2022 Proto4j | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.proto4j.redis.mysql; //@date 03.09.2022 | ||
|
||
import org.proto4j.redis.FactoryManager; | ||
import org.proto4j.redis.sql.SQLConfiguration; | ||
import org.proto4j.redis.sql.SQLFactory; | ||
import org.proto4j.redis.sql.SQLService; | ||
import org.proto4j.redis.sql.SQLSource; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLDataException; | ||
import java.sql.SQLException; | ||
import java.sql.SQLWarning; | ||
import java.util.Properties; | ||
|
||
public class MySQLFactory implements SQLFactory { | ||
|
||
public static final String FACTORY = "mysql"; | ||
|
||
static { | ||
try { | ||
// This factory should work only if the MySQL-Driver | ||
// is registered. Otherwise, this service can not be called | ||
// because the corresponding driver is missing. | ||
DriverManager.getDriver("jdbc:mysql:temp"); | ||
|
||
FactoryManager.registerFactory(new MySQLFactory()); | ||
} catch (SQLException e) { | ||
System.err.println("WARNING: no suitable driver for jdbc:mysql"); | ||
} | ||
} | ||
|
||
public MySQLFactory() { | ||
} | ||
|
||
@Override | ||
public SQLSource engineGetSource(SQLConfiguration conf) throws SQLDataException, SQLWarning { | ||
return new MySQLSource(conf); | ||
} | ||
|
||
@Override | ||
public SQLService engineGetService(SQLSource source) throws SQLException { | ||
return new MySQLService(source); | ||
} | ||
|
||
@Override | ||
public String engineDriverType() { | ||
return FACTORY; | ||
} | ||
|
||
@Override | ||
public int getMajorVersion() { | ||
String[] vInfo = getVersion().split("\\."); | ||
return vInfo.length > 1 ? Integer.parseInt(vInfo[1]) : 1; | ||
} | ||
|
||
@Override | ||
public int getMinorVersion() { | ||
String[] vInfo = getVersion().split("\\."); | ||
return vInfo.length > 2 ? Integer.parseInt(vInfo[2]) : 0; | ||
} | ||
|
||
public static String getVersion() { | ||
URL versionFile = MySQLFactory.class.getResource("/redis-sqlite.properties"); | ||
if (versionFile == null) { | ||
throw new UnsupportedClassVersionError("Could not examine version"); | ||
} | ||
|
||
String version = "unknown"; | ||
try { | ||
Properties data = new Properties(); | ||
data.load(versionFile.openStream()); | ||
version = data.getProperty("version", version); | ||
version = version.trim(); | ||
} catch (IOException e) { | ||
System.err.println(e.getMessage()); | ||
} | ||
return version; | ||
} | ||
} |
Oops, something went wrong.