I have a class called ErrorItem that have multiple construtors. Is it possible to call another constructor inside of the constructor to manage default values?
Example:
CONSTRUCTOR PUBLIC ErrorItem():
ErrorItem("", "", "", -1, "", "").
END CONSTRUCTOR.
CONSTRUCTOR PUBLIC ErrorItem(
ItemNo AS CHARACTER
,UpcCode AS CHARACTER
,CustomerPo AS CHARACTER
,ColumnId AS INTEGER
,Description AS CHARACTER):
ErrorItem(ItemNo, UpcCode, CustomerPo, ColumnId, Description, "").
END CONSTRUCTOR.
CONSTRUCTOR PUBLIC ErrorItem(
ItemNo AS CHARACTER
,UpcCode AS CHARACTER
,CustomerPo AS CHARACTER
,ColumnId AS INTEGER
,Description AS CHARACTER
,Detail AS CHARACTER
):
ASSIGN
THIS-OBJECT:ItemNo = ItemNo
THIS-OBJECT:UpcCode = UpcCode
THIS-OBJECT:CustomerPo = CustomerPo
THIS-OBJECT:ColumnId = ColumnId
THIS-OBJECT:Description = Description
THIS-OBJECT:Detail = Detail
.
END CONSTRUCTOR.
Thank you!
Sebastien
Yes - the format is:
CONSTRUCTOR PUBLIC ErrorItem(variable list):
THIS-OBJECT(local variable list).
/* Stuff */
END CONSTRUCTOR.
Also the "THIS-OBJECT" call has to be the first statement in the constructor.
Related
I've been trying to dynamically use a PostgreSQL 13 native query:
public interface TasksRepository extends JpaRepository<Task, Long>, JpaSpecificationExecutor<Task> {
}
#AllArgsConstructor
public class TaskSpecification implements Specification<Task> {
private final String entityCode;
private final UUID entityId;
#Override
public Predicate toPredicate(Root<Task> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
// see https://www.postgresql.org/docs/13/functions-json.html
// jsonb_path_exists ( target jsonb, path jsonpath [, vars jsonb [, silent boolean ]] ) → boolean
String template = "$[*] ? (#.entityCode == $code && #.entityId == $id)";
String variable = "{\"code\":\"?1\", \"id\":\"?2\"}"
.replace("?1", this.entityCode)
.replace("?2", this.entityId.toString());
return builder.isTrue(
builder.function("jsonb_path_exists", Boolean.class,
/* target */ root.<List<RelatedEntity>>get("taskTags"),
/* path */ builder.literal("'" + template + "'::jsonpath"), //DEBUG CAST
/* vars */ builder.literal("'" + variable + "'::jsonb"), //DEBUG CAST
/* silent */ builder.literal(Boolean.FALSE)
));
}
}
But ended up with traumatic errors, despite my casting attempt:
Hibernate:
select
task0_.id as id1_0_,
task0_.business_unit as business2_0_,
task0_.due_date as due_date3_0_,
task0_.is_urgent as is_urgen4_0_,
task0_.task_tags as task_tag5_0_,
task0_.task_text as task_tex6_0_,
task0_.task_type as task_typ7_0_
from
tasks_table task0_
where
jsonb_path_exists(task0_.task_tags,?,?,?)=true
binding parameter [1] as [VARCHAR] - ['$[*] ? (#.entityCode == $code && #.entityId == $id)'::jsonpath]
binding parameter [2] as [VARCHAR] - ['{"code":"ETY", "id":"bedb1903-3827-4507-883b-d41888d2ed68"}'::jsonb]
binding parameter [3] as [BOOLEAN] - [false]
SQL Error: 0, SQLState: 42883
ERROR: function jsonb_path_exists(jsonb, character varying, character varying, boolean) does not exist
Indice : No function matches the given name and argument types. You might need to add explicit type casts.
I've tried to cast the above inner query parameters, but I suspect that this is a JPA-level issue; but I couldn't find the corresponding types to cast (jsonpath, jsonb) in my dependencies for them to applied with builder/Expression#as
Maybe the function is not visible (with schema issue or something alike?)
Thanks for any help
Try removing the cast ::jsonpath and give it a try.
A json path is not a data type, so no need for the cast. Instead this part root.<List<RelatedEntity>>get("taskTags") shoud be a valid json object, I am not sure how this is rendered in the query.
To verify what is rendered and the values binded to the query, enable logging for hibernate as such in application.properties;
logging.level.org.hibernate.SQL=trace
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace
This will show you the query and the value passed in the query.
I would like to write javadoc in Eclipse.
I have this piece of code:
private int variable;
When I want to add #value parametar in Eclipse above line I get {#value} instead of #value. When I want to add #author, I get output without {} brackets, as I want. How can I get #value without brackets?
Since the #value tag appears in running text, it should be in braces. It is not a tag like #author, which occurs at the end and basically considers the text up to the next (braceless) tag as its parameters.
So Eclipse's suggestion is correct. Why do you want to use that tag without braces?
The Javadoc tool will replace #value tags with the value of the constant it documents (if no parameter is given) or with the value of the constant mentioned in the parameter. For example:
/** The value {#value}. */
public static int aConstant = 1;
/**
* Does something.
* #param aValue should be {#value #aConstant}.
* #return 42
*/
public int aMethod(int aValue) {
...
}
I have the following function that works fine:
Function GetAgentEmailWorksheet(AgentObjectId As String)
Dim specific_agent As clsAgent
Set specific_agent = New clsAgent
specific_agent.AgentSheetName = "agentsFullOutput.csv"
Dim id_array() As Variant
id_array = specific_agent.AgentIDArray
Dim email_array() As Variant
email_array = specific_agent.AgentEmailArray
GetAgentEmailWorksheet = vlook_using_array(AgentObjectId, id_array, email_array)
End Function
When, however, I change the last line to:
GetAgentEmailWorksheet = vlook_using_array(AgentObjectId, specific_agent.AgentIDArray, specific_agent.AgentEmailArray)
I get the following error:
Compile error:
Type mismatch:array or user-defined type expected
and it hi-lights AgentIDArray (or AgentEmailArray if I sub out the first parameter.
Why?
EDIT
here's the fuction vlook_using_array:
Function vlook_using_array(target_string As String, _
input_array() As Variant, _
output_array() As Variant)
Dim rows_dim As Long
Dim cols_dim As Integer
For rows_dim = 1 To UBound(input_array, 1)
For cols_dim = 1 To UBound(input_array, 2)
If input_array(rows_dim, cols_dim) = target_string Then
vlook_using_array = output_array(rows_dim, cols_dim)
End If
Next cols_dim
Next rows_dim
End Function
Here are the clsAgent properties:
Public Property Get AgentClientsArray() As Variant
AgentClientsArray = get_column_array(AgentClientsCol)
End Property
Public Property Get AgentIDArray() As Variant
AgentIDArray = get_column_array(1)
End Property
Public Property Get AgentEmailArray() As Variant
AgentEmailArray = get_column_array(AgentEmailCol)
End Property
Here's the function that's in the class module:
Private Function get_column_array(col_num As Integer) As Variant
' create a range out of the used range (of the sheet) in the column specified
' used to create array properties in the class
Dim total_rows As Long
total_rows = Worksheets(Me.AgentSheetName).UsedRange.rows.Count
Dim target_range As Range
With Worksheets(Me.AgentSheetName)
Set target_range = .Range(.Cells(1, col_num), .Cells(total_rows, col_num))
End With
Dim target_arr() As Variant
target_arr = target_range
get_column_array = target_arr
End Function
There's a difference between this:
Public Property Get AgentIDArray() As Variant
AgentIDArray = get_column_array(1)
End Property
and
Public Property Get AgentIDArray() As Variant()
AgentIDArray = get_column_array(1)
End Property
The first (which you have in your class) returns a Variant which happens to be an array, the second an array of variants.
So, the return value of your AgentIDArray is not consistent with the parameter types expected by vlook_using_array
I am trying to implement System.Collections.IComparer in Progress 4gl.
With the following code, I get the error:
Incompatible data types in expression or assignement. (223)
CLASS Tools.Comparer.ItemByItemNo IMPLEMENTS System.Collections.IComparer:
METHOD PUBLIC INTEGER Compare(
INPUT o1 AS System.Object
,INPUT o2 AS System.Object):
/* declaration */
DEFINE VARIABLE oItem1 AS Entity.Item NO-UNDO.
DEFINE VARIABLE oItem2 AS Entity.Item NO-UNDO.
/* cast */
ASSIGN oItem1 = CAST(o1, "Entity.Item").
ASSIGN oItem2 = CAST(o2, "Entity.Item").
/* compare */
RETURN Tools.String:Compare(oItem1:ItemNo, oItem2:ItemNo).
END METHOD.
END CLASS.
Is it possible to cast a class from System.Object?
Thank you! Sebastien
/* Here the code of compare to mimic the .NET compare in progress */
METHOD STATIC PUBLIC INTEGER Compare(
INPUT String1 AS CHARACTER
,INPUT String2 AS CHARACTER):
IF string1 < string2 THEN
RETURN -1.
ELSE IF string1 = string2 THEN
RETURN 0.
ELSE IF string1 > string2 THEN
RETURN 1.
END METHOD.
From the Knowledge Base:
Cause
This is expected behavior. The code is trying to assign an ABL class into a property whose type is System.Object. This cannot be done. The compiler error is correct (incompatible types). All .NET classes inherit from System.Object, which in turn inherits from Progress.Lang.Object, but ABL classes do not inherit from System.Object, i.e. the hierarchy is:
P.L.O
|
<user-defined class>
Workaround
In order to be able to assign an ABL class into a System.Object, it must inherit from System.Object:
P.L.O
|
S.O
|
<.NET classes>
Sample Code
USING Progress.Lang.*.
USING System.*.
CLASS a INHERITS Object:
...
END CLASS.
See this knowledgebase entry for a complete description
I have created two classes as interface / implementation classes, and wish to pass a particular example of one class to a method in the other. The definitions are as follows...
Class BigInt...
Option Explicit
Public Sub dothing(ByRef passed_object As MyInt)
End Sub
and an implementation BigImplementation...
Option Explicit
Implements BigInt
Public Sub BigInt_dothing(ByRef passed_obj As MyInt)
Dim i As Integer
i = passed_obj.getprop
End Sub
The class I am planning to pass is...
Option Explicit
Public Property Get getprop() As Integer
End Property
Public Property Let letprop(ByVal myval As Integer)
End Property
implemented as MyImplementation thus...
Option Explicit
Implements MyInt
Private myval As Integer
Public Property Get myint_getprop() As Integer
myint_getprop = myval
End Property
Public Property Let myint_letprop(ByVal passed_int As Integer)
myval = passed_int
End Property
I am then driving this with the following snippet of code:-
Private Sub Command_Click()
Dim myobj As MyInt
Set myobj = New MyImplementation
Dim mybigobj As BigInt
Set mybigobj = New BigImplementation
myobj.letprop = 1
Call mysub(myobj)
mybigobj.dothing (myobj) ' Line with problem
End Sub
Private Sub mysub(ByVal passed_obj As MyInt)
Dim i As Integer
i = passed_obj.getprop
End Sub
When the execution reaches the line marked, I get run-time error 438 - Object doesn't support property or method. The call to the ordinary function mysub works perfectly. Does anyone know what I am doing wrong and what I need to do to fix this?
Use either
mybigobj.dothing myobj
or
Call mybigobj.dothing(myobj)
Putting extra parentheses around a reference evaluates its default property and passes it's value as actual argument.
mybigobj.dothing requires its parameter to be a MyInt
Public Sub BigInt_dothing(ByRef passed_obj As MyInt)
Dim i As Integer
i = passed_obj.getprop
End Sub
You're passing a MyImplementation
Set myobj = New MyImplementation
So possiblly something like (my vb is rusty)
mybigobj.dothing (myobj.myint_getprop())