2
0
Fork 0

moved xpql over and test for release

This commit is contained in:
willem.cazander 2011-01-10 21:55:33 +01:00
parent a51eeeb254
commit fa06f4e015
56 changed files with 3009 additions and 158 deletions

10
vasc-xpql/.classpath Normal file
View file

@ -0,0 +1,10 @@
<?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.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
vasc-xpql/.project Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-xpql</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,6 @@
#Mon Jan 10 02:20:38 CET 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,9 @@
#Mon Jan 10 02:20:38 CET 2011
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

36
vasc-xpql/pom.xml Normal file
View file

@ -0,0 +1,36 @@
<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-base</artifactId>
<groupId>com.idcanet.vasc</groupId>
<version>0.3.1-SNAPSHOT</version>
</parent>
<groupId>com.idcanet.vasc</groupId>
<artifactId>vasc-xpql</artifactId>
<version>0.3.1-SNAPSHOT</version>
<name>vasc-xpql</name>
<description>vasc xpql parser for queries.</description>
<dependencies>
<dependency>
<groupId>com.idcanet.x4o</groupId>
<artifactId>x4o-core</artifactId>
<version>${x4o-core.version}</version>
</dependency>
<!-- JSP depency -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<!-- Metamodel
<dependency>
<groupId>dk.eobjects.metamodel</groupId>
<artifactId>MetaModel-full</artifactId>
<version>1.1.2</version>
<scope>compile</scope>
<optional/>
</dependency>
-->
</dependencies>
</project>

View file

@ -0,0 +1,65 @@
/*
* Copyright 2004-2010 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.idcanet.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.");
}
queryMap.put(query.getName(),query);
}
public Query getQuery(String name) {
return queryMap.get(name);
}
public Set<String> getQueryNames() {
return queryMap.keySet();
}
}

View file

@ -0,0 +1,71 @@
/*
* Copyright 2004-2010 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql;
import javax.el.ValueExpression;
import com.idcanet.x4o.core.X4OParser;
import com.idcanet.x4o.element.ElementContext;
/**
* Parse an xpql file/resource
*
* @author Willem Cazander
* @version 1.0 Aug 29, 2010
*/
public class XPQLParser extends X4OParser {
static public String XPQL_LANGUAGE = "xpql";
private QueryStore queryStore = null;
public XPQLParser() {
this(new QueryStore());
}
public XPQLParser(QueryStore queryStore) {
super(XPQL_LANGUAGE);
if (queryStore==null) {
throw new NullPointerException("Can work with null QueryStore.");
}
this.queryStore=queryStore;
addGlobalELBean("__queryStore__", queryStore);
}
public QueryStore getQueryStore() {
return queryStore;
}
static public QueryStore getQueryStore(ElementContext elementContext) {
if (elementContext==null) {
throw new NullPointerException("ElementContext may not be null.");
}
ValueExpression ee = elementContext.getExpressionFactory().createValueExpression(elementContext.getELContext(),"${__queryStore__}",QueryStore.class);
QueryStore qs = (QueryStore)ee.getValue(elementContext.getELContext());
return qs;
}
}

View file

@ -0,0 +1,151 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl;
import com.idcanet.vasc.xpql.query.AbstractQuery;
import com.idcanet.vasc.xpql.query.Query;
import com.idcanet.vasc.xpql.query.QueryParameterValue;
import com.idcanet.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 com.idcanet.xtes.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 com.idcanet.xtes.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 com.idcanet.xtes.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 com.idcanet.xtes.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,49 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl;
import com.idcanet.vasc.xpql.query.AbstractQueryParameterValue;
import com.idcanet.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,122 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl;
import com.idcanet.vasc.xpql.XPQLParser;
import com.idcanet.vasc.xpql.query.AbstractQueryPart;
import com.idcanet.vasc.xpql.query.Query;
import com.idcanet.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 {
XPQLParser parser = new XPQLParser(query.getQueryStore());
parser.parseResource(resource);
} 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 {
XPQLParser parser = new XPQLParser(query.getQueryStore());
parser.parseResource(resource);
} 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,206 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.idcanet.vasc.xpql.query.AbstractQueryPart;
import com.idcanet.vasc.xpql.query.Query;
import com.idcanet.vasc.xpql.query.QueryParameterValue;
import com.idcanet.vasc.xpql.query.QueryPart;
/**
*
* @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);
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();
builder.append('?');
//if (doAdd) {
QueryParameterValue vv = new DefaultQueryParameterValue();
vv.setName(value.getName());
vv.setValue(v);
vv.setType(QueryParameterValue.QueryParameterType.parameter);
query.addOrderQueryParameterValue(vv);
//}
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,66 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl;
import com.idcanet.vasc.xpql.query.AbstractQueryPart;
import com.idcanet.vasc.xpql.query.Query;
import com.idcanet.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,76 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
import com.idcanet.vasc.xpql.query.Query;
/**
*
*
* @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 com.idcanet.x4o.element.AbstractElement#doCharacters(java.lang.String)
*/
@Override
public void doCharacters(String arg0) {
comment.append(arg0);
}
/**
* @see com.idcanet.x4o.element.AbstractElement#doComment(java.lang.String)
*/
@Override
public void doComment(String arg0) {
comment.append(arg0);
}
/**
* @see com.idcanet.x4o.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,51 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElementAttributeConverter;
import com.idcanet.x4o.element.Element;
import com.idcanet.x4o.element.ElementAttributeConverterException;
import com.idcanet.vasc.xpql.query.QueryParameterValue.QueryParameterType;
/**
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class ParameterTypeAttributeConverter extends AbstractElementAttributeConverter {
/**
* @see com.idcanet.x4o.element.AbstractElementClassParameterConverter#doConvertAttribute(com.idcanet.x4o.element.Element, java.lang.Object)
*/
public Object doConvertAttribute(Element arg0, Object value) throws ElementAttributeConverterException {
try {
return QueryParameterType.valueOf(""+value);
} catch (Exception ex) {
throw new ElementAttributeConverterException(this,"Could not convert to QueryParameterType value="+value,ex);
}
}
}

View file

@ -0,0 +1,84 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElementBindingHandler;
import com.idcanet.x4o.element.Element;
import com.idcanet.x4o.element.ElementBindingHandlerException;
import com.idcanet.vasc.xpql.impl.QueryInclude;
import com.idcanet.vasc.xpql.impl.QueryParameter;
import com.idcanet.vasc.xpql.query.Query;
import com.idcanet.vasc.xpql.query.QueryParameterValue;
import com.idcanet.vasc.xpql.query.QueryPart;
/**
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class QueryBindingHandler extends AbstractElementBindingHandler {
public boolean canBind(Element element) {
Object parent = element.getParent().getElementObject();
Object child = element.getElementObject();
boolean p = false;
boolean c = false;
if(parent instanceof Query) { p=true; }
if(child instanceof QueryPart) { c=true; }
if(child instanceof QueryParameterValue) { c=true; }
// remove recuive stack
if(element instanceof SQLElement) { c=false; }
if(p&c) { return true; } else { return false; }
}
public void doBind(Element element) throws ElementBindingHandlerException {
Object parent = element.getParent().getElementObject();
Object child = element.getElementObject();
if(parent instanceof Query) {
Query query = (Query)parent;
// skip those with diffent life cycle because of sql characters adding elements in sax phase.
if (child instanceof QueryParameter) {
return;
}
if (child instanceof QueryInclude) {
return;
}
if (child instanceof QueryPart) {
query.addQueryPart((QueryPart)child);
}
if (child instanceof QueryParameterValue) {
query.addLocalQueryParameterValue((QueryParameterValue)child);
query.addQueryParameterValue((QueryParameterValue)child);
}
}
}
}

View file

@ -0,0 +1,55 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElementConfigurator;
import com.idcanet.x4o.element.Element;
import com.idcanet.x4o.element.ElementConfiguratorException;
import com.idcanet.vasc.xpql.QueryStore;
import com.idcanet.vasc.xpql.XPQLParser;
import com.idcanet.vasc.xpql.query.Query;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class QueryElementConfigurator extends AbstractElementConfigurator {
/**
* @see com.idcanet.x4o.element.ElementConfigurator#doConfigElement(com.idcanet.x4o.element.Element)
*/
public void doConfigElement(Element element) throws ElementConfiguratorException {
if ((element.getElementObject() instanceof Query)==false) {
throw new ElementConfiguratorException(this,"No query element object");
}
QueryStore store = XPQLParser.getQueryStore(element.getElementContext());
Query query = (Query)element.getElementObject();
query.setQueryStore(store);
store.addQuery(query);
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
import com.idcanet.vasc.xpql.query.Query;
import com.idcanet.vasc.xpql.query.QueryPart;
/**
* Inserts the query inlude element direct on start-tag
*
* @author Willem Cazander
* @version 1.0 Dec 2, 2009
*/
public class QueryIncludeElement extends AbstractElement {
/**
* @see com.idcanet.x4o.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,58 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
import com.idcanet.vasc.xpql.query.Query;
import com.idcanet.vasc.xpql.query.QueryPart;
/**
* Inserts the query element direct on start-tag
*
* @author Willem Cazander
* @version 1.0 Mar 24, 2009
*/
public class QueryParameterElement extends AbstractElement {
/**
* @see com.idcanet.x4o.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,51 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElementAttributeConverter;
import com.idcanet.x4o.element.Element;
import com.idcanet.x4o.element.ElementAttributeConverterException;
import com.idcanet.vasc.xpql.query.Query.QueryType;
/**
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class QueryTypeAttributeConverter extends AbstractElementAttributeConverter {
/**
* @see com.idcanet.x4o.element.AbstractElementClassParameterConverter#doConvertAttribute(com.idcanet.x4o.element.Element, java.lang.Object)
*/
public Object doConvertAttribute(Element arg0, Object value) throws ElementAttributeConverterException {
try {
return QueryType.valueOf(""+value);
} catch (Exception ex) {
throw new ElementAttributeConverterException(this,"Could not convert to QueryType value="+value,ex);
}
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright 2004-2006 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.impl.x4o;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
import com.idcanet.vasc.xpql.impl.QueryText;
import com.idcanet.vasc.xpql.query.Query;
/**
*
*
* @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 com.idcanet.x4o.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 com.idcanet.x4o.element.AbstractElement#doComment(java.lang.String)
*/
@Override
public void doComment(String arg0) {
sql.append("/* "+arg0+" */");
}
/**
* @see com.idcanet.x4o.element.AbstractElement#getElementObject()
*/
@Override
public Object getElementObject() {
return getParent().getElementObject();
}
}

View file

@ -0,0 +1,259 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.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 com.idcanet.vasc.xpql.QueryStore;
import com.idcanet.vasc.xpql.impl.DefaultQueryParameterValue;
/**
*
* @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 com.idcanet.xtes.xpql.query.Query#getName()
*/
public String getName() {
return name;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#setName(java.lang.String)
*/
public void setName(String name) {
this.name=name;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#addQueryComment(java.lang.String)
*/
public void addQueryComment(String comment) {
queryComments.add(comment);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#addQueryParameterValue(com.idcanet.xtes.xpql.query.QueryParameterValue)
*/
public void addQueryParameterValue(QueryParameterValue value) {
queryParameterValues.put(value.getName(), value);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#addLocalQueryParameterValue(com.idcanet.xtes.xpql.query.QueryParameterValue)
*/
public void addLocalQueryParameterValue(QueryParameterValue value) {
localQueryParameterValues.put(value.getName(), value);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#addOrderQueryParameterValue(com.idcanet.xtes.xpql.query.QueryParameterValue)
*/
public void addOrderQueryParameterValue(QueryParameterValue value) {
orderQueryParameterValues.add(value);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#addQueryPart(com.idcanet.xtes.xpql.query.QueryPart)
*/
public void addQueryPart(QueryPart queryPart) {
queryParts.add(queryPart);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getProperty(java.lang.String)
*/
public Object getProperty(String name) {
return properties.get(name);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getPropertyString(java.lang.String)
*/
public String getPropertyString(String name) {
return getProperty(name).toString();
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getQueryComments()
*/
public List<String> getQueryComments() {
return queryComments;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getQueryParameterValue(java.lang.String)
*/
public QueryParameterValue getQueryParameterValue(String name) {
return queryParameterValues.get(name);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getQueryParts()
*/
public List<QueryPart> getQueryParts() {
return queryParts;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#setProperty(java.lang.String, java.lang.Object)
*/
public void setProperty(String name, Object value) {
properties.put(name,value);
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getPropertyKeys()
*/
public Collection<String> getPropertyKeys() {
return properties.keySet();
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getQueryParameters()
*/
public List<String> getQueryParameters() {
return null;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getQueryParameterValues()
*/
public Collection<QueryParameterValue> getQueryParameterValues() {
return queryParameterValues.values();
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getLocalQueryParameterValues()
*/
public Collection<QueryParameterValue> getLocalQueryParameterValues() {
return localQueryParameterValues.values();
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getOrderQueryParameterValues()
*/
public List<QueryParameterValue> getOrderQueryParameterValues() {
return orderQueryParameterValues;
}
/**
* @see com.idcanet.xtes.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 com.idcanet.xtes.xpql.query.Query#getType()
*/
public QueryType getType() {
return type;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#setType(com.idcanet.xtes.xpql.query.Query.QueryType)
*/
public void setType(QueryType type) {
this.type=type;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#getQueryStore()
*/
public QueryStore getQueryStore() {
return queryStore;
}
/**
* @see com.idcanet.xtes.xpql.query.Query#setQueryStore(com.idcanet.xtes.xpql.QueryStore)
*/
public void setQueryStore(QueryStore store) {
this.queryStore=store;
}
abstract public Query clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,113 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.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 com.idcanet.xtes.xpql.query.QueryParameterValue#getName()
*/
public String getName() {
return name;
}
/**
* @see com.idcanet.xtes.xpql.query.QueryParameterValue#setName(java.lang.String)
*/
public void setName(String name) {
this.name=name;
}
/**
* @see com.idcanet.xtes.xpql.query.QueryParameterValue#getDefaultValue()
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* @see com.idcanet.xtes.xpql.query.QueryParameterValue#setDefaultValue(java.lang.Object)
*/
public void setDefaultValue(Object defaultValue) {
this.defaultValue=defaultValue;
}
/**
* @see com.idcanet.xtes.xpql.query.QueryParameterValue#getValue()
*/
public Object getValue() {
return value;
}
/**
* @see com.idcanet.xtes.xpql.query.QueryParameterValue#setType(com.idcanet.xtes.xpql.query.QueryParameterValue.QueryParameterType)
*/
public void setType(QueryParameterType type) {
this.type=type;
}
/**
* @see com.idcanet.xtes.xpql.query.QueryParameterValue#getType()
*/
public QueryParameterType getType() {
return type;
}
/**
* @see com.idcanet.xtes.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,91 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.query;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 4, 2007
*/
abstract public class AbstractQueryPart implements QueryPart {
/**
* @see com.idcanet.xtes.xpql.query.QueryPart#toSQL()
*/
abstract public String toSQL(Query query);
/**
* Returns the toSQL() retult.
* @see com.idcanet.xtes.xpql.query.QueryPart#toPreparedSQL()
*/
public String toPreparedSQL(Query query) {
return toSQL(query);
}
/**
* XML escapes the toSQL() return String.
* @see com.idcanet.xtes.xpql.query.QueryPart#toXML()
*/
public String toXML(Query query) {
return escapeXML(toSQL(query));
}
/**
* Returns the toSQL() retult.
* @see com.idcanet.xtes.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,86 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.query;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.idcanet.vasc.xpql.QueryStore;
/**
* TODO: add clonale support
*
* @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,116 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.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,70 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. 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 IDCA 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 IDCA 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.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.xpql.query;
/**
*
* @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

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
com.idcanet.x4o = ALL
# Java 6 has internal logging on many builtin libs
sun.level=OFF
java.level=OFF
javax.level=OFF

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<xtes xmlns="http://xtes.idcanet.com/eld/xtes-lang.eld"
xmlns:x4o="http://x4o.idcanet.com/eld/x4o-lang.eld"
>
<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>
<xslt name="test">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Import of the original stylesheet which "just" creates a bunch of HTML files from any valid DocBook instance -->
<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl"/>
<!-- You must plug-in your custom templates here -->
<xsl:template match="/">
<!-- Call original code from the imported stylesheet -->
<xsl:apply-imports/>
<!-- Call custom templates for the ToC and the manifest -->
<xsl:call-template name="etoc"/>
<!-- DISABLED WRITE PLUGIN.xml(only needed in sepertor help project) <xsl:call-template name="plugin.xml"/> -->
</xsl:template>
</xsl:stylesheet>
</xslt>
<mail name="test-email">
<x4o:property name="mail.from" value="ergens@nowhere.nl"/>
<x4o:property name="mail.subject" value="Check je porn collectie"/>
<x4o:property name="mail.bcc" value="bcc@yoyo.nl"/>
Beste <parameter name="name"/>,<br/>
<br/>
Hier is uw factuur;<br/>
datum: <parameter name="date"/><br/>
total: <parameter name="total"/><br/>
<a href="[#]${appiets.map['key']}[/#]/affiliatelinks.jsp">clickje</a>
<br/>
<br/>
<query name="get_products">
<queryvalue name="userid" value="[from_id/]"/>
</query>
<br/>
<br/>
Groeten,<br/>
<parameter name="full_name"/><br/>
</mail>
<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>
</xtes>

View file

@ -0,0 +1,12 @@
<xtes 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>
</xtes>

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<xtes xmlns="http://xtes.idcanet.com/eld/xtes-lang.eld"
xmlns:x4o="http://x4o.idcanet.com/eld/x4o-lang.eld"
>
<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>
</xtes>