* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
+
package mir.producer;
import java.io.PrintWriter;
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
+
package mir.producer;
import java.util.Map;
--- /dev/null
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package mir.producer;
+
+import java.util.Map;
+
+import mir.log.LoggerWrapper;
+import mir.storage.Database;
+import mir.util.ParameterExpander;
+
+public class FreeQueryProducerNode implements ProducerNode {
+ public static final int QUERY_TYPE_SET = 1;
+ public static final int QUERY_TYPE_ROW = 2;
+ public static final int QUERY_TYPE_VALUE = 3;
+
+ private Database database = new Database();
+ private String key;
+ private String query;
+ private String limitExpression;
+ private int type;
+
+ public FreeQueryProducerNode(String aKey, String aQuery, String aLimit, int aType) {
+ key = aKey;
+ query = aQuery;
+ limitExpression = aLimit;
+ type = aType;
+ }
+
+ public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
+ Object result = null;
+
+ try {
+ switch (type) {
+ case QUERY_TYPE_VALUE:
+ result = database.executeFreeSingleValueSql(ParameterExpander.expandExpression(aValueMap, query));
+ break;
+
+ case QUERY_TYPE_ROW:
+ result = database.executeFreeSingleRowSql(ParameterExpander.expandExpression(aValueMap, query));
+ break;
+
+ case QUERY_TYPE_SET:
+ int limit=10;
+ if (limitExpression!=null)
+ limit=ParameterExpander.evaluateIntegerExpression(aValueMap, limitExpression);
+
+ result = database.executeFreeSql(
+ ParameterExpander.expandExpression( aValueMap, query ),
+ limit);
+ break;
+ }
+ }
+ catch (Throwable t) {
+ aLogger.error("Error while executing free query: " + t.toString());
+ }
+
+ try {
+ ParameterExpander.setValueForKey(
+ aValueMap,
+ ParameterExpander.expandExpression(aValueMap, key),
+ result);
+ }
+ catch (Throwable t) {
+ aLogger.error("Error while setting key " + key + ": " + t.toString());
+ }
+ };
+
+}
\ No newline at end of file
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
package mir.producer.reader;
import mir.producer.LoggingProducerNode;
import mir.producer.LoopProducerNode;
import mir.producer.ProducerNode;
-import mir.producer.RSSProducerNode;
+import mir.producer.*;
import mir.producer.ResourceBundleProducerNode;
import mir.producer.ScriptCallingProducerNode;
import mir.util.XMLReader;
aBuilderLibrary.registerBuilder("RSS", RSSProducerNodeBuilder.class);
+ aBuilderLibrary.registerBuilder("FreeQuery", FreeQueryProducerNodeBuilder.class);
+
aBuilderLibrary.registerFactory("Enumerate", new EnumeratingProducerNodeBuilder.factory(aModel));
aBuilderLibrary.registerFactory("List", new ListProducerNodeBuilder.factory(aModel));
aBuilderLibrary.registerFactory("Batch", new BatchingProducerNodeBuilder.factory(aModel));
////////////////////////////////////////////////////////////////////////////////
+ public static class FreeQueryProducerNodeBuilder extends AbstractProducerNodeBuilder {
+ private final static String FREEQUERY_KEY_ATTRIBUTE = KEY_ATTRIBUTE;
+ private final static String FREEQUERY_LIMIT_ATTRIBUTE = LIMIT_ATTRIBUTE;
+ private final static String FREEQUERY_QUERY_ATTRIBUTE = "query";
+ private final static String FREEQUERY_TYPE_ATTRIBUTE = "type";
+ private final static String[] FREEQUERY_REQUIRED_ATTRIBUTES = { KEY_ATTRIBUTE, FREEQUERY_QUERY_ATTRIBUTE };
+ private final static String[] FREEQUERY_OPTIONAL_ATTRIBUTES = { LIMIT_ATTRIBUTE, FREEQUERY_TYPE_ATTRIBUTE };
+ private final static String[] FREEQUERY_SUBNODES = {};
+
+ private String key;
+ private String query;
+ private String limit;
+ private int type;
+
+ public FreeQueryProducerNodeBuilder() {
+ super(FREEQUERY_SUBNODES);
+ }
+
+ public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc {
+ String typeString;
+
+ XMLReaderTool.checkAttributes(anAttributes, FREEQUERY_REQUIRED_ATTRIBUTES, FREEQUERY_OPTIONAL_ATTRIBUTES);
+
+ key = (String) anAttributes.get(FREEQUERY_KEY_ATTRIBUTE);
+ query = (String) anAttributes.get(FREEQUERY_QUERY_ATTRIBUTE);
+ limit = (String) anAttributes.get(FREEQUERY_LIMIT_ATTRIBUTE);
+
+ if (anAttributes.containsKey(FREEQUERY_TYPE_ATTRIBUTE)) {
+ typeString = ((String) anAttributes.get( FREEQUERY_TYPE_ATTRIBUTE ));
+
+ if (typeString.toLowerCase().equals("set"))
+ type = FreeQueryProducerNode.QUERY_TYPE_SET;
+ else if (typeString.toLowerCase().equals("row"))
+ type = FreeQueryProducerNode.QUERY_TYPE_ROW;
+ else if (typeString.toLowerCase().equals("value"))
+ type = FreeQueryProducerNode.QUERY_TYPE_VALUE;
+ else
+ throw new ProducerConfigExc("unknown query type: " + typeString + " (allowed are set, row and value)");
+ }
+ else
+ type = FreeQueryProducerNode.QUERY_TYPE_SET;
+ };
+
+ public ProducerNode constructNode() {
+ return new FreeQueryProducerNode(key, query, limit, type);
+ };
+ }
+
+////////////////////////////////////////////////////////////////////////////////
+
public static class ResourceBundleProducerNodeBuilder extends AbstractProducerNodeBuilder {
private final static String RESOURCEBUNDLE_KEY_ATTRIBUTE = KEY_ATTRIBUTE;
private final static String RESOURCEBUNDLE_BUNDLE_ATTRIBUTE = "bundle";
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
-import java.util.List;
+import java.util.*;
import java.util.Map;
+import com.codestudio.util.SQLManager;
+
+import freemarker.template.SimpleHash;
+import freemarker.template.SimpleList;
+
import mir.config.MirPropertiesConfiguration;
import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
import mir.entity.Entity;
import mir.storage.store.StoreUtil;
import mir.util.JDBCStringRoutines;
-import com.codestudio.util.SQLManager;
-
-import freemarker.template.SimpleHash;
-import freemarker.template.SimpleList;
-
/**
* Diese Klasse implementiert die Zugriffsschicht auf die Datenbank.
* Treiber, Host, User und Passwort, ueber den der Zugriff auf die
* Datenbank erfolgt.
*
- * @version $Id: Database.java,v 1.40 2003/04/28 00:44:06 zapata Exp $
+ * @version $Id: Database.java,v 1.41 2003/05/02 01:02:45 zapata Exp $
* @author rk
*
*/
public String getCoreTable() {
if (theCoreTable != null) {
return theCoreTable;
- } else {
+ }
+ else {
return theTable;
}
}
if (rs != null) {
try {
switch (aType) {
- case java.sql.Types.BIT:
- outValue = (rs.getBoolean(valueIndex) == true) ? "1" : "0";
+ case java.sql.Types.BIT:
+ outValue = (rs.getBoolean(valueIndex) == true) ? "1" : "0";
- break;
+ break;
- case java.sql.Types.INTEGER:
- case java.sql.Types.SMALLINT:
- case java.sql.Types.TINYINT:
- case java.sql.Types.BIGINT:
+ case java.sql.Types.INTEGER:
+ case java.sql.Types.SMALLINT:
+ case java.sql.Types.TINYINT:
+ case java.sql.Types.BIGINT:
- int out = rs.getInt(valueIndex);
+ int out = rs.getInt(valueIndex);
- if (!rs.wasNull()) {
- outValue = new Integer(out).toString();
- }
+ if (!rs.wasNull()) {
+ outValue = new Integer(out).toString();
+ }
- break;
+ break;
- case java.sql.Types.NUMERIC:
+ case java.sql.Types.NUMERIC:
- /** @todo Numeric can be float or double depending upon
- * metadata.getScale() / especially with oracle */
- long outl = rs.getLong(valueIndex);
+ /** @todo Numeric can be float or double depending upon
+ * metadata.getScale() / especially with oracle */
+ long outl = rs.getLong(valueIndex);
- if (!rs.wasNull()) {
- outValue = new Long(outl).toString();
- }
+ if (!rs.wasNull()) {
+ outValue = new Long(outl).toString();
+ }
- break;
+ break;
- case java.sql.Types.REAL:
+ case java.sql.Types.REAL:
- float tempf = rs.getFloat(valueIndex);
+ float tempf = rs.getFloat(valueIndex);
- if (!rs.wasNull()) {
- tempf *= 10;
- tempf += 0.5;
+ if (!rs.wasNull()) {
+ tempf *= 10;
+ tempf += 0.5;
- int tempf_int = (int) tempf;
- tempf = (float) tempf_int;
- tempf /= 10;
- outValue = "" + tempf;
- outValue = outValue.replace('.', ',');
- }
+ int tempf_int = (int) tempf;
+ tempf = (float) tempf_int;
+ tempf /= 10;
+ outValue = "" + tempf;
+ outValue = outValue.replace('.', ',');
+ }
- break;
+ break;
- case java.sql.Types.DOUBLE:
+ case java.sql.Types.DOUBLE:
- double tempd = rs.getDouble(valueIndex);
+ double tempd = rs.getDouble(valueIndex);
- if (!rs.wasNull()) {
- tempd *= 10;
- tempd += 0.5;
+ if (!rs.wasNull()) {
+ tempd *= 10;
+ tempd += 0.5;
- int tempd_int = (int) tempd;
- tempd = (double) tempd_int;
- tempd /= 10;
- outValue = "" + tempd;
- outValue = outValue.replace('.', ',');
- }
+ int tempd_int = (int) tempd;
+ tempd = (double) tempd_int;
+ tempd /= 10;
+ outValue = "" + tempd;
+ outValue = outValue.replace('.', ',');
+ }
- break;
+ break;
- case java.sql.Types.CHAR:
- case java.sql.Types.VARCHAR:
- case java.sql.Types.LONGVARCHAR:
- outValue = rs.getString(valueIndex);
+ case java.sql.Types.CHAR:
+ case java.sql.Types.VARCHAR:
+ case java.sql.Types.LONGVARCHAR:
+ outValue = rs.getString(valueIndex);
- break;
+ break;
- case java.sql.Types.LONGVARBINARY:
- outValue = rs.getString(valueIndex);
+ case java.sql.Types.LONGVARBINARY:
+ outValue = rs.getString(valueIndex);
- break;
+ break;
- case java.sql.Types.TIMESTAMP:
+ case java.sql.Types.TIMESTAMP:
- // it's important to use Timestamp here as getting it
- // as a string is undefined and is only there for debugging
- // according to the API. we can make it a string through formatting.
- // -mh
- Timestamp timestamp = (rs.getTimestamp(valueIndex));
+ // it's important to use Timestamp here as getting it
+ // as a string is undefined and is only there for debugging
+ // according to the API. we can make it a string through formatting.
+ // -mh
+ Timestamp timestamp = (rs.getTimestamp(valueIndex));
- if (!rs.wasNull()) {
- java.util.Date date = new java.util.Date(timestamp.getTime());
- outValue = _dateFormatterOut.format(date);
- _cal.setTime(date);
+ if (!rs.wasNull()) {
+ java.util.Date date = new java.util.Date(timestamp.getTime());
+ outValue = _dateFormatterOut.format(date);
+ _cal.setTime(date);
- int offset =
- _cal.get(Calendar.ZONE_OFFSET) + _cal.get(Calendar.DST_OFFSET);
- String tzOffset =
- StringUtil.zeroPaddingNumber(offset / _millisPerHour, 2, 2);
- outValue = outValue + "+" + tzOffset;
- }
+ int offset =
+ _cal.get(Calendar.ZONE_OFFSET) + _cal.get(Calendar.DST_OFFSET);
+ String tzOffset =
+ StringUtil.zeroPaddingNumber(offset / _millisPerHour, 2, 2);
+ outValue = outValue + "+" + tzOffset;
+ }
- break;
+ break;
- default:
- outValue = "<unsupported value>";
- logger.warn( "Unsupported Datatype: at " + valueIndex + " (" + aType + ")");
+ default:
+ outValue = "<unsupported value>";
+ logger.warn("Unsupported Datatype: at " + valueIndex + " (" + aType + ")");
}
} catch (SQLException e) {
throw new StorageObjectFailure("Could not get Value out of Resultset -- ",
* @return EntityList mit den gematchten Entities
* @exception StorageObjectException
*/
- public EntityList selectByWhereClause(String where)
- throws StorageObjectFailure {
+ public EntityList selectByWhereClause(String where) throws StorageObjectFailure {
return selectByWhereClause(where, 0);
}
* @return EntityList mit den gematchten Entities
* @exception StorageObjectException
*/
- public EntityList selectByWhereClause(String whereClause, int offset)
- throws StorageObjectFailure {
+ public EntityList selectByWhereClause(String whereClause, int offset) throws StorageObjectFailure {
return selectByWhereClause(whereClause, null, offset);
}
* @return EntityList mit den gematchten Entities
* @exception StorageObjectException
*/
- public EntityList selectByWhereClause(String where, String order)
- throws StorageObjectFailure {
+ public EntityList selectByWhereClause(String where, String order) throws StorageObjectFailure {
return selectByWhereClause(where, order, 0);
}
* @return EntityList mit den gematchten Entities
* @exception StorageObjectException
*/
- public EntityList selectByWhereClause(String whereClause, String orderBy,
- int offset) throws StorageObjectFailure {
+ public EntityList selectByWhereClause(String whereClause, String orderBy, int offset) throws StorageObjectFailure {
return selectByWhereClause(whereClause, orderBy, offset, defaultLimit);
}
/**
* select-Operator liefert eine EntityListe mit den gematchten Datens?tzen zur?ck.
- * @param wc where-Clause
- * @param ob orderBy-Clause
+ * @param aWhereClause where-Clause
+ * @param anOrderByClause orderBy-Clause
* @param offset ab welchem Datensatz
* @param limit wieviele Datens?tze
* @return EntityList mit den gematchten Entities
* @exception StorageObjectException
*/
- public EntityList selectByWhereClause(String wc, String ob, int offset,
- int limit) throws StorageObjectFailure {
+ public EntityList selectByWhereClause(String aWhereClause, String anOrderByClause,
+ int offset, int limit) throws StorageObjectFailure {
+
// check o_store for entitylist
if (StoreUtil.implementsStorableObject(theEntityClass)) {
StoreIdentifier search_sid =
- new StoreIdentifier(theEntityClass,
- StoreContainerType.STOC_TYPE_ENTITYLIST,
- StoreUtil.getEntityListUniqueIdentifierFor(theTable, wc, ob, offset,
- limit));
+ new StoreIdentifier(
+ theEntityClass, StoreContainerType.STOC_TYPE_ENTITYLIST,
+ StoreUtil.getEntityListUniqueIdentifierFor(theTable, aWhereClause, anOrderByClause, offset, limit));
EntityList hit = (EntityList) o_store.use(search_sid);
if (hit != null) {
/** @todo count sql string should only be assembled if we really count
* see below at the end of method //rk */
- if ((wc != null) && (wc.trim().length() == 0)) {
- wc = null;
+ if ((aWhereClause != null) && (aWhereClause.trim().length() == 0)) {
+ aWhereClause = null;
}
StringBuffer countSql =
StringBuffer selectSql =
new StringBuffer("select * from ").append(theTable);
- if (wc != null) {
- selectSql.append(" where ").append(wc);
- countSql.append(" where ").append(wc);
+ if (aWhereClause != null) {
+ selectSql.append(" where ").append(aWhereClause);
+ countSql.append(" where ").append(aWhereClause);
}
- if ((ob != null) && !(ob.trim().length() == 0)) {
- selectSql.append(" order by ").append(ob);
+ if ((anOrderByClause != null) && !(anOrderByClause.trim().length() == 0)) {
+ selectSql.append(" order by ").append(anOrderByClause);
}
if (theAdaptor.hasLimit()) {
theReturnList.setCount(count);
theReturnList.setOffset(offset);
- theReturnList.setWhere(wc);
- theReturnList.setOrder(ob);
+ theReturnList.setWhere(aWhereClause);
+ theReturnList.setOrder(anOrderByClause);
theReturnList.setStorage(this);
theReturnList.setLimit(limit);
} else {
throwStorageObjectException("Internal Error: theEntityClass not set!");
}
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e) {
throwStorageObjectException("No access! -- " + e.getMessage());
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throwStorageObjectException("IOException! -- " + e.getMessage());
- } catch (InstantiationException e) {
+ }
+ catch (InstantiationException e) {
throwStorageObjectException("No Instatiation! -- " + e.getMessage());
- } catch (SQLException sqe) {
+ }
+ catch (SQLException sqe) {
throwSQLException(sqe, "makeEntityFromResultSet");
return null;
return rs;
}
+ public ResultSet executeSql(String sql) throws StorageObjectFailure, SQLException {
+ long startTime = System.currentTimeMillis();
+
+ try {
+ Connection connection = getPooledCon();
+ Statement statement = connection.createStatement();
+ ResultSet result;
+
+ result = statement.executeQuery(sql);
+
+ logger.debug((System.currentTimeMillis() - startTime) + "ms. for: " + sql);
+ return result;
+ }
+ catch (Throwable e) {
+ logger.error(e.getMessage() +"\n" + (System.currentTimeMillis() - startTime) + "ms. for: " + sql);
+ throw new StorageObjectFailure(e);
+ }
+ }
+
+ private Map processRow(ResultSet aResultSet) throws StorageObjectFailure, StorageObjectExc {
+ try {
+ Map result = new HashMap();
+ ResultSetMetaData metaData = aResultSet.getMetaData();
+ int nrColumns = metaData.getColumnCount();
+ for (int i=0; i<nrColumns; i++) {
+ result.put(metaData.getColumnName(i+1), getValueAsString(aResultSet, i+1, metaData.getColumnType(i+1)));
+ }
+
+ return result;
+ }
+ catch (Throwable e) {
+ throw new StorageObjectFailure(e);
+ }
+ }
+
+ public List executeFreeSql(String sql, int aLimit) throws StorageObjectFailure, StorageObjectExc {
+ try {
+ ResultSet resultset = executeSql(sql);
+ List result = new Vector();
+
+ while (resultset.next() && result.size() < aLimit) {
+ result.add(processRow(resultset));
+ }
+
+ return result;
+ }
+ catch (Throwable e) {
+ throw new StorageObjectFailure(e);
+ }
+ };
+
+ public Map executeFreeSingleRowSql(String sql) throws StorageObjectFailure, StorageObjectExc {
+ try {
+ ResultSet resultset = executeSql(sql);
+
+ if (resultset.next())
+ return processRow(resultset);
+ else
+ return null;
+ }
+ catch (Throwable t) {
+ throw new StorageObjectFailure(t);
+ }
+ };
+
+ public String executeFreeSingleValueSql(String sql) throws StorageObjectFailure, StorageObjectExc {
+ Map row = executeFreeSingleRowSql(sql);
+
+ if (row==null)
+ return null;
+
+ Iterator i = row.values().iterator();
+ if (i.hasNext())
+ return (String) i.next();
+ else
+ return null;
+ };
+
/**
* returns the number of rows in the table
*/
long startTime = System.currentTimeMillis();
String sql = "SELECT Count(*) FROM " + theTable;
- if ((where != null) && !(where.length() == 0)) {
+ if ((where != null) && (where.length() != 0)) {
sql = sql + " where " + where;
}
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
package mir.storage;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
+import java.util.Map;
-import mir.entity.Entity;
-import mir.entity.EntityList;
import freemarker.template.SimpleHash;
import freemarker.template.SimpleList;
+import mir.entity.Entity;
+import mir.entity.EntityList;
+
/**
* Implementiert Interface f?r die Speicherschicht.
abstract public Connection getPooledCon() throws StorageObjectFailure;
/**
- * Dokumentation siehe Database.java
+ *
* @param a
* @param sql
- * @return ResultSet
- * @exception StorageObjectException, SQLException
+ * @return
+ * @throws StorageObjectFailure
+ * @throws SQLException
+ */
+ abstract public ResultSet executeSql(Statement a, String sql) throws StorageObjectFailure, SQLException;
+
+ /**
+ *
+ * @param sql
+ * @return
+ * @throws StorageObjectFailure
+ * @throws SQLException
*/
- abstract public ResultSet executeSql(Statement a, String sql)
- throws StorageObjectFailure, SQLException;
+ abstract public ResultSet executeSql(String sql) throws StorageObjectFailure, SQLException;
+
+ /**
+ * Executes 1 sql statement and returns the results as a <code>List</code> of <code>Map</code>s
+ *
+ * @param sql
+ * @return
+ * @throws StorageObjectFailure
+ * @throws StorageObjectExc
+ */
+ abstract public List executeFreeSql(String sql, int aLimit) throws StorageObjectFailure, StorageObjectExc;
+
+ /**
+ * Executes 1 sql statement and returns the first result row as a <<code>Map</code>s
+ * (<code>null</code> if there wasn't any row)
+ *
+ * @param sql
+ * @return
+ * @throws StorageObjectFailure
+ * @throws StorageObjectExc
+ */
+ abstract public Map executeFreeSingleRowSql(String sql) throws StorageObjectFailure, StorageObjectExc ;
+
+ /**
+ * Executes 1 sql statement and returns the first column of the first result row as a <<code>String</code>s
+ * (<code>null</code> if there wasn't any row)
+ *
+ * @param sql
+ * @return
+ * @throws StorageObjectFailure
+ * @throws StorageObjectExc
+ */
+ abstract public String executeFreeSingleValueSql(String sql) throws StorageObjectFailure, StorageObjectExc ;
/**
* Dokumentation siehe Database.java
}
}
- protected void constructContentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure {
+ protected void constructContentAdapterDefinition(EntityAdapterDefinition anEntityAdapterDefinition) throws MirLocalizerFailure, MirLocalizerExc {
try {
anEntityAdapterDefinition.addDBDateField("creationdate", "webdb_create");
anEntityAdapterDefinition.addDBDateField("changedate", "webdb_lastchange");
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
package mircoders.module;
import mir.log.LoggerWrapper;
-import mir.module.AbstractModule;
+import mir.module.*;
+import mir.util.*;
import mir.storage.StorageObject;
public class ModuleArticleType extends AbstractModule {
this.theStorage = theStorage;
}
+
+ public String articleTypeIdForName(String aName) throws ModuleExc, ModuleFailure {
+ try {
+ return theStorage.executeFreeSingleValueSql("select id from article_type where name = '" + JDBCStringRoutines.escapeStringLiteral(aName) + "'");
+ }
+ catch (Throwable t) {
+ throw new ModuleFailure(t);
+ }
+ }
+
}
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
package mircoders.module;
import mir.log.LoggerWrapper;
-import mir.module.AbstractModule;
+import mir.module.*;
import mir.storage.StorageObject;
+import mir.util.*;
/**
* Title: mir - another content management system
static LoggerWrapper logger = new LoggerWrapper("Module.Language");
public ModuleLanguage (StorageObject theStorage) {
-
if (theStorage == null)
logger.warn("ModuleLanguage -- StorageObject was null!");
this.theStorage = theStorage;
}
+
+ public String languageIdForCode(String aCode) throws ModuleExc, ModuleFailure {
+ try {
+ return theStorage.executeFreeSingleValueSql("select id from language where code = '" + JDBCStringRoutines.escapeStringLiteral(aCode) + "'");
+ }
+ catch (Throwable t) {
+ throw new ModuleFailure(t);
+ }
+ }
}
\ No newline at end of file