Lentz Independent ConsultingOnline Notebook

off Oracle sysdate

lentzic to Oracle  

Oracle interprets number constants in date expressions as a number of days.

Count of Results from the Previous Hour:
select count(*) from(
select * from header where TO_CHAR(START_RUN_PERIOD, ‘mm/dd/yyyy HH24′) = TO_CHAR(sysdate -1/24, ‘mm/dd/yyyy HH24′))
where last_updated_date > start_run_period

See http://www.dba-oracle.com/t_date_math_manipulation.htm for some nice date arithmetic examples.

bcp sourcedb.db.Table out SourceTableOut.dat -n -U -P -S

bcp destinationdb.db.Table in SourceTableOut.dat -n -U -P -S

Query example:
bcp “select * from mydb.db.TableName where Index > 158″ queryout TableOut.dat -n -U -P -S

off An Excuse to Use Reflection

lentzic to Java  

I had to transform a table with date columns 1 through 8 into individual rows in another table. At first, I thought I’d have to check my loop index then conditionally call the correct method on the source object. Instead, I used the reflection api:

Source source = dao.getSource();
for(int i = 1; i < 9; i++){
Destination dest = new Destination();
Class c = source.getClass();
String index = Integer.valueOf(i).toString();
try {
//set values from summary
Method getStartDT = c.getDeclaredMethod(“getPeriodStartDT”+index, (Class [])null);
dest.setStartRunPeriod((Calendar)getStartDT.invoke(source, (Object[])null));

off Google Sets

lentzic to Java  

import java.util.Set;
import com.google.common.collect.Sets;

final Set aAreas = dao.getDistinctAAreas();
final Set bAreas = dao.getDistinctBAreas();
final Set areasInANotInB = Sets.difference(aAreas, bAreas);
final Set areasInBNotInA = Sets.difference(bAreas, aAreas);

off JMS Delivery Count

lentzic to JMS  

//to get the javax.jms.Message delivery count to an MDB
msg.getIntProperty(“JMSXDeliveryCount”);

//to get the configured maxDeliveryAttempts from a JBoss Queue using MBeans
import javax.management.MBeanServer;
import org.jboss.jms.server.destination.DestinationMBean;
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.mx.util.MBeanServerLocator;

Queue q = (Queue)message.getJMSDestination();
qName = “jboss.messaging.destination:name=” + q.getQueueName()+ “,service=Queue”;
MBeanServer server = MBeanServerLocator.locateJBoss();
DestinationMBean mbean = (DestinationMBean) MBeanProxyExt.create(DestinationMBean.class, qName, server);
int maxDeliveryAttempts = mbean.getMaxDeliveryAttempts();

0 Articles Worth a Second Read

lentzic to Java  

Transaction and redelivery in JMS

Linux Guide

Oracle Drivers and Issues with DATE Columns

HTTP 400 Explained

EAI Patterns

Hibernate Annotations

Open Source Gantt Charts

TattleTale

Quartz Cron Expressions

CSS Float

Monitoring and Management Using JMX

JConsole: Class Loading & Garbage Collection

XPath and Default Namespace Handling

Multiple JBoss Instances on One Machine
JBoss AS Config

Deployment Considerations

RichFaces Demo

Google Collections

SchemaSpy

http://www.oracle.com/technetwork/articles/javase/index-140168.html#binsch

The xjc binding compiler can be found in the Java 6 jdk1.6.0_XX\bin directory and is used to generate Java classes from an XSD:

xjc -p com.mycompany.model myschema.xsd -d targetDirectory

XSD with inline ParmList definition results in generated inner class:


[sourcecode language="xml"]
<xs:element name="DataHeader">
   <xs:complexType>
      <xs:sequence>
         <xs:element ref="DataName"/>
         <xs:element ref="DataTimeStamp"/>
         <xs:element name="ParmList" minOccurs = "0" maxOccurs="unbounded">
           <xs:complexType>
             <xs:sequence>
               <xs:element name="ParmName" type="xs:string"/>
               <xs:element name="ParmValue" type="xs:string"/>
             </xs:sequence>
           </xs:complexType>
         </xs:element>
      </xs:sequence>
    </xs:complexType>
</xs:element>
[/sourcecode]

xjc Binding Compiler generated class:

public class DataHeader
       protected List<DataHeader.ParmList> pList;

public static class ParmList {
       protected String parmName;
       protected String parmValue;

XSD with separate ParmList definition with reference in DataHeader generates two separate classes:

[sourcecode language="xml"]
<xs:element name="ParmValue">
   <xs:simpleType>
      <xs:restriction base="xs:string"/>
   </xs:simpleType>
</xs:element>
<xs:element name="ParmName"> ...

<xs:element name="ParmList">
   <xs:complexType>
      <xs:sequence>
         <xs:element ref="ParmName"/>
         <xs:element ref="ParmValue"/> ...

<xs:element name="DataHeader">
   <xs:complexType>
      <xs:sequence>
         <xs:element ref="DataName"/>
         <xs:element ref="ParmList" minOccurs="0" maxOccurs="unbounded"/> ...

[/sourcecode]

xjc Binding Compiler generated classes:

public class DataHeader
      protected List<ParmList> plist;

public class ParmList
      protected String parmName;
      protected String parmValue;

0 MockRunner

lentzic to Testing  

Problem: You need to mock a ResultSet for testing purposes.

Solution: Use MockRunner’s MockResultSet.

http://mockrunner.sourceforge.net

Download the mockrunner-0.4.2.zip and extract the mockrunner-jdbc.jar file from \mockrunner-0.4.2\lib\jdk1.6\jee5 to get the MockResultSet. Also, extract \mockrunner-0.4.2\jar\jakarta-oro-2.0.8.jar to get MalformedPatternException.

Example usage:

private static final String sql = “select * from tableName”;
MockConnection conn = new MockConnection();
MockCallableStatement cs = new MockCallableStatement(conn, sql);
MockResultSet rs = new MockResultSet(“testResultSet”);

rs.addColumn(“columnA”, new Integer[]{1});
rs.addColumn(“columnB”, new String[]{“Column B Value”});
rs.addColumn(“columnC”, new Double[]{2});

rs.setStatement(cs);

CachedRowSet crs = new OracleCachedRowSet();
crs.populate(rs);

Problem: Deleted Eclipse project outside of Perforce and GetLatestRevision no longer pulls files into local workspace

Solution:

  • select project in the Depot
  • rt-click the project > Remove from Workspace
  • delete the project locally
  • rt-click on the project in the Depot
  • GetLatestRevision

0 CachedRowSet

lentzic to JDBC  

http://download.oracle.com/javase/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html

  • disconnected, serializable, cloneable, and scrollable container for rows of data
  • good for large amounts of data where the client holds the rows for a long period of time

If using Oracle, consider the OracleCachedRowSet implementation of the CachedRowSet interface.

Method of interest:  populate(ResultSet data)

Example:
Connection con;
CallableStatement cstmt = con.prepareCall("select * from mytable where name=?");
cstmt.setString(1, "Bob");
ResultSet rs = cstmt.executeQuery();

CachedRowSet crs = new OracleCachedRowSet();
crs.populate(rs);