-
Notifications
You must be signed in to change notification settings - Fork 19
DynamoDB external datastore support library #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
32a825b
DynamoDB support initial commit (WIP)
gusbro 7caf40f
Add support for querying tables
gusbro a3247de
Add support for CRUD operations
gusbro d62020c
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro c411c57
Round some edges
gusbro 1e1aa37
rolled back unintended commit
gusbro 56fe85b
Optimize imports
gusbro 7fc789c
Fix error with blank password and local url. Fix lint errors
gusbro 5a75076
Fix lint errors
gusbro e5ab84d
Merge branch 'master' into DynamoDBIssue69246
gusbro e5e7953
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro 467c492
Allow datetime fields to only contain the date part
gusbro 0d68b9a
Add missing implementation for getDate/1
gusbro 255dbbd
Merge branch 'DynamoDBIssue69246' of https://github.com/genexuslabs/J…
gusbro 63ea5e1
Add special case for queries that filter with an empty string key
gusbro 9002832
Merge branch 'master' into DynamoDBIssue69246
jechague 8dc285b
Update version to 2.6
jechague 4042b19
Remove hardcoded dependency version
jechague eea3a3d
Add support for binary streams
gusbro 1d3675b
Fix NullPointerException when trying to get a binary stream from a re…
gusbro b2053d8
Add support for blobs, when duplicate/when none semantics. Fix datetimes
gusbro 5cedb46
add 'as' method to cast a query to its derived type
gusbro 966a2d3
fix imports
gusbro 6acda81
Merge branch 'master' into DynamoDBIssue69246
gusbro 0449780
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro 3605655
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro a3a0136
Improve Query/Scan inference. Fix lint errors
gusbro f7f60de
Merge branch 'DynamoDBIssue69246' of https://github.com/genexuslabs/J…
gusbro 0458136
Merge branch 'master' into DynamoDBIssue69246
ggallotti 92c18e1
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro a3e9b61
Merge branch 'DynamoDBIssue69246' of https://github.com/genexuslabs/J…
gusbro 8ad04ae
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro d187d49
Fix datetime fields. Fix update queries
gusbro 2d5516a
Merge branch 'master' into DynamoDBIssue69246
gusbro 8251aeb
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro b2a7ff4
Fix possible input types for Date and DateTime in toAttributeValue
gusbro a4dc6c2
Merge branch 'DynamoDBIssue69246' of https://github.com/genexuslabs/J…
gusbro 9a8be4d
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro 1718a92
Change DateTime->String conversion. It was shifting offsets twice to …
gusbro b7a3340
Simplify empty datetime parameters so there is no need manage java.ut…
gusbro a365556
Merge branch 'master' into DynamoDBIssue69246
gusbro f772273
Merge remote-tracking branch 'origin/master' into DynamoDBIssue69246
gusbro 226ca84
Merge branch 'DynamoDBIssue69246' of https://github.com/genexuslabs/J…
gusbro d5be2e8
Update build workflow - #596
gusbro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,58 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>com.genexus</groupId> | ||
| <artifactId>parent</artifactId> | ||
| <version>${revision}${changelist}</version> | ||
| </parent> | ||
|
|
||
| <artifactId>gxdynamodb</artifactId> | ||
| <name>GeneXus DynamoDB</name> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>bom</artifactId> | ||
| <version>2.17.151</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>software.amazon.awssdk</groupId> | ||
| <artifactId>dynamodb</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>gxclassR</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.genexus</groupId> | ||
| <artifactId>gxcommon</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <finalName>gxdynamodb</finalName> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>8</source> | ||
| <target>8</target> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
75 changes: 75 additions & 0 deletions
75
gxdynamodb/src/main/java/com/genexus/db/dynamodb/DataStoreHelperDynamoDB.java
This file contains hidden or 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,75 @@ | ||
| package com.genexus.db.dynamodb; | ||
|
|
||
| import com.genexus.CommonUtil; | ||
| import com.genexus.db.ServiceCursorBase; | ||
| import com.genexus.db.driver.GXConnection; | ||
| import com.genexus.db.driver.GXPreparedStatement; | ||
| import com.genexus.db.service.GXType; | ||
| import com.genexus.db.service.IQuery; | ||
| import com.genexus.db.service.ServiceDataStoreHelper; | ||
|
|
||
| import java.sql.Date; | ||
| import java.sql.Timestamp; | ||
|
|
||
| public class DataStoreHelperDynamoDB extends ServiceDataStoreHelper | ||
| { | ||
| public DynamoQuery newQuery() | ||
| { | ||
| return new DynamoQuery(this); | ||
| } | ||
| public DynamoQuery newScan() | ||
| { | ||
| return new DynamoScan(this); | ||
| } | ||
|
|
||
| public DynamoDBMap Map(String name) | ||
| { | ||
| return new DynamoDBMap(name); | ||
| } | ||
|
|
||
| public Object empty(GXType gxtype) | ||
| { | ||
| switch(gxtype) | ||
| { | ||
| case Number: | ||
| case Int16: | ||
| case Int32: | ||
| case Int64: return 0; | ||
| case Date: return new Date(CommonUtil.nullDate().getTime()); | ||
| case DateTime: | ||
| case DateTime2: return new Timestamp(CommonUtil.nullDate().getTime()); | ||
| case Byte: | ||
| case NChar: | ||
| case NClob: | ||
| case NVarChar: | ||
| case Char: | ||
| case LongVarChar: | ||
| case Clob: | ||
| case VarChar: | ||
| case Raw: | ||
| case Blob: | ||
| case NText: | ||
| case Text: | ||
| case Image: | ||
| case UniqueIdentifier: | ||
| case Xml: | ||
| case DateAsChar: return ""; | ||
| case Boolean: return false; | ||
| case Decimal: return 0f; | ||
|
|
||
| case Geography: | ||
| case Geopoint: | ||
| case Geoline: | ||
| case Geopolygon: | ||
|
|
||
| case Undefined: | ||
| default: return null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public GXPreparedStatement getPreparedStatement(GXConnection con, IQuery query, ServiceCursorBase cursor, int cursorNum, boolean currentOf, Object[] parms) | ||
| { | ||
| return new GXPreparedStatement(new DynamoDBPreparedStatement(con.getJDBCConnection(), (DynamoQuery)query, cursor, parms, con), con, con.getHandle(), "", cursor.getCursorId(), currentOf); | ||
| } | ||
| } | ||
147 changes: 147 additions & 0 deletions
147
gxdynamodb/src/main/java/com/genexus/db/dynamodb/DynamoDBConnection.java
This file contains hidden or 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,147 @@ | ||
| package com.genexus.db.dynamodb; | ||
|
|
||
| import com.genexus.db.service.ServiceConnection; | ||
| import org.apache.commons.lang.StringUtils; | ||
| import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
| import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
| import software.amazon.awssdk.regions.Region; | ||
| import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
| import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder; | ||
|
|
||
| import java.net.URI; | ||
| import java.sql.ResultSet; | ||
| import java.util.Enumeration; | ||
| import java.util.Properties; | ||
| import java.util.concurrent.Executor; | ||
|
|
||
| public class DynamoDBConnection extends ServiceConnection | ||
| { | ||
| private static final String GXDYNAMODB_VERSION = "1.0"; | ||
| private static final String GXDYNAMODB_PRODUCT_NAME = "DynamoDB"; | ||
|
|
||
| private static final String CLIENT_ID = "user"; | ||
| private static final String CLIENT_SECRET = "password"; | ||
| private static final String REGION = "region"; | ||
| private static final String LOCAL_URL = "localurl"; | ||
|
|
||
|
|
||
| DynamoDbClient mDynamoDB; | ||
| Region mRegion = Region.US_EAST_1; | ||
|
|
||
| public DynamoDBConnection(String connUrl, Properties initialConnProps) | ||
| { | ||
| super(connUrl, initialConnProps); // After initialization use props variable from super class to manage properties | ||
| initializeDBConnection(connUrl); | ||
| } | ||
|
|
||
| private void initializeDBConnection(String connUrl) | ||
| { | ||
| String mLocalUrl = null, mClientId = null, mClientSecret = null; | ||
| for(Enumeration<Object> keys = props.keys(); keys.hasMoreElements(); ) | ||
| { | ||
| String key = (String)keys.nextElement(); | ||
| String value = props.getProperty(key, key); | ||
| switch(key.toLowerCase()) | ||
| { | ||
| case LOCAL_URL: mLocalUrl = value; break; | ||
| case CLIENT_ID: mClientId = value; break; | ||
| case CLIENT_SECRET: mClientSecret = value; break; | ||
| case REGION: mRegion = Region.of(value); break; | ||
| default: break; | ||
| } | ||
| } | ||
| DynamoDbClientBuilder builder = DynamoDbClient.builder().region(mRegion); | ||
| if(mLocalUrl != null) | ||
| builder = builder.endpointOverride(URI.create(mLocalUrl)); | ||
| if(StringUtils.isNotEmpty(mClientId) && | ||
| StringUtils.isNotEmpty(mClientSecret)) | ||
| { | ||
| AwsBasicCredentials mCredentials = AwsBasicCredentials.create(mClientId, mClientSecret); | ||
| builder = builder.credentialsProvider(StaticCredentialsProvider.create(mCredentials)); | ||
| } | ||
| mDynamoDB = builder.build(); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------------------------------- | ||
|
|
||
| @Override | ||
| public void close() | ||
| { | ||
| mDynamoDB.close(); | ||
| mDynamoDB = null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isClosed() | ||
| { | ||
| return mDynamoDB != null; | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------------------------------- | ||
| @Override | ||
| public String getDatabaseProductName() | ||
| { | ||
| return GXDYNAMODB_PRODUCT_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDatabaseProductVersion() | ||
| { | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDriverName() | ||
| { | ||
| return mDynamoDB.getClass().getName(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getDriverVersion() | ||
| { | ||
| return String.format("%s/%s", mDynamoDB.serviceName(), GXDYNAMODB_VERSION); | ||
| } | ||
|
|
||
| // JDK8: | ||
| @Override | ||
| public void setSchema(String schema) | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
|
|
||
| @Override | ||
| public String getSchema() | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
|
|
||
| @Override | ||
| public void abort(Executor executor) | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
|
|
||
| @Override | ||
| public void setNetworkTimeout(Executor executor, int milliseconds) | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
|
|
||
| @Override | ||
| public int getNetworkTimeout() | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
|
|
||
| @Override | ||
| public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean generatedKeyAlwaysReturned() | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
gxdynamodb/src/main/java/com/genexus/db/dynamodb/DynamoDBDriver.java
This file contains hidden or 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,73 @@ | ||
| package com.genexus.db.dynamodb; | ||
|
|
||
| import java.sql.*; | ||
| import java.util.Properties; | ||
| import java.util.logging.Logger; | ||
|
|
||
| public class DynamoDBDriver implements Driver | ||
| { | ||
| private static final int MAJOR_VERSION = 1; | ||
| private static final int MINOR_VERSION = 0; | ||
| private static final String DRIVER_ID = "dynamodb:"; | ||
|
|
||
| private static final DynamoDBDriver DYNAMODB_DRIVER; | ||
| static | ||
| { | ||
| DYNAMODB_DRIVER = new DynamoDBDriver(); | ||
| try | ||
| { | ||
| DriverManager.registerDriver(DYNAMODB_DRIVER); | ||
| }catch(SQLException e) | ||
| { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| public DynamoDBDriver() | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public Connection connect(String url, Properties info) | ||
| { | ||
| if(!acceptsURL(url)) | ||
| return null; | ||
| return new DynamoDBConnection(url.substring(DRIVER_ID.length()), info); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean acceptsURL(String url) | ||
| { | ||
| return url.startsWith(DRIVER_ID); | ||
| } | ||
|
|
||
| @Override | ||
| public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) | ||
| { | ||
| return new DriverPropertyInfo[0]; | ||
| } | ||
|
|
||
| @Override | ||
| public int getMajorVersion() | ||
| { | ||
| return MAJOR_VERSION; | ||
| } | ||
|
|
||
| @Override | ||
| public int getMinorVersion() | ||
| { | ||
| return MINOR_VERSION; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean jdbcCompliant() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public Logger getParentLogger() | ||
| { | ||
| throw new UnsupportedOperationException("Not supported yet."); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
gxdynamodb/src/main/java/com/genexus/db/dynamodb/DynamoDBErrors.java
This file contains hidden or 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,7 @@ | ||
| package com.genexus.db.dynamodb; | ||
|
|
||
| public class DynamoDBErrors | ||
| { | ||
| public static final String ValidationException = "ValidationException"; | ||
| public static final CharSequence ValidationExceptionMessageKey = "The AttributeValue for a key attribute cannot contain an empty string value."; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.