Kotlin Code using org.objectweb.asm library
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes.*
fun main(args: Array<String>) {
val classWriter = ClassWriter(ClassWriter.COMPUTE_MAXS)
classWriter.visit(
V1_8,
ACC_PUBLIC,
"com/github/patrick/learnasm/build/HelloWorld",
null,
"java/lang/Object",
null
)
val methodVisitor = classWriter.visitMethod(
ACC_PUBLIC + ACC_STATIC,
"main",
"([Ljava/lang/String;)V",
null,
null
)
methodVisitor.visitFieldInsn(
GETSTATIC,
"java/lang/System",
"out",
"Ljava/io/PrintStream;"
)
methodVisitor.visitLdcInsn(
"Hello World!"
)
methodVisitor.visitMethodInsn(
INVOKEVIRTUAL,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V",
false
)
methodVisitor.visitInsn(
RETURN
)
methodVisitor.visitMaxs(
0,
0
)
methodVisitor.visitEnd()
val bytes = classWriter.toByteArray()
val clazz = defineClass(
"com.github.patrick.learnasm.build.HelloWorld",
bytes,
0,
bytes.count()
)
clazz.getDeclaredMethod("main", Array<String>::class.java).invoke(null, null)
}
I am trying to learn asm, and I'm curious whether creating a method with named parameter is possible.
For example in this case, the created class has no parameter name (defaults to var0 in decompiler), and I wish I could save parameter names like "args". Would it be possible?
Found an answer by looking into compiled class (by including debugging information)
The simple way is to just mock the compiled class
All I had to do is put some label on it, and visit local variable with name.
methodVisitor = classWriter.visitMethod(
Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
"main",
"([Ljava/lang/String;)V",
null,
null
)
methodVisitor.visitParameterAnnotation(
0,
"Lorg.jetbrains.annotations.NotNull;",
false
)
val start = Label()
methodVisitor.visitLabel(start)
methodVisitor.visitFieldInsn(
Opcodes.GETSTATIC,
"java/lang/System",
"out",
"Ljava/io/PrintStream;"
)
methodVisitor.visitLdcInsn("Hello World!")
methodVisitor.visitMethodInsn(
Opcodes.INVOKEVIRTUAL,
"java/io/PrintStream",
"println",
"(Ljava/lang/String;)V",
false
)
methodVisitor.visitInsn(Opcodes.RETURN)
val end = Label()
methodVisitor.visitLabel(end)
methodVisitor.visitLocalVariable(
"args",
"[Ljava/lang/String;",
null,
start,
end,
0
)
methodVisitor.visitMaxs(0, 0)
methodVisitor.visitEnd()
take the following two tables as given:
Objects with columns objId, objTaxonId
Taxa with columns taxId, taxValidSynonymId, taxName (Note Taxa is plural for Taxon)
if a Taxon is valid, its id and validSynonymId are identical, otherwise they are different. To find all synonyms of a Taxon you 'only' need to find all Taxa where the taxValidSynonymId is filled with the taxId of the valid Taxon
how can i gain all Objects where the Taxon has a given Name (including their Synonyms?)
in SQL this is done in a few lines (and Minutes)
SELECT *
FROM Objects
WHERE objTaxonId IN (
SELECT taxId
FROM Taxa
WHERE taxName LIKE 'Test Taxon 1'
OR taxSynIdTaxon IN(
SELECT taxId
FROM Taxa
WHERE taxName LIKE 'Test Taxon 1'
)
)
i was able to work out the inside part, where i gain the list of Taxa and its Synonyms. Now i need to transform this Query to a Subquery...
String NAME_LIKE = "Test Taxon 1";
EntityManager em = EntityManagerProvider.getEntityManager("TestDB"); // get the EntityManager
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaxonImpl> cqObject = cb.createQuery(TaxonImpl.class);//
Root<TaxonImpl> taxonRoot = cqObject.from(TaxonImpl.class);//
Expression<String> taxon_name = taxonRoot.<String> get("taxName");
Predicate where = cb.equal(taxon_name, NAME_LIKE);
// subquery
Subquery<Integer> subQuery = cqObject.subquery(Integer.class);
Root<TaxonImpl> subRoot = subQuery.from(clsImpl);
subQuery.select(subRoot.<Integer> get("taxId"));
subQuery.where(cb.equal(subRoot.<String> get("taxName"), NAME_LIKE));
where = cb.or(where, taxonRoot.get("taxValidSynonymId").in(subQuery));
cqObject.where(where);
Query query = em.createQuery(cqObject);
List<TaxonImpl> result = query.getResultList();
NOTE: the Taxon is Mapped as an many to One relation (target-entity is TaxonImpl)
in my actual application the code (from the subquery) will be dynamically, so a Native Query does not help me.
i figured out how to "transform" the subquery into a query but Eclipselink threw me two errors
the first was forbidden access via field, when i tried the in on a result of TaxonImpl (i tried that first, as in my mapping files the Taxon is mapped as Entity.
so after this i tried to form the SQL 1:1 to JPA.
but Eclipselink generated something weird:
SELECT t0.objIdObject, t0.objAdminCreated, t0.objAdminCreator, t0.objAdminEdited, t0.objAdminEditor, t0.objAdminImport1, t0.objAdminImport2, t0.objAddBool1, t0.objAddBool2, t0.objAddBool3, t0.objAddBool4, t0.objAddBool5, t0.objAddDateTime1, t0.objAddDateTime2, t0.objCommonComments, t0.objCommonDescription, t0.objCommonKeywords, t0.objCommonName, t0.objCommonPublished, t0.objCommonPublishedAs, t0.objCommonStatus, t0.objCommonType, t0.objCommonTypustype, t0.objDetAccuracy, t0.objDetCf, t0.objDetComments, t0.objDetDate, t0.objDetMethod, t0.objDetResult, t0.objAddFloat1, t0.objAddFloat2, t0.objAddFloat3, t0.objAddFloat4, t0.objAddFloat5, t0.objEventAbundance, t0.objEventCollectionMethod, t0.objEventComments, t0.objEventMoreContacts, t0.objEventDateDay1, t0.objEventDate1, t0.objEventDateMonth1, t0.objEventDate2, t0.objEventDateUncertain, t0.objEventDateYear1, t0.objEventEcosystem, t0.objEventHabitat, t0.objEventNumber, t0.objEventPermission, t0.objEventSubstratum, t0.objEventTime1, t0.objEventTime2, t0.objEventWeekNumber, t0.objFlora, t0.objGuidObject, t0.objIOComments, t0.objIODeAccessed, t0.objAddInt1, t0.objAddInt2, t0.objAddInt3, t0.objAddInt4, t0.objAddInt5, t0.objStorageForeignNumber, t0.objStorageNumber, t0.objStorageNumberInCollection, t0.objStorageNumberOld, t0.objStorageNumberPrefix, t0.objAddLkp1, t0.objAddLkp10, t0.objAddLkp2, t0.objAddLkp3, t0.objAddLkp4, t0.objAddLkp5, t0.objAddLkp6, t0.objAddLkp7, t0.objAddLkp8, t0.objAddLkp9, t0.objAddLkpCs1, t0.objAddLkpCs10, t0.objAddLkpCs11, t0.objAddLkpCs12, t0.objAddLkpCs13, t0.objAddLkpCs14, t0.objAddLkpCs15, t0.objAddLkpCs2, t0.objAddLkpCs3, t0.objAddLkpCs4, t0.objAddLkpCs5, t0.objAddLkpCs6, t0.objAddLkpCs7, t0.objAddLkpCs8, t0.objAddLkpCs9, t0.objOriginAccessionDate, t0.objOriginAccessionNumber, t0.objOriginComments, t0.objOriginMoreContacts, t0.objOriginSource, t0.objOriginType, t0.objPreparationComments, t0.objPreparationDate, t0.objPreparationType, t0.objPropAdults, t0.objPropAge, t0.objPropAgeUnit, t0.objPropEggs, t0.objPropFemale, t0.objPropHeight, t0.objPropHeightUnit, t0.objPropJuveniles, t0.objPropLarvae, t0.objPropLength, t0.objPropLengthUnit, t0.objPropMale, t0.objPropObservation, t0.objPropObservationComments, t0.objPropPupae, t0.objPropSex, t0.objPropStadium, t0.objPropWeight, t0.objPropWeightUnit, t0.objPropWidth, t0.objPropWidthUnit, t0.objSiteComments, t0.objStorageComments, t0.objStorageContainerNumber, t0.objStorageContainerPieces, t0.objStorageContainerType, t0.objStorageLevel1, t0.objStorageLevel2, t0.objStorageLevel3, t0.objStorageLevel4, t0.objStorageLevel5, t0.objStorageNumberInContainer, t0.objstoragePieces, t0.objStorageValue, t0.objStorageValueUnit, t0.objAddText1, t0.objAddText10, t0.objAddText2, t0.objAddText3, t0.objAddText4, t0.objAddText5, t0.objAddText6, t0.objAddText7, t0.objAddText8, t0.objAddText9, t0.objIdCollection, t0.objCommonIdReference, t0.objDetIdContact, t0.objDetIdReference, t0.objEventIdContact, t0.objIdExcursion, t0.objOriginIdContact, t0.objPreparationIdContact, t0.objIdProject, t0.objSiteIdSite, t0.objdetIdTaxon
FROM tObjects t0
WHERE t0.objdetIdTaxon IN (
SELECT t1.taxIdTaxon.t1.taxIdTaxon
FROM tTaxa t1
WHERE (t1.taxTaxonDisplay LIKE 'Test Taxon 1'
OR t1.taxSynIdTaxon IN (
SELECT t2.taxSynIdTaxon
FROM tTaxa t2
WHERE t2.taxTaxonDisplay LIKE 'Test Taxon 1')))
to take out the error:
SELECT t1.taxIdTaxon.t1.taxIdTaxon
which is complete crap. you cannot execute a function on an type of int!
resolving this error (BUG?) introduces a new construct (which still returns the same results)
SELECT t1.objIdObject, t1.objAdminCreated, t1.objAdminCreator, t1.objAdminEdited, t1.objAdminEditor, t1.objAdminImport1, t1.objAdminImport2, t1.objAddBool1, t1.objAddBool2, t1.objAddBool3, t1.objAddBool4, t1.objAddBool5, t1.objAddDateTime1, t1.objAddDateTime2, t1.objCommonComments, t1.objCommonDescription, t1.objCommonKeywords, t1.objCommonName, t1.objCommonPublished, t1.objCommonPublishedAs, t1.objCommonStatus, t1.objCommonType, t1.objCommonTypustype, t1.objDetAccuracy, t1.objDetCf, t1.objDetComments, t1.objDetDate, t1.objDetMethod, t1.objDetResult, t1.objAddFloat1, t1.objAddFloat2, t1.objAddFloat3, t1.objAddFloat4, t1.objAddFloat5, t1.objEventAbundance, t1.objEventCollectionMethod, t1.objEventComments, t1.objEventMoreContacts, t1.objEventDateDay1, t1.objEventDate1, t1.objEventDateMonth1, t1.objEventDate2, t1.objEventDateUncertain, t1.objEventDateYear1, t1.objEventEcosystem, t1.objEventHabitat, t1.objEventNumber, t1.objEventPermission, t1.objEventSubstratum, t1.objEventTime1, t1.objEventTime2, t1.objEventWeekNumber, t1.objFlora, t1.objGuidObject, t1.objIOComments, t1.objIODeAccessed, t1.objAddInt1, t1.objAddInt2, t1.objAddInt3, t1.objAddInt4, t1.objAddInt5, t1.objStorageForeignNumber, t1.objStorageNumber, t1.objStorageNumberInCollection, t1.objStorageNumberOld, t1.objStorageNumberPrefix, t1.objAddLkp1, t1.objAddLkp10, t1.objAddLkp2, t1.objAddLkp3, t1.objAddLkp4, t1.objAddLkp5, t1.objAddLkp6, t1.objAddLkp7, t1.objAddLkp8, t1.objAddLkp9, t1.objAddLkpCs1, t1.objAddLkpCs10, t1.objAddLkpCs11, t1.objAddLkpCs12, t1.objAddLkpCs13, t1.objAddLkpCs14, t1.objAddLkpCs15, t1.objAddLkpCs2, t1.objAddLkpCs3, t1.objAddLkpCs4, t1.objAddLkpCs5, t1.objAddLkpCs6, t1.objAddLkpCs7, t1.objAddLkpCs8, t1.objAddLkpCs9, t1.objOriginAccessionDate, t1.objOriginAccessionNumber, t1.objOriginComments, t1.objOriginMoreContacts, t1.objOriginSource, t1.objOriginType, t1.objPreparationComments, t1.objPreparationDate, t1.objPreparationType, t1.objPropAdults, t1.objPropAge, t1.objPropAgeUnit, t1.objPropEggs, t1.objPropFemale, t1.objPropHeight, t1.objPropHeightUnit, t1.objPropJuveniles, t1.objPropLarvae, t1.objPropLength, t1.objPropLengthUnit, t1.objPropMale, t1.objPropObservation, t1.objPropObservationComments, t1.objPropPupae, t1.objPropSex, t1.objPropStadium, t1.objPropWeight, t1.objPropWeightUnit, t1.objPropWidth, t1.objPropWidthUnit, t1.objSiteComments, t1.objStorageComments, t1.objStorageContainerNumber, t1.objStorageContainerPieces, t1.objStorageContainerType, t1.objStorageLevel1, t1.objStorageLevel2, t1.objStorageLevel3, t1.objStorageLevel4, t1.objStorageLevel5, t1.objStorageNumberInContainer, t1.objstoragePieces, t1.objStorageValue, t1.objStorageValueUnit, t1.objAddText1, t1.objAddText10, t1.objAddText2, t1.objAddText3, t1.objAddText4, t1.objAddText5, t1.objAddText6, t1.objAddText7, t1.objAddText8, t1.objAddText9, t1.objIdCollection, t1.objCommonIdReference, t1.objDetIdContact, t1.objDetIdReference, t1.objEventIdContact, t1.objIdExcursion, t1.objOriginIdContact, t1.objPreparationIdContact, t1.objIdProject, t1.objSiteIdSite, t1.objdetIdTaxon
FROM tTaxa t0, tObjects t1
WHERE (
t0.taxIdTaxon IN (
SELECT t2.taxIdTaxon
FROM tTaxa t2
WHERE (t2.taxTaxonDisplay LIKE 'Test Taxon 1'
OR t2.taxSynIdTaxon IN (
SELECT t3.taxSynIdTaxon
FROM tTaxa t3
WHERE t3.taxTaxonDisplay LIKE 'Test Taxon 1'
)
)
) AND (t0.taxIdTaxon = t1.objdetIdTaxon)
)
this seems strange to me, but it is working - and it is faster than my alternative query, which includes a inner join
NOTE: Eclipselink does ignore the JoinType. regardless what you pass it takes an left outer join. (documentation says something else!)
finally i provide the two examples for join and joinless
private static Predicate addSynonymsWithJoins(Root<BioObjectImpl> r, CriteriaBuilder b, CriteriaQuery cq,
Attribute attr, Path path, Object value) {
Join taxJoin = r.join(BioObjectEnum.taxon.name(), JoinType.INNER);
Path<Object> taxValidSynonymId = taxJoin.get(TaxonEnum.validSynonymId.name());
Subquery<TaxonImpl> innerSubquery = cq.subquery(TaxonImpl.class);
Root fromSubTax = innerSubquery.from(TaxonImpl.class);
innerSubquery.select(fromSubTax.<Integer> get(TaxonEnum.id.name()));
Predicate dynamic1 = cb.like(fromSubTax.get(TaxonEnum.name.name()),
NAME_LIKE);
innerSubquery.where(dynamic1);
Predicate dynamic2 = resolveComparator(b, attr, taxJoin.get(attr.getPropertyName()), attr.getValue());//
Predicate p = b.or(taxValidSynonymId.in(innerSubquery), dynamic2);
return p;
}
private static Predicate addSynonymsWithoutJoins(Root<BioObjectImpl> r, CriteriaBuilder b, CriteriaQuery cq,
Attribute attr, Path path, Object value) {
cq.select(r);
Path<Integer> objTaxonId = r.<Integer> get(BioObjectEnum.taxon.name()).get(TaxonEnum.id.name());
Subquery<Integer> t2 = cq.subquery(Integer.class);
Root<TaxonImpl> t2fromTaxon = t2.from(TaxonImpl.class);
Path<Integer> t2taxId = t2fromTaxon.<Integer> get(TaxonEnum.validSynonymId.name());
t2.select(t2taxId);
Predicate t2dynamicWhere = resolveComparator(b, attr, t2fromTaxon.get(attr.getPropertyName()), attr.getValue());
t2.where(t2dynamicWhere);
Subquery<Integer> t1 = cq.subquery(Integer.class);
Root<TaxonImpl> t1fromTaxon = t1.from(TaxonImpl.class);
Predicate t1dynamicWhere = b.like(fromSubTax.get(TaxonEnum.name.name()),
NAME_LIKE);
Path<Integer> t1Select = t1fromTaxon.<Integer> get(TaxonEnum.id.name());
t1.select(t1Select);
Path<Integer> t1TaxSynonymId = t1fromTaxon.<Integer> get(TaxonEnum.validSynonymId.name());
t1dynamicWhere = b.or(t1dynamicWhere, t1TaxSynonymId.in(t2));
t1.where(t1dynamicWhere);
Predicate where = objTaxonId.in(t1);
return where;
}
We've been using Esproc with our BIRT reports for a while now and everything worked perfectly. We followed this tutorial and things worked. However, the latest version of their software incorporated a couple of new functionalities and as such, we now need to upgrade the version running with BIRT. The thing is that now, nothing's working. We keep getting NullPointerException when trying to run reports. This is what we're getting so far:
The following report will be sent to Eclipse:
------
STATUS
------
pluginId org.eclipse.jface
pluginVersion 3.12.0.v20160518-1929
code 2
severity 4
message Problems occurred when invoking code from plug-in: "org.eclipse.jface".
fingerprint eb22eddc61b2abbaef12193bb7441fab
Exception:java.lang.NullPointerException: null
at com.esproc.jdbc.Server.getDfxList(Unknown Source:88)
at com.esproc.jdbc.InternalConnection.getMetaData(Unknown Source:314)
at org.eclipse.birt.report.data.oda.jdbc.ui.provider.JdbcMetaDataProvider.isSupportSchema(JdbcMetaDataProvider.java:305)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createDBMetaDataSelectionComposite(SQLDataSetEditorPage.java:405)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createPageControl(SQLDataSetEditorPage.java:334)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createPageCustomControl(SQLDataSetEditorPage.java:307)
at org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSetWizardPage.createControl(DataSetWizardPage.java:123)
at org.eclipse.datatools.connectivity.oda.design.internal.ui.DataSetEditorPageCore.createContents(DataSetEditorPageCore.java:74)
at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:241)
at org.eclipse.birt.report.designer.data.ui.dataset.PropertyPageWrapper.createPageControl(PropertyPageWrapper.java:61)
at org.eclipse.birt.report.designer.data.ui.property.PropertyNode.createPageControl(PropertyNode.java:238)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.showPage(AbstractPropertyDialog.java:577)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.showSelectionPage(AbstractPropertyDialog.java:482)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.showSelectionPage(DataSetEditor.java:913)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog$2$1.run(AbstractPropertyDialog.java:438)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog$2.selectionChanged(AbstractPropertyDialog.java:433)
at org.eclipse.jface.viewers.Viewer$1.run(Viewer.java:158)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:155)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2191)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1728)
at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:1077)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:383)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.initTreeSelection(AbstractPropertyDialog.java:408)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.createDialogArea(AbstractPropertyDialog.java:299)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.createDialogArea(DataSetEditor.java:124)
at org.eclipse.jface.dialogs.Dialog.createContents(Dialog.java:767)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.createContents(DataSetEditor.java:602)
at org.eclipse.jface.window.Window.create(Window.java:426)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1095)
at org.eclipse.birt.report.designer.ui.dialogs.BaseDialog.open(BaseDialog.java:107)
at org.eclipse.birt.report.designer.data.ui.actions.EditDataSetAction.doAction(EditDataSetAction.java:105)
at org.eclipse.birt.report.designer.internal.ui.views.actions.AbstractElementAction.run(AbstractElementAction.java:70)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4410)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4228)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3816)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:687)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:604)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(null:-2)
at sun.reflect.NativeMethodAccessorImpl.invoke(null:-1)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(null:-1)
at java.lang.reflect.Method.invoke(null:-1)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
------
REPORT
------
anonymousId 12355fbc-cb0f-41c4-b330-1d4a60fd5df2
name
email
comment
eclipseBuildId 4.6.0.I20160606-1100
eclipseProduct org.eclipse.epp.package.reporting.product
javaRuntimeVersion 1.8.0_71-b15
osgiWs win32
osgiOs Windows10
osgiOsVersion 10.0.0
osgiArch x86_64
severity UNKNOWN
-------
BUNDLES
-------
name org.eclipse.birt.report.data.oda.jdbc.ui
version 4.6.0.v201606072122
name org.eclipse.birt.report.data.oda.jdbc
version 4.6.0.v201606072122
name org.eclipse.birt
version 4.6.0.v201606072122
name org.eclipse.birt.report.designer.ui
version 4.6.0.v201606072122
name org.eclipse.birt.report.designer.ui.views
version 4.6.0.v201606072122
name org.eclipse.core.databinding.observable
version 1.6.0.v20160511-1747
name org.eclipse.core.databinding
version 1.6.0.v20160412-0910
name org.eclipse.core.runtime
version 3.12.0.v20160606-1342
name org.eclipse.datatools.connectivity.oda.design.ui
version 3.3.0.201603142002
name org.eclipse.datatools.connectivity.oda.design
version 3.4.0.201603142002
name org.eclipse.datatools.connectivity.oda
version 3.5.0.201603142002
name org.eclipse.datatools.connectivity
version 1.13.0.201603142002
name org.eclipse.e4.ui.workbench
version 1.4.0.v20160517-1624
name org.eclipse.e4.ui.workbench.swt
version 0.14.0.v20160523-1900
name org.eclipse.equinox.app
version 1.3.400.v20150715-1528
name org.eclipse.equinox.launcher
version 1.3.200.v20160318-1642
name org.eclipse.jface
version 3.12.0.v20160518-1929
name org.eclipse.swt
version 3.105.0.v20160603-0902
name org.eclipse.ui
version 3.108.0.v20160518-1929
name org.eclipse.ui.ide.application
version 1.1.100.v20160518-1929
name org.eclipse.ui.ide
version 3.12.0.v20160601-1609
Anyone has any idea what's going on?
Thanks
Okay, so I was able to actually get things working and the solution isn't exactly what I'd call trivial. I actually had to modify and recompile three BIRT classes. You can easily get the source code here if you don't want to do the Google search. Anyway, our first modification is given to us by the error message cited above. We need to alter JdbcMetaDataProvider.java located in the org.eclipse.birt.report.data.oda.jdbc.ui_4.6.0.v201606072122.jar package. What we're looking for is the isSupportSchema() method. and more specifically this bit of code:
try
{
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( SQLException e )
{
try
{
reconnect( );
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( Exception e1 )
{
try
{
ResultSet rs = connection.getMetaData( ).getSchemas( );
if( rs != null )
return true;
else
return false;
}
catch (SQLException e2)
{
logger.log( Level.WARNING, e.getMessage( ), e1 );
return false;
}
}
}
Not having access to Esproc's code, I can't exactly say why it does this, but connection.getMetaData( ).supportsSchemasInTableDefinitions( ); throws a NullPointerException. With no "catch" block to treat said exception, Eclipse will just stop its execution and prevent you from accessing your dataset. So we need to fix that like so:
try
{
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( SQLException e )
{
try
{
reconnect( );
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( Exception e1 )
{
try
{
ResultSet rs = connection.getMetaData( ).getSchemas( );
if( rs != null )
return true;
else
return false;
}
catch (SQLException e2)
{
logger.log( Level.WARNING, e.getMessage( ), e1 );
return false;
}
}
}
catch (NullPointerException e)
{
return false;
}
Now then, the next two bits of code we need to alter are located in the oda-jdbc.jar package. The first one we're looking for is the Connection.java class and more specifically the method populateConnectionProp( ).
private void populateConnectionProp( ) throws SQLException
{
if( jdbcConn!= null )
{
if( this.autoCommit != null )
jdbcConn.setAutoCommit( this.autoCommit );
else
{
if (DBConfig.getInstance().qualifyPolicy(
jdbcConn.getMetaData().getDriverName(),
DBConfig.SET_COMMIT_TO_FALSE) ) {
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
if( this.isolationMode!= Constants.TRANSCATION_ISOLATION_DEFAULT)
jdbcConn.setTransactionIsolation( this.isolationMode );
}
}
This time the culprit throwing a NullPointerException is this line jdbcConn.getMetaData().getDriverName(). Again, not having access to Esproc's code, I don't really know why trying to recover the driver's name doesn't work, but anyway all we need to do is actually catch the exception and things will work normally again:
private void populateConnectionProp( ) throws SQLException
{
if( jdbcConn!= null )
{
if( this.autoCommit != null )
jdbcConn.setAutoCommit( this.autoCommit );
else
{
try
{
if (DBConfig.getInstance().qualifyPolicy(
jdbcConn.getMetaData().getDriverName(),
DBConfig.SET_COMMIT_TO_FALSE) ) {
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
catch(NullPointerException e)
{
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
if( this.isolationMode!= Constants.TRANSCATION_ISOLATION_DEFAULT)
jdbcConn.setTransactionIsolation( this.isolationMode );
}
}
The other class we're looking for is the CallStatement.java class. In it we're going to have to locate the getCallableParamMetaData() method that I've pasted below:
private java.util.List getCallableParamMetaData( )
{
java.util.List paramMetaDataList = new ArrayList( );
try
{
DatabaseMetaData metaData = conn.getMetaData( );
String cataLog = conn.getCatalog( );
String procedureNamePattern = getNamePattern( this.paramUtil.getProcedure( ) );
String schemaPattern = null;
if ( this.paramUtil.getSchema( ) != null )
{
schemaPattern = getNamePattern( this.paramUtil.getSchema( ) );
}
// handles schema.package.storedprocedure for databases such as
// Oracle
if ( !metaData.supportsCatalogsInProcedureCalls( ) )
{
if (this.paramUtil.getPackage( ) != null)
{
cataLog = getNamePattern( this.paramUtil.getPackage( ) );
}
}
java.sql.ResultSet rs = null;
rs = metaData.getProcedureColumns( cataLog,
schemaPattern,
procedureNamePattern,
null );
while ( rs.next( ) )
{
ParameterDefn p = new ParameterDefn( );
p.setParamName( rs.getString( "COLUMN_NAME" ) );
p.setParamInOutType( rs.getInt( "COLUMN_TYPE" ) );
p.setParamType( rs.getInt( "DATA_TYPE" ) );
p.setParamTypeName( rs.getString( "TYPE_NAME" ) );
p.setPrecision( rs.getInt( "PRECISION" ) );
p.setScale( rs.getInt( "SCALE" ) );
p.setIsNullable( rs.getInt( "NULLABLE" ) );
if ( p.getParamType( ) == Types.OTHER )
correctParamType( p );
paramMetaDataList.add( p );
}
rs.close( );
}
catch ( SQLException e )
{
logger.log( Level.SEVERE, "Fail to get SP paramters", e );
}
catch( JDBCException ex)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex );
}
return paramMetaDataList;
}
Basically, somewhere within the while ( rs.next( ) ) loop lies the culprit throwing the NullPointerException. So all we need to do to is add a catch statement to treat it as follow:
private java.util.List getCallableParamMetaData( )
{
java.util.List paramMetaDataList = new ArrayList( );
try
{
DatabaseMetaData metaData = conn.getMetaData( );
String cataLog = conn.getCatalog( );
String procedureNamePattern = getNamePattern( this.paramUtil.getProcedure( ) );
String schemaPattern = null;
if ( this.paramUtil.getSchema( ) != null )
{
schemaPattern = getNamePattern( this.paramUtil.getSchema( ) );
}
// handles schema.package.storedprocedure for databases such as
// Oracle
if ( !metaData.supportsCatalogsInProcedureCalls( ) )
{
if (this.paramUtil.getPackage( ) != null)
{
cataLog = getNamePattern( this.paramUtil.getPackage( ) );
}
}
java.sql.ResultSet rs = null;
rs = metaData.getProcedureColumns( cataLog,
schemaPattern,
procedureNamePattern,
null );
while ( rs.next( ) )
{
ParameterDefn p = new ParameterDefn( );
p.setParamName( rs.getString( "COLUMN_NAME" ) );
p.setParamInOutType( rs.getInt( "COLUMN_TYPE" ) );
p.setParamType( rs.getInt( "DATA_TYPE" ) );
p.setParamTypeName( rs.getString( "TYPE_NAME" ) );
p.setPrecision( rs.getInt( "PRECISION" ) );
p.setScale( rs.getInt( "SCALE" ) );
p.setIsNullable( rs.getInt( "NULLABLE" ) );
if ( p.getParamType( ) == Types.OTHER )
correctParamType( p );
paramMetaDataList.add( p );
}
rs.close( );
}
catch ( SQLException e )
{
logger.log( Level.SEVERE, "Fail to get SP paramters", e );
}
catch( JDBCException ex)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex );
}
catch( NullPointerException ex1)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex1 );
}
return paramMetaDataList;
}
Once you've done your modifications to the files, you actually need to recompile your source code. To do this successfully, you're going to need to copy a couple of jars from Eclipse's plugin folder into the same folder as where you've placed the file you're trying to compile. The jars are given below in the command you need to enter to compile your source code. Here's what you need to enter in order to compile each file:
JdbcMetaDataProvider.java
javac -cp ".;
c:/mypath/org.eclipse.birt.report.data.bidi.utils_4.6.0.v201606072122.jar;
c:/mypath/org.eclipse.birt.report.data.oda.jdbc.ui_4.6.0.v201606072122.jar;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda.design_3.4.0.201603142002.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda.design.ui_3.3.0.201603142002.jar;
c:/mypath/org.eclipse.emf.ecore_2.12.0.v20160420-0247.jar;
c:/mypath/org.eclipse.emf.common_2.12.0.v20160420-0247.jar" JdbcMetaDataProvider.java > log.txt 2>&1
Connection.java
javac -cp ".;
c:/mypath/org.eclipse.birt.report.data.bidi.utils_4.6.0.v201606072122.jar;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/com.ibm.icu_56.1.0.v201601250100.jar" Connection.java > log.txt 2>&1
CallStatement.java
javac -cp ".;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/com.ibm.icu_56.1.0.v201601250100.jar" CallStatement.java > log.txt 2>&1
Now, there's a couple of things that need to be said about the two above commands:
1) They actually need to be entered on one line. I merely broke them down like so for clarity purposes so that each jar needed was easy to spot.
2) This is actually a windows command. If you're running the command on Linux, each jar needs to be separated by a colon(:) instead of a semi-colon(;).
Once the compilation is successful, you'll end up with the following .class files:
JdbcMetaDataProvider$1TempThread.class
JdbcMetaDataProvider$2TempThread.class
JdbcMetaDataProvider.class
Connection$Constants.class
Connection.class
CallStatement.class
These need to be copied back into the original jar files so that they replace the files already there. Luckily, a jar file is nothing more than a zip file so in windows, any unzipping software will easily open things up for you and allow you to navigate to the proper folder.
Here are the the folders in question for each jar:
org\eclipse\birt\report\data\oda\jdbc\ui\provider\
org\eclipse\birt\report\data\oda\jdbc\
org\eclipse\birt\report\data\oda\jdbc\
Once that's done, restart Eclipse and things should work like normal again. I hope this helps someone in the future.