2
0
Fork 0

Refactored demo section to single app layout.

This commit is contained in:
Willem Cazander 2013-09-20 19:18:39 +02:00
parent b3635cf64d
commit 4bd244f4e5
337 changed files with 1630 additions and 1883 deletions

View file

@ -0,0 +1,78 @@
/*
* 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;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import net.forwardfire.vasc.xpql.query.Query;
/**
* Holds all the queries.
*
* @author Willem Cazander
* @version 1.0 Aug 30, 2010
*/
public class QueryStore {
private Map<String,Query> queryMap = new HashMap<String,Query>(100);
public void addQuery(Query query) {
if (query==null) {
throw new NullPointerException("Can't add null query.");
}
if (query.getName()==null) {
throw new NullPointerException("Can't add query with null name.");
}
if (query.getName().isEmpty()) {
throw new IllegalArgumentException("Can't add query with empty name.");
}
if (query.getQueryStore()!=null) {
throw new IllegalArgumentException("Query has already an store.");
}
query.setQueryStore(this);
queryMap.put(query.getName(),query);
}
public Collection<Query> getQueries() {
return queryMap.values();
}
public Query getQuery(String name) {
return queryMap.get(name);
}
public Set<String> getQueryNames() {
return queryMap.keySet();
}
public void addAll(QueryStore store) {
for (String key:store.getQueryNames()) {
Query q = store.getQuery(key);
addQuery(q);
}
}
}

View file

@ -0,0 +1,52 @@
/*
* 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;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
/**
* Parse an xpql file/resource
*
* @author Willem Cazander
* @version 1.0 Aug 29, 2010
*/
public class XPQLDriver extends X4ODriver<QueryStore> {
static public String LANGUAGE_NAME = "xpql";
static public String[] LANGUAGE_VERSIONS = new String[]{X4ODriver.DEFAULT_LANGUAGE_VERSION};
@Override
public String getLanguageName() {
return LANGUAGE_NAME;
}
@Override
public String[] getLanguageVersions() {
return LANGUAGE_VERSIONS;
}
static public XPQLDriver getInstance() {
return (XPQLDriver)X4ODriverManager.getX4ODriver(LANGUAGE_NAME);
}
}

View file

@ -0,0 +1,62 @@
/*
* 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.execute.jpa;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.persistence.EntityManager;
import net.forwardfire.vasc.xpql.query.Query;
/**
*
* @author Willem Cazander
* @version 1.0 17 Sep 2010
*/
public interface XpqlQueryManager {
public Query getQuery(String name);
public List<Object> execute(EntityManager entityManager,Query query);
public Object executeObject(EntityManager entityManager,Query query);
public Integer executeUpdate(EntityManager entityManager,Query query);
public List<Object> execute(EntityManager entityManager,String query,Map<String,Object> parameters);
public Object executeObject(EntityManager entityManager,String query,Map<String,Object> parameters);
public Integer executeUpdate(EntityManager entityManager,String query,Map<String,Object> parameters);
@Local
public interface ILocal extends XpqlQueryManager {
}
@Remote
public interface IRemote extends XpqlQueryManager {
}
}

View file

@ -0,0 +1,342 @@
/*
* 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.execute.jpa;
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.SessionContext;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;
import org.x4o.xml.io.X4OReader;
import net.forwardfire.vasc.xpql.QueryStore;
import net.forwardfire.vasc.xpql.XPQLDriver;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
/**
* XpqlQueryManagerImpl
*
* @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;
@Resource
private SessionContext context;
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: RMED."+value);
//entityManager = EntityManager.class.cast(context.lookup(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) {
XPQLDriver driver = XPQLDriver.getInstance();
X4OReader<QueryStore> reader = driver.createReader();
QueryStore store = null;
logger.fine("Try loading: "+resource);
try {
store = reader.readResource(resource);
} catch (Exception e) {
throw new RuntimeException("Could not load xpql resource: "+resource+" error: "+e.getMessage(),e);
}
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(EntityManager entityManager,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();
}
public Object executeObject(EntityManager entityManager,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(EntityManager entityManager,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(entityManager,query);
}
public Object executeObject(EntityManager entityManager,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(entityManager,query);
}
public Integer executeUpdate(EntityManager entityManager,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(EntityManager entityManager,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(entityManager,query);
}
}

View file

@ -0,0 +1,104 @@
package net.forwardfire.vasc.xpql.execute.jpa;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.naming.Context;
import javax.naming.InitialContext;
import net.forwardfire.vasc.xpql.query.Query;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
public class XpqlVascJndiQueriesElement extends AbstractElement {
@Override
public void doElementEnd() throws ElementException {
// set queries map to element object
Map<String,Query> queries = new HashMap<String,Query>(100);
setElementObject(queries);
String jndiName = getAttributes().get("jndi");
if (jndiName==null) {
throw new ElementException("No 'jndi' attributes defined.");
}
if (jndiName.isEmpty()) {
throw new ElementException("Empty 'jndi' attributes can't load.");
}
// load queries from ejb3 bean reference
XpqlQueryManager xpqlManager = null;
try {
Context context = new InitialContext();
xpqlManager = (XpqlQueryManager)context.lookup( jndiName );
} catch (Exception e) {
throw new ElementException("Could not get the ejb resource bundle: "+e.getMessage(),e);
}
if (xpqlManager==null) {
throw new ElementException("XpqlQueryManager ejb resource is null.");
}
XpqlController refBean = new XpqlController(xpqlManager);
setElementObject(refBean);
}
class XpqlController implements Map<String,Query> {
private XpqlQueryManager xpqlManager = null;
public XpqlController(XpqlQueryManager xpqlManager) {
this.xpqlManager=xpqlManager;
}
public void clear() {
}
public boolean containsKey(Object key) {
return true;
}
public boolean containsValue(Object value) {
return true;
}
public Set<Map.Entry<String, Query>> entrySet() {
return null;
}
public Query get(Object key) {
return xpqlManager.getQuery((String)key);
}
public boolean isEmpty() {
return false;
}
public Set<String> keySet() {
return null;
}
public Query put(String key, Query value) {
return null;
}
@SuppressWarnings("unchecked")
public void putAll(Map m) {
}
public Query remove(Object key) {
return null;
}
public int size() {
return 0;
}
public Collection<Query> values() {
return null;
}
}
}

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.xpql.execute.jpa;

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.xpql.execute;

View file

@ -0,0 +1,147 @@
/*
* 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.impl;
import net.forwardfire.vasc.xpql.query.AbstractQuery;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
import net.forwardfire.vasc.xpql.query.QueryPart;
/**
* This class defines an executable SQL query.
*
* @author Willem Cazander, Arjan Tijms
* @version 1.0 17/11/2004
* @since 1.0
*/
public class DefaultQuery extends AbstractQuery {
/** Is set as option values when value is null */
static final String NULL_STRING = "";
// ========= QueryPart interface
/**
* @see net.forwardfire.vasc.xpql.query.AbstractQueryPart#toEdit()
*/
@Override
public String toEdit(Query query) {
StringBuffer queryBuffer = new StringBuffer();
for ( QueryPart queryPart:getQueryParts() ) {
queryBuffer.append( queryPart.toEdit(query) );
}
return queryBuffer.toString();
}
/**
* @see net.forwardfire.vasc.xpql.query.AbstractQueryPart#toPreparedSQL()
*/
@Override
public String toPreparedSQL(Query query) {
this.getOrderQueryParameterValues().clear();
StringBuffer queryBuffer = new StringBuffer();
for ( QueryPart queryPart:getQueryParts() ) {
queryBuffer.append( queryPart.toPreparedSQL(query) );
}
return queryBuffer.toString();
}
/**
* @see net.forwardfire.vasc.xpql.query.AbstractQueryPart#toSQL()
*/
@Override
public String toSQL(Query query) {
StringBuffer queryBuffer = new StringBuffer();
for ( QueryPart queryPart:getQueryParts() ) {
queryBuffer.append( queryPart.toSQL(query) );
}
return queryBuffer.toString();
}
/**
* @see net.forwardfire.vasc.xpql.query.AbstractQueryPart#toXML()
*/
@Override
public String toXML(Query query) {
StringBuffer queryBuffer = new StringBuffer();
queryBuffer.append("\t<query name=\""+getName()+"\" type=\""+getType()+"\">\n");
for (String key:getPropertyKeys()) {
queryBuffer.append("\t\t<x4o:property name=\""+key+"\" value=\""+getPropertyString(key)+"\"/>\n");
}
queryBuffer.append("\t\t<sql>");
for ( QueryPart queryPart:getQueryParts() ) {
queryBuffer.append( queryPart.toXML(query) );
}
queryBuffer.append("</sql>\n");
for ( String comment:getQueryComments()) {
queryBuffer.append("\t\t<comment>");
queryBuffer.append(comment);
queryBuffer.append("</comment>\n");
}
for ( QueryParameterValue qpv:getLocalQueryParameterValues()) {
queryBuffer.append("\t\t<parameterValue ");
queryBuffer.append("name=\""+qpv.getName()+"\" ");
if (qpv.getValue()!=null) {
queryBuffer.append("value=\""+qpv.getValue()+"\" ");
}
if (qpv.getDefaultValue()!=null) {
queryBuffer.append("defaultValue=\""+qpv.getDefaultValue()+"\" ");
}
queryBuffer.append("type=\""+qpv.getType()+"\" ");
queryBuffer.append("/>\n");
}
queryBuffer.append("\t</query>\n");
return queryBuffer.toString();
}
public Query clone() throws CloneNotSupportedException {
Query query = new DefaultQuery();
//query.setTemplateStore(getTemplateStore());
query.setName(getName());
query.setType(getType());
for (String key:getPropertyKeys()) {
query.setProperty(key,getProperty(key));
}
for (QueryPart part:getQueryParts()) {
query.addQueryPart(part.clone());
}
for (String com:getQueryComments()) {
query.addQueryComment(com);
}
for (QueryParameterValue q:getLocalQueryParameterValues()) {
query.addQueryParameterValue(q.clone());
}
return query;
}
}

View file

@ -0,0 +1,45 @@
/*
* 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.impl;
import net.forwardfire.vasc.xpql.query.AbstractQueryParameterValue;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
public class DefaultQueryParameterValue extends AbstractQueryParameterValue {
public QueryParameterValue clone() throws CloneNotSupportedException {
QueryParameterValue p = new DefaultQueryParameterValue();
p.setDefaultValue(getDefaultValue());
p.setName(getName());
p.setType(getType());
p.setValue(getValue());
p.setValueType(getValueType());
return p;
}
}

View file

@ -0,0 +1,127 @@
/*
* 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.impl;
import org.x4o.xml.io.X4OReader;
import net.forwardfire.vasc.xpql.QueryStore;
import net.forwardfire.vasc.xpql.XPQLDriver;
import net.forwardfire.vasc.xpql.query.AbstractQueryPart;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.QueryPart;
/**
* Handled included query parts
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
public class QueryInclude extends AbstractQueryPart {
private String name = null;
private String resource = null;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the resource
*/
public String getResource() {
return resource;
}
/**
* @param resource the resource to set
*/
public void setResource(String resource) {
this.resource = resource;
}
@Override
public String toSQL(Query query) {
if (query.getQueryStore().getQuery(getName())==null) {
if (resource!=null) {
try {
XPQLDriver driver = XPQLDriver.getInstance();
X4OReader<QueryStore> reader = driver.createReader();
QueryStore store = reader.readResource(resource);
query.getQueryStore().addAll(store);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return query.getQueryStore().getQuery(getName()).toSQL(query);
}
public String toPreparedSQL(Query query) {
if (query.getQueryStore().getQuery(getName())==null) {
if (resource!=null) {
try {
XPQLDriver driver = XPQLDriver.getInstance();
X4OReader<QueryStore> reader = driver.createReader();
QueryStore store = reader.readResource(resource);
query.getQueryStore().addAll(store);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return query.getQueryStore().getQuery(getName()).toPreparedSQL(query);
}
public String toXML(Query query) {
if (resource==null) {
return "<include name=\""+name+"\"/>";
}
return "<include name=\""+name+"\" resource=\""+resource+"\"/>";
}
public String toEdit(Query query) {
if (resource==null) {
return "@inc:"+name;
}
return "@inc:"+name+"@"+resource;
}
public QueryPart clone() throws CloneNotSupportedException {
QueryInclude include = new QueryInclude();
include.setName(getName());
include.setResource(getResource());
return include;
}
}

View file

@ -0,0 +1,213 @@
/*
* 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.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.forwardfire.vasc.xpql.query.AbstractQueryPart;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.Query.QueryType;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
import net.forwardfire.vasc.xpql.query.QueryPart;
/**
* QueryParameter.
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
public class QueryParameter extends AbstractQueryPart {
private String name = null;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
@SuppressWarnings("unchecked")
public String toSQL(Query query) {
QueryParameterValue value = query.getQueryParameterValue(getName());
if ( value == null ) {
return "";
}
if ( value.getValue() == null) {
if (value.getDefaultValue() == null ) {
return "";
}
return value.getDefaultValue().toString();
}
if (value.getType()==null) {
value.setType(QueryParameterValue.QueryParameterType.parameter);
}
if (value.getType()==QueryParameterValue.QueryParameterType.parameterList) {
List valueList = null;
if (value.getValue() instanceof List) {
valueList = (List)value.getValue();
}
if (value.getValue() instanceof String) {
valueList = new ArrayList();
String[] array = ((String)value.getValue()).split(",");
for (String a:array) {
valueList.add(a);
}
}
if (valueList==null) {
valueList = new ArrayList();
valueList.add(value.getValue());
}
StringBuilder builder = new StringBuilder(valueList.size()+3);
Iterator i = valueList.iterator();
while (i.hasNext()) {
Object v = i.next();
builder.append(v.toString());
if (i.hasNext()) {
builder.append(',');
}
}
return builder.toString();
}
return value.getValue().toString();
}
@SuppressWarnings("unchecked")
public String toPreparedSQL(Query query) {
QueryParameterValue value = query.getQueryParameterValue(getName());
if ( value == null ) {
return "";
}
if (value.getType()==null) {
value.setType(QueryParameterValue.QueryParameterType.parameter);
}
String result = null;
switch (value.getType()) {
default:
case parameter:
//if (query.getOrderQueryParameterValues().contains(value)==false) {
query.addOrderQueryParameterValue(value);
if (QueryType.hql.equals(query.getType())) {
result = "?"+query.getOrderQueryParameterValues().size();
} else {
result = "?";
}
break;
case parameterList:
// add extra method so , toObjectList, which does al the prepare work.
Object valueO = value.getValue();
if (valueO==null) {
return "";
}
List valueList = null;
if (valueO instanceof List) {
valueList = (List)valueO;
}
if (valueO instanceof String) {
valueList = new ArrayList();
String[] array = ((String)valueO).split(",");
for (String a:array) {
valueList.add(a);
}
}
if (valueList==null) {
valueList = new ArrayList();
valueList.add(value);
}
//boolean doAdd = false;
//if (query.getOrderQueryParameterValues().contains(value)==false) {
//}
StringBuilder builder = new StringBuilder(valueList.size()+3);
Iterator i = valueList.iterator();
while (i.hasNext()) {
Object v = i.next();
//if (doAdd) {
QueryParameterValue vv = new DefaultQueryParameterValue();
vv.setName(value.getName());
vv.setValue(v);
vv.setType(QueryParameterValue.QueryParameterType.parameter);
query.addOrderQueryParameterValue(vv);
//}
if (QueryType.hql.equals(query.getType())) {
builder.append("?"+query.getOrderQueryParameterValues().size());
} else {
builder.append('?');
}
if (i.hasNext()) {
builder.append(',');
}
}
result = builder.toString();
break;
case raw:
// The structural type of a "value" indicates that we're dealing with a SQL construct
// instead of a 'value' in the sense of values for prepared statements. In the XPQL dialect,
// options can be structure as well as values.
if (value.getValue()!=null) {
result = value.getValue().toString();
} else if (value.getDefaultValue()!=null) {
result = value.getDefaultValue().toString();
} else {
result = "";
}
break;
case xpql:
result = null;
break;
}
return result;
}
public String toXML(Query query) {
return "<parameter name=\"" + getName() + "\"/>";
}
public String toEdit(Query query) {
return "@"+getName();
}
public QueryPart clone() throws CloneNotSupportedException {
QueryParameter p = new QueryParameter();
p.setName(getName());
return p;
}
}

View file

@ -0,0 +1,62 @@
/*
* 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.impl;
import net.forwardfire.vasc.xpql.query.AbstractQueryPart;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.QueryPart;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
public class QueryText extends AbstractQueryPart {
String text = null;
/**
* @return the text
*/
public String getText() {
return text;
}
/**
* @param text the text to set
*/
public void setText(String text) {
this.text = text;
}
@Override
public String toSQL(Query query) {
return text;
}
public QueryPart clone() throws CloneNotSupportedException {
QueryText text = new QueryText();
text.setText(getText());
return text;
}
}

View file

@ -0,0 +1,73 @@
/*
* 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.impl.x4o;
import net.forwardfire.vasc.xpql.query.Query;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
/**
*
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2006
*/
public class CommentElement extends AbstractElement {
private StringBuffer comment = null;
public CommentElement() {
comment = new StringBuffer(20);
}
/**
* @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String)
*/
@Override
public void doCharacters(String arg0) {
comment.append(arg0);
}
/**
* @see org.x4o.xml.element.AbstractElement#doComment(java.lang.String)
*/
@Override
public void doComment(String arg0) {
comment.append(arg0);
}
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
if (getParent()==null) {
throw new ElementException("No parent element");
}
if ((getParent().getElementObject() instanceof Query)==false) {
throw new ElementException("No query parent element object");
}
((Query)getParent().getElementObject()).addQueryComment(comment.toString());
}
}

View file

@ -0,0 +1,66 @@
/*
* 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.impl.x4o;
import java.util.Locale;
import net.forwardfire.vasc.xpql.query.QueryParameterValue.QueryParameterType;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* ParameterTypeObjectConverter
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class ParameterTypeObjectConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 40849496158706355L;
public Class<?> getObjectClassTo() {
return QueryParameterType.class;
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((QueryParameterType)obj).name();
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return QueryParameterType.valueOf(""+str);
} catch (Exception ex) {
throw new ObjectConverterException(this,"Could not convert to QueryParameterType value="+str,ex);
}
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
ParameterTypeObjectConverter result = new ParameterTypeObjectConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,93 @@
/*
* 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.impl.x4o;
import net.forwardfire.vasc.xpql.impl.QueryInclude;
import net.forwardfire.vasc.xpql.impl.QueryParameter;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
import net.forwardfire.vasc.xpql.query.QueryPart;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
* QueryBindingHandler binds query elements.
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class QueryBindingHandler extends AbstractElementBindingHandler<Query> {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
QueryPart.class,
QueryParameterValue.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return Query.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
@Override
public void bindChild(Element childElement, Query parentObject,Object childObject) throws ElementBindingHandlerException {
// skip those with different life cycle because of sql characters adding elements in sax phase.
if (childObject instanceof QueryParameter) {
return;
}
if (childObject instanceof QueryInclude) {
return;
}
if (childObject == parentObject) {
return; // skip sql element
}
if (childObject instanceof QueryPart) {
parentObject.addQueryPart((QueryPart)childObject);
}
if (childObject instanceof QueryParameterValue) {
parentObject.addLocalQueryParameterValue((QueryParameterValue)childObject);
parentObject.addQueryParameterValue((QueryParameterValue)childObject);
}
}
@Override
public void createChilderen(Element parentElement, Query parentObject) throws ElementBindingHandlerException {
for (QueryPart part:parentObject.getQueryParts()) {
createChild(parentElement, part);
}
for (QueryParameterValue value:parentObject.getQueryParameterValues()) {
createChild(parentElement, value);
}
}
}

View file

@ -0,0 +1,56 @@
/*
* 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.impl.x4o;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.QueryPart;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
/**
* Inserts the query inlude element direct on start-tag
*
* @author Willem Cazander
* @version 1.0 Dec 2, 2009
*/
public class QueryIncludeElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementStart() throws ElementException {
if (getParent()==null) {
throw new ElementException("No parent element");
}
if ((getParent().getElementObject() instanceof Query)==false) {
throw new ElementException("No query parent element object");
}
if ((getElementObject() instanceof QueryPart)==false) {
throw new ElementException("No QueryPart element object");
}
((Query)getParent().getElementObject()).addQueryPart((QueryPart)getElementObject());
}
}

View file

@ -0,0 +1,56 @@
/*
* 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.impl.x4o;
import net.forwardfire.vasc.xpql.query.Query;
import net.forwardfire.vasc.xpql.query.QueryPart;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
/**
* Inserts the query element direct on start-tag
*
* @author Willem Cazander
* @version 1.0 Mar 24, 2009
*/
public class QueryParameterElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementStart() throws ElementException {
if (getParent()==null) {
throw new ElementException("No parent element");
}
if ((getParent().getElementObject() instanceof Query)==false) {
throw new ElementException("No query parent element object");
}
if ((getElementObject() instanceof QueryPart)==false) {
throw new ElementException("No QueryPart element object");
}
((Query)getParent().getElementObject()).addQueryPart((QueryPart)getElementObject());
}
}

View file

@ -0,0 +1,67 @@
/*
* 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.impl.x4o;
import java.util.Locale;
import net.forwardfire.vasc.xpql.query.Query.QueryType;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* QueryTypeObjectConverter converts query type enum.
*
* todo: rm this for the enum conv.
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class QueryTypeObjectConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 2383122486722789617L;
public Class<?> getObjectClassTo() {
return QueryType.class;
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((QueryType)obj).name();
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return QueryType.valueOf(""+str);
} catch (Exception ex) {
throw new ObjectConverterException(this,"Could not convert to QueryType value="+str,ex);
}
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
QueryTypeObjectConverter result = new QueryTypeObjectConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,77 @@
/*
* 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.impl.x4o;
import net.forwardfire.vasc.xpql.impl.QueryText;
import net.forwardfire.vasc.xpql.query.Query;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
/**
*
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2006
*/
public class SQLElement extends AbstractElement {
private StringBuffer sql = null;
public SQLElement() {
sql = new StringBuffer(20);
}
/**
* @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String)
*/
@Override
public void doCharacters(String text) throws ElementException {
if (getParent()==null) {
throw new ElementException("No parent element");
}
if ((getParent().getElementObject() instanceof Query)==false) {
throw new ElementException("No query parent element object");
}
QueryText q = new QueryText();
q.setText(text);
((Query)getParent().getElementObject()).addQueryPart(q);
}
/**
* @see org.x4o.xml.element.AbstractElement#doComment(java.lang.String)
*/
@Override
public void doComment(String arg0) {
sql.append("/* "+arg0+" */");
}
/**
* @see org.x4o.xml.element.AbstractElement#getElementObject()
*/
@Override
public Object getElementObject() {
return getParent().getElementObject();
}
}

View file

@ -0,0 +1,257 @@
/*
* 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.query;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.xpql.QueryStore;
import net.forwardfire.vasc.xpql.impl.DefaultQueryParameterValue;
/**
* AbstractQuery
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
abstract public class AbstractQuery extends AbstractQueryPart implements Query {
private String name = null;
private List<QueryPart> queryParts = null;
private Map<String,QueryParameterValue> localQueryParameterValues = null;
private Map<String,QueryParameterValue> queryParameterValues = null;
private List<QueryParameterValue> orderQueryParameterValues = null;
private List<String> queryComments = null;
private Map<String,Object> properties = null;
private QueryType type = null;
private QueryStore queryStore = null;
/**
* Init all fields.
*/
public AbstractQuery() {
queryParts = new ArrayList<QueryPart>(10);
localQueryParameterValues = new HashMap<String,QueryParameterValue>(6);
queryParameterValues = new HashMap<String,QueryParameterValue>(6);
orderQueryParameterValues = new ArrayList<QueryParameterValue>(6);
queryComments = new ArrayList<String>(2);
properties = new HashMap<String,Object>(5);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getName()
*/
public String getName() {
return name;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#setName(java.lang.String)
*/
public void setName(String name) {
this.name=name;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#addQueryComment(java.lang.String)
*/
public void addQueryComment(String comment) {
queryComments.add(comment);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#addQueryParameterValue(net.forwardfire.vasc.xpql.query.QueryParameterValue)
*/
public void addQueryParameterValue(QueryParameterValue value) {
queryParameterValues.put(value.getName(), value);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#addLocalQueryParameterValue(net.forwardfire.vasc.xpql.query.QueryParameterValue)
*/
public void addLocalQueryParameterValue(QueryParameterValue value) {
localQueryParameterValues.put(value.getName(), value);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#addOrderQueryParameterValue(net.forwardfire.vasc.xpql.query.QueryParameterValue)
*/
public void addOrderQueryParameterValue(QueryParameterValue value) {
orderQueryParameterValues.add(value);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#addQueryPart(net.forwardfire.vasc.xpql.query.QueryPart)
*/
public void addQueryPart(QueryPart queryPart) {
queryParts.add(queryPart);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getProperty(java.lang.String)
*/
public Object getProperty(String name) {
return properties.get(name);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getPropertyString(java.lang.String)
*/
public String getPropertyString(String name) {
return getProperty(name).toString();
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getQueryComments()
*/
public List<String> getQueryComments() {
return queryComments;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getQueryParameterValue(java.lang.String)
*/
public QueryParameterValue getQueryParameterValue(String name) {
return queryParameterValues.get(name);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getQueryParts()
*/
public List<QueryPart> getQueryParts() {
return queryParts;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#setProperty(java.lang.String, java.lang.Object)
*/
public void setProperty(String name, Object value) {
properties.put(name,value);
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getPropertyKeys()
*/
public Collection<String> getPropertyKeys() {
return properties.keySet();
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getQueryParameters()
*/
public List<String> getQueryParameters() {
return null;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getQueryParameterValues()
*/
public Collection<QueryParameterValue> getQueryParameterValues() {
return queryParameterValues.values();
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getLocalQueryParameterValues()
*/
public Collection<QueryParameterValue> getLocalQueryParameterValues() {
return localQueryParameterValues.values();
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getOrderQueryParameterValues()
*/
public List<QueryParameterValue> getOrderQueryParameterValues() {
return orderQueryParameterValues;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#setQueryParameter(java.lang.String, java.lang.Object)
*/
public void setQueryParameter(String name, Object value) {
if (name==null) {
throw new NullPointerException("name can't be null.");
}
QueryParameterValue parameter = getQueryParameterValue(name);
if (parameter==null) {
// not found create new one
parameter = new DefaultQueryParameterValue();
parameter.setName(name);
parameter.setType(QueryParameterValue.QueryParameterType.parameter);
addQueryParameterValue(parameter);
}
// check if we need to convert
//System.out.println("Con: "+parameter.getValueType()+" value: "+value+" valueClass: "+value.getClass());
if (parameter.getValueType()!=null && value instanceof String) {
try {
Constructor<?> c = parameter.getValueType().getConstructor(String.class);
value = c.newInstance(value);
} catch (Exception e) {
// TODO: fix
throw new RuntimeException(e);
}
}
parameter.setValue(value);
}
public void setQueryParameters(Map<String,Object> parameters) {
for (String key:parameters.keySet()) {
setQueryParameter(key,parameters.get(key));
}
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getType()
*/
public QueryType getType() {
return type;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#setType(net.forwardfire.vasc.xpql.query.Query.QueryType)
*/
public void setType(QueryType type) {
this.type=type;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#getQueryStore()
*/
public QueryStore getQueryStore() {
return queryStore;
}
/**
* @see net.forwardfire.vasc.xpql.query.Query#setQueryStore(net.forwardfire.vasc.xpql.query.QueryStore)
*/
public void setQueryStore(QueryStore store) {
this.queryStore=store;
}
abstract public Query clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,109 @@
/*
* 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.query;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
abstract public class AbstractQueryParameterValue implements QueryParameterValue {
private String name = null;
private Object value = null;
private Object defaultValue = null;
private QueryParameterType type = null;
private Class<?> valueType = null;
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#getName()
*/
public String getName() {
return name;
}
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#setName(java.lang.String)
*/
public void setName(String name) {
this.name=name;
}
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#getDefaultValue()
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#setDefaultValue(java.lang.Object)
*/
public void setDefaultValue(Object defaultValue) {
this.defaultValue=defaultValue;
}
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#getValue()
*/
public Object getValue() {
return value;
}
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#setType(net.forwardfire.vasc.xpql.query.QueryParameterValue.QueryParameterType)
*/
public void setType(QueryParameterType type) {
this.type=type;
}
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#getType()
*/
public QueryParameterType getType() {
return type;
}
/**
* @see net.forwardfire.vasc.xpql.query.QueryParameterValue#setValue(java.lang.Object)
*/
public void setValue(Object value) {
this.value=value;
}
/**
* @return the valueType
*/
public Class<?> getValueType() {
return valueType;
}
/**
* @param valueType the valueType to set
*/
public void setValueType(Class<?> valueType) {
this.valueType = valueType;
}
abstract public QueryParameterValue clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,87 @@
/*
* 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.query;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
abstract public class AbstractQueryPart implements QueryPart {
/**
* @see net.forwardfire.vasc.xpql.query.QueryPart#toSQL()
*/
abstract public String toSQL(Query query);
/**
* Returns the toSQL() retult.
* @see net.forwardfire.vasc.xpql.query.QueryPart#toPreparedSQL()
*/
public String toPreparedSQL(Query query) {
return toSQL(query);
}
/**
* XML escapes the toSQL() return String.
* @see net.forwardfire.vasc.xpql.query.QueryPart#toXML()
*/
public String toXML(Query query) {
return escapeXML(toSQL(query));
}
/**
* Returns the toSQL() retult.
* @see net.forwardfire.vasc.xpql.query.QueryPart#toEdit()
*/
public String toEdit(Query query) {
return toSQL(query);
}
// helper method
public static String escapeXML(String input) {
StringBuffer filtered = new StringBuffer();
for ( char c : input.toCharArray() ) {
switch (c) {
case '<':
filtered.append("&lt;");
break;
case '>':
filtered.append("&gt;");
break;
case '"':
filtered.append("&quot;");
break;
case '&':
filtered.append("&amp;");
break;
default:
filtered.append(c);
}
}
return filtered.toString();
}
abstract public QueryPart clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,83 @@
/*
* 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.query;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.xpql.QueryStore;
/**
* Query which is build out of QueryParts.
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
public interface Query extends QueryPart {
static public enum QueryType {
sql,
hql
}
public void setName(String name);
public String getName();
public void setType(QueryType type);
public QueryType getType();
public void addQueryPart(QueryPart queryPart);
public List<QueryPart> getQueryParts();
public void addQueryComment(String comment);
public List<String> getQueryComments();
public void addQueryParameterValue(QueryParameterValue value);
public void addLocalQueryParameterValue(QueryParameterValue value);
public void addOrderQueryParameterValue(QueryParameterValue value);
public Collection<QueryParameterValue> getQueryParameterValues();
public Collection<QueryParameterValue> getLocalQueryParameterValues();
public List<QueryParameterValue> getOrderQueryParameterValues();
public QueryParameterValue getQueryParameterValue(String name);
public void setQueryParameter(String name,Object value);
public void setQueryParameters(Map<String,Object> parameters);
public List<String> getQueryParameters();
public void setProperty(String name,Object value);
public Object getProperty(String name);
public String getPropertyString(String name);
public Collection<String> getPropertyKeys();
public void setQueryStore(QueryStore store);
public QueryStore getQueryStore();
/**
* Force impl to have public clone methode
* @return
* @throws CloneNotSupportedException
*/
public Query clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,112 @@
/*
* 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.query;
/**
* A QueryParameterValue
*
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
public interface QueryParameterValue {
/**
* The value type
*/
static public enum QueryParameterType {
/** one parameter value */
parameter,
/** Multiple value */
parameterList,
/** parser the value as xpql syntax */
xpql,
/** Put the value in raw in the output */
raw
}
/**
* Sets the name
* @param name The name to set.
*/
public void setName(String name);
/**
* Gets the name
* @return Returns the name
*/
public String getName();
/**
* Sets the value
* @param value The value to set.
*/
public void setValue(Object value);
/**
* Gets the value
* @return Returns the value
*/
public Object getValue();
/**
* Sets the defaultValue
* @param defaultValue The defaultValue to set.
*/
public void setDefaultValue(Object defaultValue);
/**
* Gets the defaultValue
* @return Returns the defaultValue
*/
public Object getDefaultValue();
/**
* Sets type value Type
* @param type The type to set.
*/
public void setType(QueryParameterType type);
/**
* Gets the type.
* @return Returns the type
*/
public QueryParameterType getType();
/**
* @return the valueType
*/
public Class<?> getValueType();
/**
* @param valueType the valueType to set
*/
public void setValueType(Class<?> valueType);
/**
* Force impl to have public clone methode
* @return
* @throws CloneNotSupportedException
*/
public QueryParameterValue clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,67 @@
/*
* 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.query;
/**
* QueryPart
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
public interface QueryPart extends Cloneable {
/**
* This method is for building the SQL version of the query part.
* This version is intended for execution.
* @return
*/
public String toSQL(Query query);
/**
* This method is for building the prepared statement SQL version of the query part.
* This version is intended for execution via a prepared statement.
* @return
*/
public String toPreparedSQL(Query query);
/**
* This method is for building the XML version of the query part.
* This version is intended for storage.
* @return
*/
public String toXML(Query query);
/**
* This method is for building the edit mode version of the query part.
* This version is intended for humans working with the format in an editor.
* @return
*/
public String toEdit(Query query);
/**
* Force impl to have public clone methode
* @return
* @throws CloneNotSupportedException
*/
public QueryPart clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,49 @@
package net.forwardfire.vasc.xpql.x4o;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import net.forwardfire.vasc.xpql.QueryStore;
import net.forwardfire.vasc.xpql.XPQLDriver;
import net.forwardfire.vasc.xpql.query.Query;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.io.X4OReader;
public class XpqlLoadQueriesElement extends AbstractElement {
private Logger logger = Logger.getLogger(XpqlLoadQueriesElement.class.getName());
@Override
public void doElementEnd() throws ElementException {
// set queries map to element object
Map<String,Query> queries = new HashMap<String,Query>(100);
setElementObject(queries);
String resource = getAttributes().get("resource");
if (resource==null) {
throw new ElementException("No 'resource' attributes defined.");
}
if (resource.isEmpty()) {
throw new ElementException("Empty 'resource' attributes can't load.");
}
// load queries from attributes
XPQLDriver driver = new XPQLDriver();
X4OReader<QueryStore> reader = driver.createReader();
QueryStore store = null;
try {
store = reader.readResource(resource);
} catch (Exception e) {
throw new ElementException(e);
}
for (String key:store.getQueryNames()) {
Query q = store.getQuery(key);
queries.put(q.getName(),q);
}
logger.info("Loaded xpql queries: "+store.getQueryNames().size());
}
}

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<modules version="1.0"
xmlns="http://language.x4o.org/xml/ns/modules"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://language.x4o.org/xml/ns/modules http://language.x4o.org/xml/ns/modules-1.0.xsd"
>
<language version="1.0">
<eld-resource>vasc-xpql.eld</eld-resource>
</language>
</modules>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<root:module
xmlns="http://eld.x4o.org/xml/ns/eld-lang"
xmlns:root="http://eld.x4o.org/xml/ns/eld-root"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd"
providerHost="vasc.forwardfire.net"
providerName="Xpql query loading"
id="vasc-xpql"
>
<namespace uri="http://vasc.forwardfire.net/xml/ns/xpql"
schemaUri="http://vasc.forwardfire.net/xml/ns/xpql-1.0.xsd"
schemaResource="xpql-1.0.xsd"
schemaPrefix="xpql"
name="Vasc Xpql"
id="ns-xpql"
>
<element tag="xpqlLoadQueries" elementClass="net.forwardfire.vasc.xpql.x4o.XpqlLoadQueriesElement"/>
</namespace>
<namespace uri="http://vasc.forwardfire.net/xml/ns/xpql-jndi"
schemaUri="http://vasc.forwardfire.net/xml/ns/xpql-jndi-1.0.xsd"
schemaResource="xpql-jndi-1.0.xsd"
schemaPrefix="jndi"
name="Vasc Xpql JNDI"
id="nsxpql-jndi"
>
<element tag="xpqlJndiQueries" elementClass="net.forwardfire.vasc.xpql.execute.jpa.XpqlVascJndiQueriesElement"/>
</namespace>
</root:module>

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2004-2012, Willem Cazander
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.
-->
<drivers version="1.0"
xmlns="http://language.x4o.org/xml/ns/drivers"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://language.x4o.org/xml/ns/drivers http://language.x4o.org/xml/ns/drivers-1.0.xsd"
>
<driver language="xpql" className="net.forwardfire.vasc.xpql.XPQLDriver"/>
</drivers>

View file

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<root:module
xmlns="http://eld.x4o.org/xml/ns/eld-lang"
xmlns:conv="http://eld.x4o.org/xml/ns/eld-conv"
xmlns:root="http://eld.x4o.org/xml/ns/eld-root"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd"
providerHost="xpql.vasc.forwardfire.net"
providerName="XML Parmeterized Query Language"
id="mod-xpql-lang"
>
<bindingHandler id="QueryBindingHandler" bean.class="net.forwardfire.vasc.xpql.impl.x4o.QueryBindingHandler"/>
<classBindingHandler id="Store-Query"
parentClass="net.forwardfire.vasc.xpql.QueryStore" childClass="net.forwardfire.vasc.xpql.query.Query"
addMethod="addQuery" getMethod="getQueries"
/>
<namespace uri="http://xpql.vasc.forwardfire.net/xml/ns/xpql-root"
schemaUri="http://xpql.vasc.forwardfire.net/xml/ns/xpql-root-1.0.xsd"
schemaResource="xpql-root-1.0.xsd"
schemaPrefix="root"
name="Xpql Language Root"
languageRoot="true"
id="ns-xpql-root"
>
<element tag="store" objectClass="net.forwardfire.vasc.xpql.QueryStore">
<description>The module query store root element.</description>
</element>
</namespace>
<namespace uri="http://xpql.vasc.forwardfire.net/xml/ns/xpql-lang"
schemaUri="http://xpql.vasc.forwardfire.net/xml/ns/xpql-lang-1.0.xsd"
schemaResource="xpql-lang-1.0.xsd"
schemaPrefix="xpql"
name="Vasc Xpql Language"
id="ns-xpql-lang"
>
<element tag="query" objectClass="net.forwardfire.vasc.xpql.impl.DefaultQuery">
<attribute name="type" defaultValue="sql">
<conv:beanConverter bean.class="net.forwardfire.vasc.xpql.impl.x4o.QueryTypeObjectConverter"/>
</attribute>
</element>
<element tag="sql" elementClass="net.forwardfire.vasc.xpql.impl.x4o.SQLElement"/>
<element tag="parameter" objectClass="net.forwardfire.vasc.xpql.impl.QueryParameter" elementClass="net.forwardfire.vasc.xpql.impl.x4o.QueryParameterElement"/>
<element tag="include" objectClass="net.forwardfire.vasc.xpql.impl.QueryInclude" elementClass="net.forwardfire.vasc.xpql.impl.x4o.QueryIncludeElement"/>
<element tag="comment" elementClass="net.forwardfire.vasc.xpql.impl.x4o.CommentElement"/>
<element tag="parameterValue" objectClass="net.forwardfire.vasc.xpql.impl.DefaultQueryParameterValue">
<attribute name="type" defaultValue="parameter">
<conv:beanConverter bean.class="net.forwardfire.vasc.xpql.impl.x4o.ParameterTypeObjectConverter"/>
</attribute>
<attribute name="valueType">
<conv:classConverter/>
</attribute>
</element>
</namespace>
</root:module>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<modules version="1.0"
xmlns="http://language.x4o.org/xml/ns/modules"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://language.x4o.org/xml/ns/modules http://language.x4o.org/xml/ns/modules-1.0.xsd"
>
<language version="1.0">
<eld-resource>xpql-lang.eld</eld-resource>
<sibling-loader>org.x4o.xml.lang.meta.MetaLanguageSiblingLoader</sibling-loader>
</language>
</modules>

View file

@ -0,0 +1,22 @@
package net.forwardfire.vasc.xpql;
import net.forwardfire.vasc.xpql.query.Query;
import org.x4o.xml.io.X4OReader;
import junit.framework.TestCase;
public class XPQLDriverTest extends TestCase {
public void testReader() throws Exception {
XPQLDriver driver = XPQLDriver.getInstance();
X4OReader<QueryStore> reader = driver.createReader();
QueryStore store = reader.readResource("xpql/tests.xml");
assertNotNull(store);
assertFalse(store.getQueryNames().isEmpty());
for (Query q:store.getQueries()) {
System.out.println("Name: "+q.getName());
System.out.println(q.toSQL(q));
}
}
}

View file

@ -0,0 +1,20 @@
#
# Enables all logging for debugging unit tests.
# Specify the handlers to create in the root logger
# (all loggers are children of the root logger)
# The following creates two handlers
handlers = java.util.logging.ConsoleHandler
# Set the default logging level for new ConsoleHandler instances
java.util.logging.ConsoleHandler.level = ALL
# Set the default logging level for the root logger
.level = ALL
net.forwardfire = ALL
# Java 6 has internal logging on many builtin libs
sun.level=OFF
java.level=OFF
javax.level=OFF

View file

@ -0,0 +1,12 @@
<xpql xmlns:meta="iets" xmlns="iets1">
<meta:query>
<meta:fromItem data="schema.table['products']" alias="p"/>
<meta:select data="schema.table['products'].column['product_type']"/>
<meta:groupBy data="schema.table['products'].column['product_type']"/>
<meta:select data="schema.table['products'].column['price']" type="SUM"/>
<meta:where />
<meta:orderBy />
</meta:query>
</xpql>

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<query:store xmlns="http://xpql.vasc.forwardfire.net/xml/ns/xpql-lang"
xmlns:query="http://xpql.vasc.forwardfire.net/xml/ns/xpql-root"
xmlns:x4o="http://meta.x4o.org/xml/ns/meta-lang"
>
<query name="limit">
<sql>
LIMIT <parameter name="limit"/>
</sql>
<parameterValue name="limit" value="10" defaultValue="200" type="parameter"/>
</query>
<query name="paging" type="hql">
<sql>
OFFSET <parameter name="offset"/>
<include name="limit"/>
</sql>
<parameterValue name="offset" value="0" defaultValue="0" type="parameter"/>
</query>
<query name="baseSelect">
<x4o:property name="executionTimeout" value="200"/>
<x4o:property name="cacheTimeout" value="99"/>
<x4o:property name="jdniConnection" value="somewhere"/>
<sql>
SELECT
USERS.USERNAME AS USERNAME
USERS.PASSWD AS PASSWORD
FROM
USERS
</sql>
<comment>Bla bla</comment>
<comment>Also see this site http://www.google.com</comment>
</query>
<query name="testUsers2" type="hql">
<x4o:property name="persistanceSession" value="sessionName"/>
<sql>
<!-- SOME COMMENT -->
<include name="baseSelect"/>
<parameter name="extra_where"/>
AND role is in <parameter name="roles"/>
<include name="paging"/>
</sql>
<parameterValue name="extra_where" defaultValue="WHERE true=true" type="raw"/>
<parameterValue name="roles" value="1,12,99,200" type="parameterList"/>
<parameterValue name="limit" value="15"/>
<parameterValue name="offset" value="25"/>
</query>
</query:store>