Fw: Trying to populate the knowledge base.

48 views
Skip to first unread message

Brian Schlining

unread,
Jun 27, 2011, 12:22:24 PM6/27/11
to mbari...@googlegroups.com
Hi Andy,

Shoot, I forgot about that. The 6.0.2 release has a bad value in the key generator table. It's an easy fix though; I've attached 2 files to help you out. Here's what you do:
1) Drop the 'java.policy' file in VARS_HOME/conf
2) Drop the 'increment_uniqueid.groovy' file in VARS_HOME/scripts/groovy
3) Open a Terminal to VARS_HOME/bin
4) Run the following command:
./gsh ../scripts/groovy/increment_uniqueid.groovy

That will increment all 'nextid' values in the UniqueID table by 100. That should fix that error.

Cheers

-- B
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Brian Schlining
MBARI
Software Engineer
br...@mbari.org (mailto:br...@mbari.org)
(831)775-1855
http://www.mbari.org/staff/brian

On Saturday, June 25, 2011 at 6:07 PM, Andy Ritchie wrote:

> Hi Brian,
>
> I was working on the knowledge base template you provided, added a new object off the root (CMECS) and started adding CMECS concepts. I get an error when I try to delete child objects of cmecs. Says it's going to create a duplicate key if it tries.
>
> Here's the error.
>
> Caused by: javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'UC_CONCEPTID_FK' defined on 'CONCEPTDELEGATE'. Error Code: -1 Call: INSERT INTO ConceptDelegate (id, LAST_UPDATED_TIME, ConceptID_FK) VALUES (?, ?, ?) bind => [7802, 2011-06-25 18:04:55.09, 7800] Query: InsertObjectQuery(ConceptMetadataImpl ([id=7802] updatedTime=2011-06-25 18:04:55.09))
> org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102) org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63) vars.jpa.DAO.endTransaction(DAO.java:92) vars.knowledgebase.ui.EditConceptTreePopupMenu.triggerRemoveAction(EditConceptTreePopupMenu.java:218) vars.knowledgebase.ui.EditConceptTreePopupMenu$2.actionPerformed(EditConceptTreePopupMenu.java:86) javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) javax.swing.AbstractButton.doClick(AbstractButton.java:357) javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1223) javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1264)
...

java.policy
increment_uniqueid.groovy

Andy Ritchie

unread,
Jun 27, 2011, 12:29:45 PM6/27/11
to mbari...@googlegroups.com


Bad cell connection on the ferry... Will call you in a few,

But I was wondering if you know of an efficient way to edit the db and insert multiple values. I was able to get squirrel SQL talking to the derby db, but not sure about editing outside of the knowledge base interface...

~sent by my droid. hooray!

> --
> You received this message because you are subscribed to the Google Groups "mbari-vars" group.
> To post to this group, send email to mbari...@googlegroups.com.
> To unsubscribe from this group, send email to mbari-vars+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mbari-vars?hl=en.
>

Brian Schlining

unread,
Jun 27, 2011, 12:50:26 PM6/27/11
to mbari...@googlegroups.com, Andy Ritchie

On Monday, June 27, 2011 at 9:29 AM, Andy Ritchie wrote:

>
> Bad cell connection on the ferry... Will call you in a few,
> But I was wondering if you know of an efficient way to edit the db and insert multiple values. I was able to get squirrel SQL talking to the derby db, but not sure about editing outside of the knowledge base interface...

Yes, it's pretty easy to edit directly using SQL. VARS also has an entire API for reading/writing to the database that is much safer for inserting new objects in the database (which requires incrementing the UniqueID table). The API is pretty straight forward. I use a data access object (DAO) pattern. There's also a Groovy console in VARS that you can execute code directly from. For example, try the following:
1) cd VARS_HOME\bin
2) Run 'gsh'
3) When the groovy console starts try the following in the console:
t = new vars.ToolBox().toolBelt
dao = t.knowledgebaseDAOFactory.newConceptDAO()
dao.startTransaction()
c = dao.findByName('squid')
c.childConcepts.each { println it.primaryConceptName.name }
dao.endTransaction()

A few notes:
- Most of the methods for modifying the Knowledgebase are based around 'Concept'. See http://vars.sourceforge.net/javadoc/reference/vars/knowledgebase/Concept.html and it's DAO at http://vars.sourceforge.net/javadoc/reference/vars/knowledgebase/ConceptDAO.html
- Annotations are a bit more complicated. The API docs for annotations are in http://vars.sourceforge.net/javadoc/reference/vars/annotation/package-summary.html
- Database changes are bounded by transactions (i.e. dao.startTransaction() and dao.endTransaction()). Changing object properties within a transaction will also change them in the database when the transaction ends.
- Creating new objects in the database requires an explicit call to dao.persist(). Removing objects requires a call to dao.remove(). Persist and remove should be called within a transaction.

You can also execute SQL directly from the groovy shell too. There's many ways to do that, the increment_uniqueid.groovy file shows one way to grab a connection to the database.

--
Brian Schlining


Brian Schlining

unread,
Jun 27, 2011, 4:41:03 PM6/27/11
to Andy Ritchie, mbari...@googlegroups.com
Hi Andy,


On Monday, June 27, 2011 at 1:21 PM, Andy Ritchie wrote:

> I got your scripts, did as requested, got the following error (wondering about the paths issue:
>
> C:\VARS\bin>.\gsh ..\scripts\groovy\increment_uniqueid.groovy
> Exception in thread "main" java.lang.NoClassDefFoundError: \groovy/ui/GroovyMain
>
> Caused by: java.lang.ClassNotFoundException: \groovy.ui.GroovyMain
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> Could not find the main class: \groovy.ui.GroovyMain. Program will exit.

Apparently, my testing on windows has been a bit lacking. Replace the contents of gsh.bat with the contents of gsh.txt that's attached. (I didn't send as a .bat file as many spam checkers clobber emails with bat files). I tested the new file on a Windows 7 VM.

> If it helps, I've installed groovy, and I can get groovy from the command line. The error message didn't change from before/after groovy install. The path line in the exception makes me wonder if it's a windows thing...
You don't need to install groovy; VARS ships with Groovy and in any case the bat file won't pick up your local Groovy installation.

gsh.txt
Reply all
Reply to author
Forward
0 new messages