Update licence header without plugin

This article explains how to update license header for your java source files without any tool. It works for Notepad++, Netbeans and Eclipse and does not require installing any additional plugin.

This article appeared first at techtavern.wordpress.com.

Option 1: Using Notepad++

Open Notepad++ and navigate to Search->Find ind Files. Fill the dialog as shown below.

update-license-header-withou-any-tool-notepadplusplus

Find what: \A(.*?^package){1}
Replace with: /\*\r\n \* (line 1)\r\n \* (line 2).\r\n \*/\r\npackage
Directory: The root directory of your source code.
Filters: *.java
Activate “Regular expression” and “. maches newline”.

When using non-English license text, use UTF8 escaping for non-ascii chars. For example, use “\xE3” instead of “ã” (more examples)

Pros: Does not require any IDE.
Cons: Does not work properly for non-English license headers. Unfortunately, Notepad++ does not allow setting the encoding for the affected files.

Options 2: Using Netbeans IDE

Open the java project with Netbeans IDE, select it and navigate to Edit->Replace in Projects.

Fill the dialog as shown below.

update-license-header-withou-any-tool-netbeans

Containing text: (?s)\A(.*?^package){1}
Match: Regular expression
Replace with: /\*\r\n \* (line 1)\r\n \* (line 2).\r\n \*/\r\npackage
Scope: Your java project or browser the source root directory
File name patterns: *.java

Click on continue. A new window opens listing all affected files. Confirm.

Pros: Works better than Netbeans License Changer plugin. Supports non-English languages and respects your encoding.

Cons: Replaces at most 500 files at time. For large projects, you are required do repeat this recipe on each subdirectory.

Options 3: Using Eclipse IDE

Open the java project with Eclipse IDE, select it and navigate to Search->File.

Fill the dialog as shown below.

update-license-header-withou-any-tool-eclipse

Containing text: (?s)\A(.*?^package){1}
Activate “Regular expression”
File name patterns: *.java

Click “Replace”. A new windows opens listing all affected files and a new dialog asks for the new text: /\*\r\n \* (line 1)\r\n \* (line 2).\r\n \*/\r\npackage

update-license-header-withou-any-tool-eclipse-2

Click “Preview” to see how files are going to be changes. Or click “OK”.

Pros: Supports non-English languages and respects your encoding. Updates file only if license header is already correct.

Cons: not known yet.

Comparing your Oracle databases

This article suggests an approach to compare your development, test and production databases using SQL scripts executed from a Servlet.

This article appeared first on techtavern.wordpress.com

Create a Servlet that produces following SQL statements as a text report: (replace **** with a proper value applicable to your database).

  • Tables, sequences and views: SELECT OBJECT_TYPE, OBJECT_NAME, STATUS FROM ALL_OBJECTS WHERE OWNER = ‘****’ ORDER BY OBJECT_TYPE, OBJECT_NAME
  • Columns of each table: SELECT TABLE_NAME, COLUMN_NAME, QUALIFIED_COL_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, CHARACTER_SET_NAME, CHAR_COL_DECL_LENGTH, CHAR_LENGTH, CHAR_USED FROM ALL_TAB_COLS WHERE OWNER = ‘****’ ORDER BY TABLE_NAME, COLUMN_NAME
  • Constrains of each table: SELECT TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE, STATUS, SEARCH_CONDITION, R_CONSTRAINT_NAME, DELETE_RULE, DEFERRABLE, DEFERRED, VALIDATED, GENERATED FROM ALL_CONSTRAINTS WHERE OWNER = ‘****’ ORDER BY TABLE_NAME, CONSTRAINT_NAME
  • Sequences: SELECT SEQUENCE_NAME, INCREMENT_BY, MIN_VALUE, MAX_VALUE, CACHE_SIZE, CYCLE_FLAG, ORDER_FLAG FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = ‘****’ ORDER BY SEQUENCE_NAME

For security reasons, you may prefer to output them into the application log.

You may request these reports on each of your environments and compare them side-by-side, for example, using Beyond Compare.

Netbeans RCP: increasing JVM memory settings

This article explains how to increase memory limits for your Netbeans RCP application when using Ant to create a ZIP package or a Windows installer.

This article appeared originally at techtavern.wordpress.com.

Introduction

Both ZIP package and Windows installer contain an executable that reads JVM and bootstrap settings from the etc/application_name.conf file. This file is copied from the laucher configuration template at netbeans-installation\harness\etc\app.conf. The default options contains all command line parameters passed to the executable. JVM parameters are prefixed by “-J”.

By default, this file has very tight memory settings (heap from 24 upto 64MB):

default_options="--branding ${branding.token} -J-Xms24m -J-Xmx64m"

Solution 1: Edit app.conf

Open netbeans-installation\harness\etc\app.conf and increase the -J-Xms and -J-Xmx parameters. However, this may require administrator priviledges if Netbeans IDE was installed into the application directory. The change will affect all application you build on the machine and will not get into your version control. You need to rememberto edit this file again on a fresh install.

Solution 2: Create your own app.conf

Create your own app.conf file within your application suite directory. Mention this file using the app.conf property within the nbproject/project.properties file of your main application suite project.

# Main-Suite\nbproject\project.properties:
app.icon=branding/core/core.jar/org/netbeans/core/startup/frame48.gif
app.name=${branding.token}
app.title=...
app.conf=nbproject/custom.conf

My custom.conf looks like the original app.conf:

# Main-Suite\nbproject\custom.conf:
# ${HOME} will be replaced by user home directory according to platform
default_userdir="${HOME}/.${APPNAME}/${buildnumber}"
default_mac_userdir="${HOME}/Library/Application Support/${APPNAME}/${buildnumber}"

# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--branding ${branding.token} -J-Xms128m -J-Xmx512m"

As the custom.conf resides inside the project configuration directory, it will be versioned by source control and used by every distribution build.

References

Calling Objectify within DeferredTask

This article explains how to call Objectify within a DeferredTask on Google App Engine push queue.

This article appeared first on techtavern.wordpress.com

Objectify Wiki presents a clear explanation how to user ObjectifyFilter to get or inject a Objectify instance into your servlet. However there is no word using Objectify within push queues.

Solution 1: Create task with worker URLs that are mapped to your servlet

Let ObjectifyFilter inject the Objectify instance. It your responsibility to encode and handle parameters and to secure your URLs.

Solution 2: Create a DeferredTask

Let GAE handle parameters and security for you. Call ObjectifyService.begin() to manually start an Objectify session. Close this session manually when the task finishes. A try-with-resources block handles everything for you.

import com.googlecode.objectify.ObjectifyService;

public class MyTask implements DeferredTask {
   final String parameter;
   public MyTask(String parameter) {
      this.parameter = parameter;
   }

   @Override
   public void run() {
      try (Closeable closeable = ObjectifyService.begin()) {
          Objectify ofy = MyObjectifyService.ofy();          
          // start transactions, read or write data.
          // ...
      } catch (IOException | RuntimeException e) {
          // log or handle failure.
      }
   }
}

I recommend a class that statically registers your entities before calling any Objectify method.

public class MyObjectifyService {
   static {
      factory().register(MyEntity.class);
      // ...
   }
   public static Objectify ofy() {
      return ObjectifyService.ofy();
   }
}

References:

Google App Engine Java SDK advices

It would have been nice if I knew this beforehand about Google App Engine Java SDK

This article originally appeared on https://techtavern.wordpress.com

GAE infrastructure is a kind of Java 7 platform. You may compile your code using the current Java 8 SDK, as long as source code version is set to Java 7. You may deploy and run your application locally with Java 8, too.

However, when deploying to Google infrastructure, there are some pitfalls.

  1. The appcfg script pre-compiles your JSP files using the Java SDK on the PATH or set by JAVA_HOME system property. If this SDK is not Java 7, appcfg will create and upload incompatible class files.
  2. Java SDK 7 is not available anymore for download on Oracle website.

I have found Java SDK 7 (7u79) installer for download still available on http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Probably, you do not want do pollute your development environment by installing a deprecated SDK. This article explains how to extract a portable SDK without running the installer. And if you do not want to mess your current PATH and JAVA_HOME system variables globally, you may set them within the appcfg.cmd file.

setlocal
set JAVA_HOME=C:\Users\Daniel\Programas\jdk7
set PATH=C:\Users\Daniel\Programas\jdk7\bin
java -Duser.language=EN -Xmx1100m -cp "%~dp0\..\lib\appengine-tools-api.jar" 
     com.google.appengine.tools.admin.AppCfg %*
endlocal