Derby

Apache Derby

If you are using generated primary keys as shown here:

create table SOME_TABLE (

   ID integer generated by default as identity,

... );

and you need to reset the generator to an integer greater than the last id

... here's an example.

-- reset the generator

alter table SOME_TABLE alter column ID restart with 1;


Apache Derby 10.9.1 Eclipse Core Plugin build and Eclipse (Juno) ui plugin fix.

Apache Derby db-derby-10.9.1.0-src Eclipse 4.2.1 Java 7

References: db-derby-10.9.1.0-src/BUILDING.html db-derby-10.8.1.2-src/plugins/eclipse/Readme.txt

Download the Apache Derby source zip. Extract the zip. Change to the source directory. db-derby-10.9.1.0-src

Perform the following ant targets. ant -quiet clobber ant -quiet buildsource ant -quiet buildjars

Build the core plugin. ant plugin

You should now have a derby_core_plugin_10.9.1.zip file in the db-derby-10.9.1.0-src/jars/sane directory.

Note: Your Eclipse IDE should not be running. Extract the derby core plugin created by the ant plugin task above and copy the contents to your Eclipse plugins directory. derby_core_plugin_10.9.1.zip

Run Eclipse.

Import the org.apache.derby.ui from the source tree. (Import > General > Existing Projects into Workspace)

Open the plugin.xml file

On the Overview tab, bump up the version number to let's say 1.1.4.

Save the file.

The bug(s) are in ...

1.)package org.apache.derby.ui.popup.actions.AddDerbyNature.java

2.)package org.apache.derby.ui.popup.actions.RemoveDerbyNature.java

Where the .setStatus method are called in these two units.


Note: ( from the javadoc of ApplicationWindow ) >void org.eclipse.jface.window.ApplicationWindow.setStatus(String message)

> >Sets or clears the message displayed in this window's status line (if it has >one). This method has no effect if the window does not have a status line.

>Parameters: >message the status message, or null to clear it

So let's assume the IDE doesn't have a status line, so this call has no effect according to the Java doc.

Commenting out these method calls from: AddDerbyNature.java //((ApplicationWindow) window).setStatus(Messages.ADDING_NATURE); //((ApplicationWindow) window).setStatus(Messages.DERBY_NATURE_ADDED);

RemoveDerbyNature.java //((ApplicationWindow)window).setStatus(Messages.REMOVING_NATURE); //((ApplicationWindow)window).setStatus(Messages.DERBY_NATURE_REMOVED);

Test: Run As Eclipse Application.

Create a project. Maybe call it “org.apache.derby.ui.test”.

Right Click on project / Select Add Apache Derby nature No error.

Right Click on project / Select Remove Apache Derby nature No error.

Add the nature again to test the other menu items. Right Click on project / Select Add Apache Derby nature

Right Click on project / Select Start Derby Network Server No error, server was started.

From the console log ... Sun Jan 27 17:51:29 EST 2013 : Security manager installed using the Basic server security policy. Sun Jan 27 17:51:29 EST 2013 : Apache Derby Network Server - 10.9.1.0 - (Unversioned directory) started and ready to accept connections on port 1527

Note: Not sure what the Unversioned directory message means

Right Click on project / Select Stop Derby Network Server No error, server was stopped. Sun Jan 27 17:53:32 EST 2013 : Apache Derby Network Server - 10.9.1.0 - (Unversioned directory) shutdown

Start the server back up … Right Click on project / Select Start Derby Network Server

create a sql folder. create a test.sql file

my test sql file.

connect 'jdbc:derby://localhost:1527/TESTDB;create=true;user=test;password=test;'; -- drop User Indexes - ignore error if first time creating drop index UserNameIdx1; -- drop the table if it exists - ignore error if first time creating drop table TEST_USER; -- create the table create table TEST_USER (

   ID integer generated by default as identity,
   USER_NAME varchar(255) not null,
   FIRST_NAME varchar(255),
   LAST_NAME varchar(255),
   PASSWORD varchar(255),
   ENABLED integer,
   CREATED_STAMP timestamp,
   CREATED_TX_STAMP timestamp,
   LAST_UPDATED_STAMP timestamp,
   LAST_UPDATED_TX_STAMP timestamp,
   constraint TEST_USER_PK primary key (ID)

); -- insert some data -- oops --- will mess with the ID generator, see the alter table restart line below. insert into TEST_USER values(0, 'admin','admin','admin','admin',1,'2013-01-18 12:00:00.000','2013-01-18 12:00:00.000','2013-01-18 12:00:00.000','2013-01-18 12:00:00.000'); -- make the USER_NAME unique create unique index UserNameIdx1 on TEST_USER(USER_NAME); -- reset the generator alter table TEST_USER alter column ID restart with 1;


Right click on file > Apache Derby > Run SQL Script using 'ij'

Refesh the projects workspace, now there should be a TESTDB folder.

Database was created. Ok.

Create a zip.

Right click on project > Export

Click on Plug-in Development > Deplyable plug-ins and fragments. Destination Tab Archive file <some_local_location>/derby_ui_plugin_1.1.4-fix.zip Options Tab Unselect Package plugins as individual JAR archives

Click finish.

Close / Exit the test instance. Exit Eclipse.

Extract the zip from above.

Copy contents of the the plugins dir to your Eclipse plugins dir.

Restart Eclipse. Create a new project.

You should be able to install an Apache Derby (10.9.1) nature onto your projects.

Note: if you built this with Java 7, don't expect it to work for any lesser JVM version.