9/5/08


ORACLE tips

FONT -- Lucida Console !!!
chcp 1251

RUSSIAN_CIS.CL8MSWIN1251
chcp 1251

для клиента виндовс NLS_LANG=AMERICAN_AMERICA.CL8MSWIN1251
для клиента линукс NLS_LANG=AMERICAN_AMERICA.CL8KOI8R

sqlplus sys/querty@xe AS SYSDBA

SELECT table_name FROM user_tables;

select to_char(to_date('19-SEP-2008','dd-mon-yyyy'),'day') from dual;
select user from dual;
select sysdate from dual;
select current_user from dual;

set ARRAYSIZE 1000;
set LINESIZE 1000;
set PAGESIZE 1000;


select level from dual connect by level < 10;
select level a from dual connect by 1 = 1;


ALTER SYSTEM SET TIMED_STATISTICS = TRUE;
ALTER SESSION SET SQL_TRACE = TRUE;

-- Created d:\oracle\product\10.2.0\admin\xe\udump\xe_ora_4916.trc

select test_connect_by.parent from persons inner join test_connect_by on persons.id = test_connect_by.child group by test_connect_by.parent;

select spid, osuser, s.program from v$process p, v$session s where p.addr=s.paddr order by 2;
alter system kill session(sid, serial#);

show parameters processes
show parameters sessions

alter system set sessions=250 scope=spfile;
alter system set processes=200 scope=spfile;

select count(*) from v$session
select count(*) from v$process

quit;

orakill xe 4072

8/22/08


Eclipse Plugins

Jigloo SWT/Swing GUI Builder
Java Persistence API (JPA) Tools
JadClipse
http://update.eclemma.org

7/21/08


Java and XML: XML binding

JAXB

XMLBeans

JiBX

7/15/08


Apache AXIS

Simple invoke standard Version web service via URLConnection:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class Main {

public static void main(String[] args) throws Exception {

HttpURLConnection httpurlconnection = null;
String HostUrl = "localhost";
String SoapActionUrl = "http://localhost:8080/axis/services/Version";

URL url = new URL(SoapActionUrl);
URLConnection urlconnection = url.openConnection();
httpurlconnection = (HttpURLConnection) urlconnection;

StringBuffer stringbuffer = new StringBuffer();

stringbuffer.append("<SOAP-ENV:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
stringbuffer.append("<SOAP-ENV:Body>");
stringbuffer.append("<getVersion>");
stringbuffer.append("</getVersion></SOAP-ENV:Body></SOAP-ENV:Envelope>");

byte abyte0[] = stringbuffer.toString().getBytes();
httpurlconnection.addRequestProperty("Host", HostUrl);
httpurlconnection.addRequestProperty("Content-Length", String.valueOf(abyte0.length));
httpurlconnection.addRequestProperty("Content-Type", "text/xml; charset=UTF-8");
httpurlconnection.addRequestProperty("SOAPAction", SoapActionUrl);
httpurlconnection.setInstanceFollowRedirects(true);

httpurlconnection.setRequestMethod("POST");
httpurlconnection.setDoOutput(true);
httpurlconnection.setDoInput(true);

OutputStream outputstream = httpurlconnection.getOutputStream();
outputstream.write(abyte0);
outputstream.close();

System.out.println(httpurlconnection.getResponseMessage());

InputStreamReader inputstreamreader = new InputStreamReader(httpurlconnection.getInputStream());
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
StringBuffer stringbuffer1 = new StringBuffer();
String s3;
while ((s3 = bufferedreader.readLine()) != null) {
stringbuffer1.append(s3);
System.out.println(s3);
}
bufferedreader.close();
httpurlconnection = null;
}
}

Result:

OK
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getVersionResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><getVersionReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)</getVersionReturn></getVersionResponse></soapenv:Body></soapenv:Envelope>

Request

POST /axis/services/Version HTTP/1.1
Host: localhost
Content-Length: 253
Content-Type: text/xml; charset=UTF-8
SOAPAction: http://localhost:8080/axis/services/Version
User-Agent: Java/1.4.2
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><getVersion></getVersion></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Tue, 15 Jul 2008 11:41:14 GMT

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getVersionResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><getVersionReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)</getVersionReturn></getVersionResponse></soapenv:Body></soapenv:Envelope>


Using AXIS classes:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class Main {
public static void main(String[] args) throws Exception {
String endpoint = "http://localhost:8080/axis/services/Version";
Call call = (Call) new Service().createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("", "getVersion"));
String ret = (String) call.invoke(new Object[] { });
System.out.println(ret);
}
}

Result:

Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)

Request:

POST /axis/services/Version HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8080
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 340

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getVersion soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></soapenv:Body></soapenv:Envelope>

Response:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Date: Tue, 15 Jul 2008 10:35:47 GMT
Connection: close

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getVersionResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><getVersionReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)</getVersionReturn></getVersionResponse></soapenv:Body></soapenv:Envelope>

Java and XML: miscellaneous notes

- Java 1.4 includes the Crimson parser, though the Axis team prefer Xerces.
- If you are installing Tomcat, get the latest 4.1.x version, and the full distribution, not the LE version for Java 1.4, as that omits the Xerces XML parser.
- SOAP messages are XML messages. Messages consist of one or more SOAP elements inside an envelope, Headers and the SOAP Body. SOAP has two syntaxes for describing the data in these elements, which is a clear descendant of the XML RPC system, and XML Schema, which is the newer system.
- Axis implements the JAX-RPC API, one of the standard ways to program Java services.
- To add an XML parser, acquire the JAXP 1.1 XML compliant parser of your choice. We recommend Xerces jars from the xml-xerces distribution, though others mostly work.
- Axis is compiled in the JAR file axis.jar; it implements the JAX-RPC API declared in the JAR files jaxrpc.jar and saaj.jar.
- The examples in this guide use Xerces. This guide adds xml-apis.jar and xercesImpl.jar to the AXISCLASSPATH so that Axis can find the parser. (from Installing and deploying web applications using xml-axis).
- Axis stands for, it's Apache EXtensible Interaction System.
- JaxMe - an implementation of JAXB, the specification for Java/XML binding.
A SOAP message is an ordinary XML document containing the following elements:
* A required Envelope element that identifies the XML document as a SOAP message
* An optional Header element that contains header information
* A required Body element that contains call and response information
* An optional Fault element that provides information about errors that occurred while processing the message
-Axis is one of the best Java-based Web services engines. It's better architected and much faster than its Apache SOAP predecessor.
-XML infoset is an abstract model of all the information in an XML document or document fragment.
- Dynamic invocation interface (DII)

-Communication Patterns
With Web Services, you can essentially distinguish three different ways of communication:

* Remote procedure call: Client sends a SOAP request to the service provider and then waits for a SOAP response (synchronous communication).
* Messaging: Client sends a SOAP request and expects no SOAP response back (one-way communication)
* Asynchronous callback: A client calls the service with one of the above methods. Later, the two parties switch roles for a callback call. This pattern can be built from either of the first two.

- WSDL 1.1 distinguishes two different binding styles (referred to as soap:binding styles): RPC and Document.

7/9/08


Java and XML: validation XML

JAXP 1.3

String schemaLang = "http://www.w3.org/2001/XMLSchema";
SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
Schema schema = factory.newSchema(new StreamSource("sample.xsd"));
Validator validator = schema.newValidator();
validator.validate(new StreamSource("sample.xml"));

Java and XML: generating XML


DOM API:

import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;

public class Main {

 public static void main(String[] args) throws Exception {

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  Document xmldoc = factory.newDocumentBuilder().getDOMImplementation().createDocument(null, "PhoneBook", null);

  Element root = xmldoc.getDocumentElement();
  Element e = xmldoc.createElementNS(null, "BookRecord");
  Node n = xmldoc.createTextNode("Value");
  e.appendChild(n);
  root.appendChild(e);

  Transformer serializer = TransformerFactory.newInstance().newTransformer();
  serializer.setOutputProperty(OutputKeys.INDENT,"yes");
  serializer.transform(new DOMSource(xmldoc), new StreamResult(new PrintWriter(System.out)));
 }
}


SAX API:

import java.io.PrintWriter;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;

import org.xml.sax.helpers.*;

public class Main {

 public static void main(String argv[]) throws Exception {

  SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
  TransformerHandler hd = tf.newTransformerHandler();
  hd.getTransformer().setOutputProperty(OutputKeys.INDENT,"yes");
  hd.setResult(new StreamResult(new PrintWriter( System.out)));

  hd.startDocument();
  hd.startElement("", "", "PhoneBook",new AttributesImpl());
  hd.startElement("", "","BookRecord", new AttributesImpl());
  hd.characters("Value".toCharArray(), 0, 5);
  hd.endElement("", "", "BookRecord");
  hd.endElement("", "", "PhoneBook");
  hd.endDocument();
 }
}


JDOM API:

package com;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class Main {

 public static void main(String argv[]) throws Exception {

  Document doc = new Document();
  Element e = new Element("PhoneBook");
  e.addContent(new Element("BookRecord").setText("Value"));
  doc.addContent(e);

  XMLOutputter outp = new XMLOutputter();
  Format f = Format.getPrettyFormat();
  //f.setIndent(" ");
  outp.setFormat(f);
  outp.output(doc, System.out);
 }
}


As result in all cases:

<?xml version="1.0" encoding="UTF-8"?>
<PhoneBook>
<BookRecord>Value</BookRecord>
</PhoneBook>



XML Serialization with java.beans.XMLEncoder class

import java.beans.XMLEncoder;

public class Main {

 public static void main(String[] args) throws Exception {
  XMLEncoder xenc = new XMLEncoder(System.out);
  xenc.writeObject("Some String");
  xenc.flush();
  xenc.close();
 }
}

Output:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_06" class="java.beans.XMLDecoder">
 <string>Some String</string>
</java>

Or more interesting:

import java.beans.XMLEncoder;

public class Main {

 public static void main(String[] args) throws Exception {

  Foo[] arr = {new Foo(), new Foo()};
  XMLEncoder encoder = new XMLEncoder(System.out);
  encoder.writeObject(arr);
  encoder.close();
  }

  public static class Foo {

  private int foo = 10 ;
  public int getFoo() {
   return foo;
  }

  public void setFoo(int foo) {
   this.foo = foo;
  }
 }
}


<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_06" class="java.beans.XMLDecoder">
 <array class="com.Main$Foo" length="2">
  <void index="0">
   <object class="com.Main$Foo"/>
  </void>
  <void index="1">
   <object class="com.Main$Foo"/>
  </void>
 </array>
</java>

As you can see - not so optimistic. For the things to be serialized propery, you need bean pattern getter methods, and sometimes even setters: so for simple java bean serialization will work fine.


XStream - a lightweight open source Java library for serializing Java objects to XML and back again.


import com.thoughtworks.xstream.XStream;

public class Main {

 public static void main(String[] args) throws Exception {

  XStream xstream = new XStream();
  xstream.alias("Foo", Foo.class);
  String xml = xstream.toXML(new Foo());
  System.out.println(xml);
 }

 public static class Foo {

  public int fooInt = 10 ;
  public String fooStr = "20";
  }
}


<Foo>
 <fooInt>10</fooInt>
 <fooStr>20</fooStr>
</Foo>

In case of List it behave too pretty good:

 List<Foo> list = new LinkedList<Foo>();
 list.add(new Foo());
 list.add(new Foo());
 String xml = xstream.toXML(list);

Result:

<linked-list>
 <Foo>
  <fooInt>10</fooInt>
  <fooStr>20</fooStr>
 </Foo>
 <Foo>
  <fooInt>10</fooInt>
  <fooStr>20</fooStr>
 </Foo>
</linked-list>