Small refactor for comming converters
This commit is contained in:
parent
75b3d5e0a0
commit
1c308a684a
178 changed files with 5865 additions and 1531 deletions
15
vasc-xpql-ejb3-server/.classpath
Normal file
15
vasc-xpql-ejb3-server/.classpath
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
36
vasc-xpql-ejb3-server/.project
Normal file
36
vasc-xpql-ejb3-server/.project
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-xpql-ejb3</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#Sat Dec 31 00:55:10 CET 2011
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#Mon Jan 02 23:47:24 CET 2012
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#Sun Dec 25 17:29:03 CET 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#Mon Jan 10 02:21:43 CET 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
||||
38
vasc-xpql-ejb3-server/pom.xml
Normal file
38
vasc-xpql-ejb3-server/pom.xml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>vasc</artifactId>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-xpql-ejb3-server</artifactId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
<name>vasc-xpql-ejb3-server</name>
|
||||
<description>xpql parsing server impl for ejb3</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-xpql-ejb3-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ejb</groupId>
|
||||
<artifactId>ejb-api</artifactId>
|
||||
<version>3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>persistence-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.transaction</groupId>
|
||||
<artifactId>jta</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,341 @@
|
|||
/*
|
||||
* Copyright 2007-2012 forwardfire.net All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.vasc.xpql.ejb3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ejb.TransactionManagement;
|
||||
import javax.ejb.TransactionManagementType;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import net.forwardfire.vasc.xpql.QueryStore;
|
||||
import net.forwardfire.vasc.xpql.XPQLParser;
|
||||
import net.forwardfire.vasc.xpql.query.Query;
|
||||
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 16 Jul 2007
|
||||
*/
|
||||
@Stateless(name="ejb/xpqlQueryManager")
|
||||
@TransactionManagement(TransactionManagementType.BEAN)
|
||||
public class XpqlQueryManagerImpl implements XpqlQueryManager.ILocal,XpqlQueryManager.IRemote {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(XpqlQueryManagerImpl.class.getName());
|
||||
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Resource
|
||||
private UserTransaction utx;
|
||||
|
||||
private Map<String,Query> queries = new HashMap<String,Query>(100);
|
||||
|
||||
@PostConstruct
|
||||
public void loadAll() {
|
||||
logger.fine("XtesManager created now loading resources...");
|
||||
try {
|
||||
long s = System.currentTimeMillis();
|
||||
|
||||
Map<String,String> keys = loadKeys();
|
||||
for (String key:keys.keySet()) {
|
||||
String value = keys.get(key);
|
||||
if (key.startsWith("load")) {
|
||||
loadResource(value);
|
||||
}
|
||||
if ("persistenceUnit".equals(key)) {
|
||||
logger.fine("getting EntityManager: "+value);
|
||||
entityManager = (EntityManager)new InitialContext().lookup(value);
|
||||
}
|
||||
}
|
||||
long t = System.currentTimeMillis()-s;
|
||||
logger.info("Total loaded xpql queries: "+queries.size()+" in "+t+" ms.");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error while load xpql resources error: "+e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads xtes-xpql-ejb3.xml from meta-inf and gives the keys
|
||||
*/
|
||||
protected Map<String,String> loadKeys() throws IOException {
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
||||
logger.fine("Getting urls");
|
||||
Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources("META-INF/xtes-xpql-ejb3.xml");
|
||||
while(e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logger.finer("Loading reletive namespaces of: "+u+" for: META-INF/xtes-xpql-ejb3.xml");
|
||||
InputStream in = u.openStream();
|
||||
try {
|
||||
properties.loadFromXML(in);
|
||||
} finally {
|
||||
if (in!=null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
e = Thread.currentThread().getContextClassLoader().getResources("/META-INF/xtes-xpql-ejb3.xml");
|
||||
while(e.hasMoreElements()) {
|
||||
URL u = e.nextElement();
|
||||
logger.finer("Loading root namespaces of: "+u+" for: /META-INF/xtes-xpql-ejb3.xml");
|
||||
InputStream in = u.openStream();
|
||||
try {
|
||||
properties.loadFromXML(in);
|
||||
} finally {
|
||||
if (in!=null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.fine("done loading");
|
||||
|
||||
Map<String,String> result = new HashMap<String,String>(20);
|
||||
for (Object key:properties.keySet()) {
|
||||
if (key instanceof String) {
|
||||
String key2 = (String) key;
|
||||
String value = properties.getProperty(key2);
|
||||
result.put(key2, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private void loadResource(String resource) {
|
||||
XPQLParser parser = new XPQLParser();
|
||||
logger.fine("Try loading: "+resource);
|
||||
try {
|
||||
parser.parseResource(resource);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not load xpql resource: "+resource+" error: "+e.getMessage(),e);
|
||||
}
|
||||
QueryStore store = parser.getQueryStore();
|
||||
|
||||
for (String key:store.getQueryNames()) {
|
||||
Query q = store.getQuery(key);
|
||||
|
||||
queries.put(q.getName(),q);
|
||||
|
||||
String out = "\n\n=========== SQL: "+q.getName()+"\n";
|
||||
//out +=q.toSQL(q);
|
||||
out +="=========== XML: "+q.getName()+"\n";
|
||||
out +=q.toXML(q);
|
||||
//out +="=========== Edit: "+q.getName()+"\n";
|
||||
//out +=q.toEdit(q);
|
||||
out +="=========== Prepard: "+q.getName()+"\n";
|
||||
out +=q.toPreparedSQL(q)+"\n";
|
||||
logger.finer("FOUND Query: "+out);
|
||||
}
|
||||
}
|
||||
|
||||
public Query getQuery(String name) {
|
||||
Query q = queries.get(name);
|
||||
return q;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> execute(Query query) {
|
||||
String sql = query.toPreparedSQL(query);
|
||||
logger.finer("Executing: "+query.getName()+" sql: "+sql);
|
||||
javax.persistence.Query q2 = null;
|
||||
if (Query.QueryType.hql==query.getType()) {
|
||||
q2 = entityManager.createQuery(sql);
|
||||
}
|
||||
if (Query.QueryType.sql==query.getType()) {
|
||||
q2 = entityManager.createNativeQuery(sql);
|
||||
}
|
||||
|
||||
// TODO: move this hack to xtest xpql
|
||||
if (query.getProperty("limit")!=null) {
|
||||
int max = new Integer(query.getPropertyString("limit"));
|
||||
q2.setMaxResults(max);
|
||||
}
|
||||
if (query.getProperty("offset")!=null) {
|
||||
int offset = new Integer(query.getPropertyString("offset"));
|
||||
q2.setFirstResult(offset);
|
||||
}
|
||||
|
||||
|
||||
List<QueryParameterValue> options = query.getOrderQueryParameterValues();
|
||||
int i=1;
|
||||
for ( QueryParameterValue value : options ) {
|
||||
Object para = value.getValue();
|
||||
if(para==null) {
|
||||
para = value.getDefaultValue();
|
||||
}
|
||||
logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName());
|
||||
q2.setParameter(i,para);
|
||||
i++;
|
||||
}
|
||||
return q2.getResultList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object executeObject(Query query) {
|
||||
String sql = query.toPreparedSQL(query);
|
||||
logger.finer("Executing: "+query.getName()+" sql: "+sql);
|
||||
javax.persistence.Query q2 = null;
|
||||
if (Query.QueryType.hql==query.getType()) {
|
||||
q2 = entityManager.createQuery(sql);
|
||||
}
|
||||
if (Query.QueryType.sql==query.getType()) {
|
||||
q2 = entityManager.createNativeQuery(sql);
|
||||
}
|
||||
|
||||
|
||||
// TODO: move this hack to xtest xpql
|
||||
if (query.getProperty("limit")!=null) {
|
||||
int max = new Integer(query.getPropertyString("limit"));
|
||||
q2.setMaxResults(max);
|
||||
}
|
||||
if (query.getProperty("offset")!=null) {
|
||||
int offset = new Integer(query.getPropertyString("offset"));
|
||||
q2.setFirstResult(offset);
|
||||
}
|
||||
|
||||
List<QueryParameterValue> options = query.getOrderQueryParameterValues();
|
||||
int i=1;
|
||||
for ( QueryParameterValue value : options ) {
|
||||
Object para = value.getValue();
|
||||
if(para==null) {
|
||||
para = value.getDefaultValue();
|
||||
}
|
||||
logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName());
|
||||
q2.setParameter(i,para);
|
||||
i++;
|
||||
}
|
||||
try {
|
||||
utx.begin();
|
||||
Object result = null;
|
||||
try {
|
||||
result = q2.getSingleResult();
|
||||
utx.commit();
|
||||
} finally {
|
||||
if (result==null) {
|
||||
utx.rollback();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (Exception se) {
|
||||
throw new RuntimeException("Transaction error: "+se.getMessage(),se);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Object> execute(String name,Map<String,Object> parameters) {
|
||||
Query query = getQuery(name);
|
||||
if (parameters!=null) {
|
||||
for (String key:parameters.keySet()) {
|
||||
Object value = parameters.get(key);
|
||||
query.setQueryParameter(key, value);
|
||||
}
|
||||
}
|
||||
return execute(query);
|
||||
}
|
||||
|
||||
public Object executeObject(String name,Map<String,Object> parameters) {
|
||||
Query query = getQuery(name);
|
||||
if (parameters!=null) {
|
||||
for (String key:parameters.keySet()) {
|
||||
Object value = parameters.get(key);
|
||||
query.setQueryParameter(key, value);
|
||||
}
|
||||
}
|
||||
return executeObject(query);
|
||||
}
|
||||
|
||||
public Integer executeUpdate(Query query) {
|
||||
String sql = query.toPreparedSQL(query);
|
||||
logger.fine("Executing: "+query.getName()+" sql: "+sql);
|
||||
try {
|
||||
javax.persistence.Query q2 = null;
|
||||
if (Query.QueryType.hql==query.getType()) {
|
||||
q2 = entityManager.createQuery(sql);
|
||||
List<QueryParameterValue> options = query.getOrderQueryParameterValues();
|
||||
int i=1;
|
||||
for ( QueryParameterValue value : options ) {
|
||||
Object para = value.getValue();
|
||||
if(para==null) {
|
||||
para = value.getDefaultValue();
|
||||
}
|
||||
logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName());
|
||||
q2.setParameter(i,para);
|
||||
i++;
|
||||
}
|
||||
utx.begin();
|
||||
Integer result = q2.executeUpdate();
|
||||
utx.commit();
|
||||
return result;
|
||||
}
|
||||
|
||||
if (Query.QueryType.sql==query.getType()) {
|
||||
q2 = entityManager.createNativeQuery(sql);
|
||||
List<QueryParameterValue> options = query.getOrderQueryParameterValues();
|
||||
int i=1;
|
||||
for ( QueryParameterValue value : options ) {
|
||||
Object para = value.getValue();
|
||||
if(para==null) {
|
||||
para = value.getDefaultValue();
|
||||
}
|
||||
logger.finest( "nr: " + i + " value: " + para+" name: "+value.getName());
|
||||
q2.setParameter(i,para);
|
||||
i++;
|
||||
}
|
||||
utx.begin();
|
||||
Integer result = q2.executeUpdate();
|
||||
utx.commit();
|
||||
return result;
|
||||
}
|
||||
} catch (Exception se) {
|
||||
throw new RuntimeException("Transaction error: "+se.getMessage(),se);
|
||||
}
|
||||
throw new IllegalStateException("unknow query type");
|
||||
}
|
||||
|
||||
public Integer executeUpdate(String name,Map<String, Object> parameters) {
|
||||
Query query = getQuery(name);
|
||||
for (String key:parameters.keySet()) {
|
||||
Object value = parameters.get(key);
|
||||
query.setQueryParameter(key, value);
|
||||
}
|
||||
return executeUpdate(query);
|
||||
}
|
||||
}
|
||||
0
vasc-xpql-ejb3-server/src/main/resources/.empty
Normal file
0
vasc-xpql-ejb3-server/src/main/resources/.empty
Normal file
0
vasc-xpql-ejb3-server/src/test/java/.empty
Normal file
0
vasc-xpql-ejb3-server/src/test/java/.empty
Normal file
0
vasc-xpql-ejb3-server/src/test/resources/.empty
Normal file
0
vasc-xpql-ejb3-server/src/test/resources/.empty
Normal file
Loading…
Add table
Add a link
Reference in a new issue