-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from kaneeldias/improve
- Loading branch information
Showing
5 changed files
with
103 additions
and
29 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
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
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
63 changes: 63 additions & 0 deletions
63
native/src/main/java/io/ballerina/stdlib/persist/sql/Utils.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,63 @@ | ||
/* | ||
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.stdlib.persist.sql; | ||
|
||
import io.ballerina.runtime.api.PredefinedTypes; | ||
import io.ballerina.runtime.api.creators.TypeCreator; | ||
import io.ballerina.runtime.api.creators.ValueCreator; | ||
import io.ballerina.runtime.api.types.RecordType; | ||
import io.ballerina.runtime.api.utils.TypeUtils; | ||
import io.ballerina.runtime.api.values.BArray; | ||
import io.ballerina.runtime.api.values.BError; | ||
import io.ballerina.runtime.api.values.BObject; | ||
import io.ballerina.runtime.api.values.BStream; | ||
import io.ballerina.runtime.api.values.BTypedesc; | ||
|
||
import static io.ballerina.stdlib.persist.sql.Constants.PERSIST_SQL_STREAM; | ||
import static io.ballerina.stdlib.persist.sql.ModuleUtils.getModule; | ||
|
||
/** | ||
* This class provides the SQL util methods for persistence. | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
public class Utils { | ||
|
||
private static BObject createPersistSQLStream(BStream sqlStream, BTypedesc targetType, BArray fields, | ||
BArray includes, BArray typeDescriptions, BObject persistClient, | ||
BError persistError) { | ||
return ValueCreator.createObjectValue(getModule(), PERSIST_SQL_STREAM, | ||
sqlStream, targetType, fields, includes, typeDescriptions, persistClient, persistError); | ||
} | ||
|
||
private static BStream createPersistSQLStreamValue(BTypedesc targetType, BObject persistSQLStream) { | ||
RecordType streamConstraint = | ||
(RecordType) TypeUtils.getReferredType(targetType.getDescribingType()); | ||
return ValueCreator.createStreamValue( | ||
TypeCreator.createStreamType(streamConstraint, PredefinedTypes.TYPE_NULL), persistSQLStream); | ||
} | ||
|
||
public static BStream createPersistSQLStreamValue(BStream sqlStream, BTypedesc targetType, BArray fields, | ||
BArray includes, BArray typeDescriptions, BObject persistClient, | ||
BError persistError) { | ||
BObject persistSQLStream = createPersistSQLStream(sqlStream, targetType, fields, includes, typeDescriptions, | ||
persistClient, persistError); | ||
return createPersistSQLStreamValue(targetType, persistSQLStream); | ||
} | ||
} |
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