Skip to content

Commit 0dedaed

Browse files
committed
Fixed generic method signature calling.
1 parent e9ac273 commit 0dedaed

File tree

4 files changed

+71
-46
lines changed

4 files changed

+71
-46
lines changed

src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ExternalEngine.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ final class ExternalEngine implements IExternalEngineIntf
7777
{
7878
private static final IEncodingFactory encodingFactory = EncodingFactory.getPlatformDefault();
7979
private static Map<String, SharedData> sharedDataMap = new ConcurrentHashMap<>();
80-
private static Map<Integer, Pair<String, Integer>> fbTypeNames;
81-
private static Map<Class<?>, DataType> dataTypesByClass;
80+
static Map<Integer, Pair<String, Integer>> fbTypeNames;
81+
static Map<Class<?>, DataType> dataTypesByClass;
8282
private static Map<String, Class<?>> javaClassesByName;
8383
private static Map<Integer, DataType> defaultDataTypes;
8484
private IExternalEngine wrapper;
@@ -1257,7 +1257,7 @@ else if (pos[0] != entryPoint.length())
12571257
{
12581258
assert outCount == 1;
12591259

1260-
if (paramTypes.size() != inCount)
1260+
if (paramTypes.size() != inCount && paramTypes.size() != 0)
12611261
{
12621262
throw new FbException(String.format("Number of parameters (%d) in the Java method " +
12631263
"does not match the number of parameters (%d) in the function declaration",
@@ -1283,7 +1283,7 @@ else if (pos[0] != entryPoint.length())
12831283

12841284
case PROCEDURE:
12851285
{
1286-
if (paramTypes.size() != inCount + outCount)
1286+
if (paramTypes.size() != inCount + outCount && paramTypes.size() != 0)
12871287
{
12881288
throw new FbException(String.format("Number of parameters (%d) in the Java method " +
12891289
"does not match the number of parameters (%d + %d) in the procedure declaration",
@@ -1327,18 +1327,6 @@ else if (pos[0] != entryPoint.length())
13271327
IMessageMetadata triggerMetadata = metadata.getTriggerMetadata(status);
13281328
try
13291329
{
1330-
int count = triggerMetadata.getCount(status);
1331-
1332-
for (int index = 0; index < count; ++index)
1333-
{
1334-
Parameter parameter = new Parameter(
1335-
dataTypesByClass.get(Object.class), Object.class);
1336-
parameter.name = triggerMetadata.getField(status, index);
1337-
parameter.type = fbTypeNames.get(triggerMetadata.getType(status, index));
1338-
1339-
routine.inputParameters.add(parameter);
1340-
}
1341-
13421330
routine.setupParameters(status, routine.inputParameters, routine.inputMetadata,
13431331
triggerMetadata, inBuilder);
13441332
}

src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/ExternalProcedure.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ public IExternalResultSet open(IStatus status, IExternalContext context, Pointer
7272
Object[] inOut = new Object[inCount + outCount];
7373
Object[] inOut2 = new Object[inCount + outCount];
7474

75-
try (InternalContext internalContext = InternalContext.create(status, context, routine,
76-
new ValuesImpl(inOut, inCount),
77-
new ValuesImpl(inOut, inCount, outCount)))
75+
boolean closeContext = true;
76+
77+
InternalContext internalContext = InternalContext.create(status, context, routine,
78+
new ValuesImpl(inOut, inCount),
79+
new ValuesImpl(inOut, inCount, outCount));
80+
81+
try
7882
{
7983
routine.getFromMessage(status, context, routine.inputParameters, inMsg, inOut);
8084

@@ -104,12 +108,19 @@ public void dispose()
104108
{
105109
try
106110
{
107-
routine.engine.runInClassLoader(status, context,
108-
routine.method.getDeclaringClass().getName(), routine.method.getName(),
109-
() -> {
110-
rs.close();
111-
return null;
112-
});
111+
try
112+
{
113+
routine.engine.runInClassLoader(status, context,
114+
routine.method.getDeclaringClass().getName(), routine.method.getName(),
115+
() -> {
116+
rs.close();
117+
return null;
118+
});
119+
}
120+
finally
121+
{
122+
internalContext.close();
123+
}
113124
}
114125
catch (Throwable t)
115126
{
@@ -153,9 +164,17 @@ public boolean fetch(IStatus status) throws FbException
153164

154165
ExtResultSet wrapped = new ExtResultSet();
155166
wrapped.wrapper = JnaUtil.pin(new IExternalResultSet(wrapped));
167+
168+
closeContext = false;
169+
156170
return wrapped.wrapper;
157171
}
158172
}
173+
finally
174+
{
175+
if (closeContext)
176+
internalContext.close();
177+
}
159178
}
160179
catch (InvocationTargetException e)
161180
{

src/fbjava-impl/src/main/java/org/firebirdsql/fbjava/impl/Routine.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static enum Type
5555
final List<Parameter> outputParameters = new ArrayList<>();
5656
final ValuesMetadataImpl inputMetadata = new ValuesMetadataImpl();
5757
final ValuesMetadataImpl outputMetadata = new ValuesMetadataImpl();
58+
boolean generic;
5859

5960
Routine(IStatus status, IRoutineMetadata metadata, ExternalEngine engine, Type type) throws FbException
6061
{
@@ -92,6 +93,23 @@ static enum Type
9293
void setupParameters(IStatus status, List<Parameter> parameters, ValuesMetadataImpl valuesMetadata,
9394
IMessageMetadata metadata, IMetadataBuilder builder) throws FbException
9495
{
96+
int count = metadata.getCount(status);
97+
98+
if (parameters.size() == 0 && count != 0)
99+
{
100+
for (int index = 0; index < count; ++index)
101+
{
102+
Parameter parameter = new Parameter(
103+
ExternalEngine.dataTypesByClass.get(Object.class), Object.class);
104+
parameter.name = metadata.getField(status, index);
105+
parameter.type = ExternalEngine.fbTypeNames.get(metadata.getType(status, index));
106+
107+
parameters.add(parameter);
108+
}
109+
110+
generic = true;
111+
}
112+
95113
for (int i = 0; i < parameters.size(); ++i)
96114
{
97115
Parameter parameter = parameters.get(i);
@@ -154,7 +172,7 @@ Object run(IStatus status, IExternalContext context, Object[] args) throws Throw
154172
() -> {
155173
try
156174
{
157-
return method.invoke(null, args);
175+
return method.invoke(null, (generic ? null : args));
158176
}
159177
catch (Exception | ExceptionInInitializerError t)
160178
{

src/fbjava-tests/src/main/java/example/Procedures.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package example;
2020

21+
import java.math.BigDecimal;
2122
import java.sql.SQLException;
2223

2324
import org.firebirdsql.fbjava.CallableRoutineContext;
@@ -52,11 +53,6 @@ public boolean fetch() throws Exception
5253
{
5354
return ++o[0] <= i + 5;
5455
}
55-
56-
@Override
57-
public void close()
58-
{
59-
}
6056
};
6157
}
6258

@@ -70,11 +66,6 @@ public boolean fetch() throws Exception
7066
{
7167
return ++o[0] <= end;
7268
}
73-
74-
@Override
75-
public void close()
76-
{
77-
}
7869
};
7970
}
8071

@@ -91,11 +82,6 @@ public boolean fetch() throws Exception
9182

9283
return ++o[0] <= end;
9384
}
94-
95-
@Override
96-
public void close()
97-
{
98-
}
9985
};
10086
}
10187

@@ -116,11 +102,6 @@ public boolean fetch() throws Exception
116102
else
117103
return false;
118104
}
119-
120-
@Override
121-
public void close()
122-
{
123-
}
124105
};
125106
}
126107

@@ -173,4 +154,23 @@ public static void p11(Object i1, Object i2, String[] o1) throws SQLException
173154

174155
output.set(1, Functions.getValues(inputMetadata, input) + " / " + Functions.getValues(outputMetadata, output));
175156
}
157+
158+
public static ExternalResultSet p12()
159+
{
160+
ProcedureContext context = ProcedureContext.get();
161+
Values outValues = context.getOutputValues();
162+
163+
BigDecimal i = (BigDecimal) context.getInputValues().get(1);
164+
outValues.set(1, i);
165+
166+
return new ExternalResultSet() {
167+
@Override
168+
public boolean fetch() throws Exception
169+
{
170+
BigDecimal o = ((BigDecimal) outValues.get(1)).add(BigDecimal.ONE);
171+
outValues.set(1, o);
172+
return o.subtract(i).intValue() <= 5;
173+
}
174+
};
175+
}
176176
}

0 commit comments

Comments
 (0)