本文整理汇总了Java中org.pentaho.di.core.database.DatabaseMeta.quoteField方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMeta.quoteField方法的具体用法?Java DatabaseMeta.quoteField怎么用?Java DatabaseMeta.quoteField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pentaho.di.core.database.DatabaseMeta
的用法示例。
在下文中一共展示了DatabaseMeta.quoteField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDeleteStatement
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public String getDeleteStatement(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.deleteParameterRowMeta = new RowMeta();
String sql = "DELETE FROM " + data.realSchemaTable + Const.CR;
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
return sql;
}
示例2: preloadCache
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
/**
* Pre-load the cache by reading the whole dimension table from disk...
*
* @throws in case there is a database or cache problem.
*/
private void preloadCache() throws KettleException{
try {
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
// tk, version, from, to, natural keys, retrieval fields...
//
String sql = "SELECT "+databaseMeta.quoteField(meta.getKeyField());
// sql+=", "+databaseMeta.quoteField(meta.getVersionField());
for (int i=0;i<meta.getKeyLookup().length;i++) {
sql+=", "+meta.getKeyLookup()[i]; // the natural key field in the table
}
for (int i=0;i<meta.getFieldLookup().length;i++) {
sql+=", "+meta.getFieldLookup()[i]; // the extra fields to retrieve...
}
sql+=", "+databaseMeta.quoteField(meta.getDateFrom()); // extra info in cache
sql+=", "+databaseMeta.quoteField(meta.getDateTo()); // extra info in cache
sql+=" FROM "+data.schemaTable;
logDetailed("Pre-loading cache by reading from database with: "+Const.CR+sql+Const.CR);
List<Object[]> rows = data.db.getRows(sql, -1);
RowMetaInterface rowMeta = data.db.getReturnRowMeta();
data.preloadKeyIndexes = new int[meta.getKeyLookup().length];
for (int i=0;i<data.preloadKeyIndexes.length;i++) {
data.preloadKeyIndexes[i] = rowMeta.indexOfValue(meta.getKeyLookup()[i]); // the field in the table
}
data.preloadFromDateIndex = rowMeta.indexOfValue(meta.getDateFrom());
data.preloadToDateIndex = rowMeta.indexOfValue(meta.getDateTo());
data.preloadCache = new DimensionCache(rowMeta, data.preloadKeyIndexes, data.preloadFromDateIndex, data.preloadToDateIndex);
data.preloadCache.setRowCache(rows);
logDetailed("Sorting the cache rows...");
data.preloadCache.sortRows();
logDetailed("Sorting of cached rows finished.");
// Also see what indexes to take to populate the lookup row...
// We only ever compare indexes and the lookup date in the cache, the rest is not needed...
//
data.preloadIndexes = new ArrayList<Integer>();
for (int i=0;i<meta.getKeyStream().length;i++) {
int index = getInputRowMeta().indexOfValue(meta.getKeyStream()[i]);
if (index<0) {
// Just to be safe...
//
throw new KettleStepException(Messages.getString("DimensionLookup.Exception.KeyFieldNotFound", meta.getFieldStream()[i])); //$NON-NLS-1$ //$NON-NLS-2$
}
data.preloadIndexes.add(index);
}
// This is all for now...
} catch(Exception e) {
throw new KettleException("Error encountered during cache pre-load", e);
}
}
示例3: setLookup
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void setLookup(RowMetaInterface rowMeta) throws KettleDatabaseException
{
data.lookupParameterRowMeta = new RowMeta();
data.lookupReturnRowMeta = new RowMeta();
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
String sql = "SELECT ";
for (int i = 0; i < meta.getUpdateLookup().length; i++)
{
if (i != 0) sql += ", ";
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
data.lookupReturnRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]).clone() );
}
sql += " FROM " + data.schemaTable + " WHERE ";
for (int i = 0; i < meta.getKeyLookup().length; i++)
{
if (i != 0) sql += " AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
{
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " " + meta.getKeyCondition()[i] + " ";
}
else
{
sql += " " + meta.getKeyCondition()[i] + " ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
}
try
{
if(log.isDetailed()) log.logDetailed(toString(), "Setting preparedStatement to [" + sql + "]");
data.prepStatementLookup = data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch (SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例4: prepareUpdate
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void prepareUpdate(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.updateParameterRowMeta = new RowMeta();
String sql = "UPDATE " + data.schemaTable + Const.CR;
sql += "SET ";
boolean comma=false;
for (int i=0;i<meta.getUpdateLookup().length;i++)
{
if ( meta.getUpdate()[i].booleanValue() ) {
if (comma) sql+= ", ";
else comma=true;
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
sql += " = ?" + Const.CR;
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]).clone() );
}
}
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]).clone() );
}
}
try
{
if(log.isDetailed()) log.logDetailed(toString(), "Setting update preparedStatement to ["+sql+"]");
data.prepStatementUpdate=data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch(SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例5: loadAllTableDataIntoTheCache
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
private void loadAllTableDataIntoTheCache() throws KettleException {
DatabaseMeta dbMeta = meta.getDatabaseMeta();
try {
// We only want to get the used table fields...
//
String sql = "SELECT ";
for (int i=0;i<meta.getStreamKeyField1().length;i++)
{
if (i>0) sql+=", ";
sql+=dbMeta.quoteField(meta.getTableKeyField()[i]);
}
// Also grab the return field...
//
for (int i=0;i<meta.getReturnValueField().length;i++) {
sql+=", "+dbMeta.quoteField(meta.getReturnValueField()[i]);
}
// The schema/table
//
sql+=" FROM "+dbMeta.getQuotedSchemaTableCombination(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTablename()));
// order by?
if (meta.getOrderByClause()!=null && meta.getOrderByClause().length()!=0)
{
sql += " ORDER BY "+meta.getOrderByClause();
}
// Now that we have the SQL constructed, let's store the rows...
//
List<Object[]> rows = data.db.getRows(sql, 0);
if (rows!=null && rows.size()>0) {
RowMetaInterface returnRowMeta = data.db.getReturnRowMeta();
// Copy the data into 2 parts: key and value...
//
for (Object[] row : rows) {
int index=0;
RowMeta keyMeta = new RowMeta();
Object[] keyData = new Object[meta.getStreamKeyField1().length];
for (int i=0;i<meta.getStreamKeyField1().length;i++) {
keyData[i] = row[index];
keyMeta.addValueMeta(returnRowMeta.getValueMeta(index++));
}
// RowMeta valueMeta = new RowMeta();
Object[] valueData = new Object[data.returnMeta.size()];
for (int i=0;i<data.returnMeta.size();i++) {
valueData[i] = row[index++];
// valueMeta.addValueMeta(returnRowMeta.getValueMeta(index++));
}
// Store the data...
//
storeRowInCache(keyMeta, keyData, valueData);
incrementLinesInput();
}
}
}
catch(Exception e) {
throw new KettleException(e);
}
}
示例6: prepareDelete
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void prepareDelete(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.deleteParameterRowMeta = new RowMeta();
String sql = "DELETE FROM " + data.schemaTable + Const.CR;
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
try
{
if (log.isDetailed()) log.logDetailed(toString(), "Setting delete preparedStatement to ["+sql+"]");
data.prepStatementDelete=data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch(SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例7: prepareUpdate
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void prepareUpdate(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.updateParameterRowMeta = new RowMeta();
String sql = "UPDATE " + data.schemaTable + Const.CR;
sql += "SET ";
for (int i=0;i<meta.getUpdateLookup().length;i++)
{
if (i!=0) sql+= ", ";
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
sql += " = ?" + Const.CR;
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]) );
}
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
try
{
if(log.isDetailed()) log.logDetailed(toString(), "Setting update preparedStatement to ["+sql+"]");
data.prepStatementUpdate=data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch(SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例8: getLookupStatement
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public String getLookupStatement(RowMetaInterface rowMeta) throws KettleDatabaseException
{
data.lookupParameterRowMeta = new RowMeta();
data.lookupReturnRowMeta = new RowMeta();
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
String sql = "SELECT ";
for (int i = 0; i < meta.getUpdateLookup().length; i++)
{
if (i != 0) sql += ", ";
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
data.lookupReturnRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]).clone() );
}
sql += " FROM " + data.realSchemaTable + " WHERE ";
for (int i = 0; i < meta.getKeyLookup().length; i++)
{
if (i != 0) sql += " AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
{
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " " + meta.getKeyCondition()[i] + " ";
}
else
{
sql += " " + meta.getKeyCondition()[i] + " ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
}
return sql;
}
示例9: getUpdateStatement
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public String getUpdateStatement(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.updateParameterRowMeta = new RowMeta();
String sql = "UPDATE " + data.realSchemaTable + Const.CR;
sql += "SET ";
boolean comma=false;
for (int i=0;i<meta.getUpdateLookup().length;i++)
{
if ( meta.getUpdate()[i].booleanValue() ) {
if (comma) sql+= ", ";
else comma=true;
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
sql += " = ?" + Const.CR;
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]).clone() );
}
}
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]).clone() );
}
}
return sql;
}
示例10: preloadCache
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
/**
* Pre-load the cache by reading the whole dimension table from disk...
*
* @throws KettleException in case there is a database or cache problem.
*/
private void preloadCache() throws KettleException{
try {
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
// tk, version, from, to, natural keys, retrieval fields...
//
String sql = "SELECT "+databaseMeta.quoteField(meta.getKeyField());
// sql+=", "+databaseMeta.quoteField(meta.getVersionField());
for (int i=0;i<meta.getKeyLookup().length;i++) {
sql+=", "+meta.getKeyLookup()[i]; // the natural key field in the table
}
for (int i=0;i<meta.getFieldLookup().length;i++) {
sql+=", "+meta.getFieldLookup()[i]; // the extra fields to retrieve...
}
sql+=", "+databaseMeta.quoteField(meta.getDateFrom()); // extra info in cache
sql+=", "+databaseMeta.quoteField(meta.getDateTo()); // extra info in cache
sql+=" FROM "+data.schemaTable;
logDetailed("Pre-loading cache by reading from database with: "+Const.CR+sql+Const.CR);
List<Object[]> rows = data.db.getRows(sql, -1);
RowMetaInterface rowMeta = data.db.getReturnRowMeta();
data.preloadKeyIndexes = new int[meta.getKeyLookup().length];
for (int i=0;i<data.preloadKeyIndexes.length;i++) {
data.preloadKeyIndexes[i] = rowMeta.indexOfValue(meta.getKeyLookup()[i]); // the field in the table
}
data.preloadFromDateIndex = rowMeta.indexOfValue(meta.getDateFrom());
data.preloadToDateIndex = rowMeta.indexOfValue(meta.getDateTo());
data.preloadCache = new DimensionCache(rowMeta, data.preloadKeyIndexes, data.preloadFromDateIndex, data.preloadToDateIndex);
data.preloadCache.setRowCache(rows);
logDetailed("Sorting the cache rows...");
data.preloadCache.sortRows();
logDetailed("Sorting of cached rows finished.");
// Also see what indexes to take to populate the lookup row...
// We only ever compare indexes and the lookup date in the cache, the rest is not needed...
//
data.preloadIndexes = new ArrayList<Integer>();
for (int i=0;i<meta.getKeyStream().length;i++) {
int index = data.inputRowMeta.indexOfValue(meta.getKeyStream()[i]);
if (index<0) {
// Just to be safe...
//
throw new KettleStepException(BaseMessages.getString(PKG, "DimensionLookup.Exception.KeyFieldNotFound", meta.getFieldStream()[i])); //$NON-NLS-1$ //$NON-NLS-2$
}
data.preloadIndexes.add(index);
}
// This is all for now...
} catch(Exception e) {
throw new KettleException("Error encountered during cache pre-load", e);
}
}
示例11: setLookup
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void setLookup(RowMetaInterface rowMeta) throws KettleDatabaseException
{
data.lookupParameterRowMeta = new RowMeta();
data.lookupReturnRowMeta = new RowMeta();
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
String sql = "SELECT ";
for (int i = 0; i < meta.getUpdateLookup().length; i++)
{
if (i != 0) sql += ", ";
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
data.lookupReturnRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]).clone() );
}
sql += " FROM " + data.schemaTable + " WHERE ";
for (int i = 0; i < meta.getKeyLookup().length; i++)
{
if (i != 0){
sql += " AND ";
}
sql += " ( ( ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
{
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " " + meta.getKeyCondition()[i] + " ";
}
else if ("= ~NULL".equalsIgnoreCase(meta.getKeyCondition()[i])){
sql += " IS NULL AND ";
if (databaseMeta.requiresCastToVariousForIsNull()) {
sql += " CAST(? AS VARCHAR(256)) IS NULL ";
}
else{
sql += " ? IS NULL ";
}
// null check
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
sql += " ) OR ( "+ databaseMeta.quoteField(meta.getKeyLookup()[i])+" = ? ";
// equality check, cloning so auto-rename because of adding same fieldname does not cause problems
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]).clone() );
}
else
{
sql += " " + meta.getKeyCondition()[i] + " ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
sql += " ) ) ";
}
try
{
if(log.isDetailed()) logDetailed("Setting preparedStatement to [" + sql + "]");
data.prepStatementLookup = data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch (SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例12: prepareUpdate
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void prepareUpdate(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.updateParameterRowMeta = new RowMeta();
String sql = "UPDATE " + data.schemaTable + Const.CR;
sql += "SET ";
boolean comma=false;
for (int i=0;i<meta.getUpdateLookup().length;i++)
{
if ( meta.getUpdate()[i].booleanValue() ) {
if (comma) sql+= ", ";
else comma=true;
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
sql += " = ?" + Const.CR;
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]).clone() );
}
}
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += " ( ( ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else if ("= ~NULL".equalsIgnoreCase(meta.getKeyCondition()[i])){
sql += " IS NULL AND ";
if (databaseMeta.requiresCastToVariousForIsNull()) {
sql += "CAST(? AS VARCHAR(256)) IS NULL";
}
else{
sql += "? IS NULL";
}
// null check
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
sql += " ) OR ( "+ databaseMeta.quoteField(meta.getKeyLookup()[i])+" = ?";
// equality check, cloning so auto-rename because of adding same fieldname does not cause problems
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]).clone() );
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]).clone() );
}
sql += " ) ) ";
}
try
{
if(log.isDetailed()) logDetailed("Setting update preparedStatement to ["+sql+"]");
data.prepStatementUpdate=data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch(SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例13: prepareDelete
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void prepareDelete(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.deleteParameterRowMeta = new RowMeta();
String sql = "DELETE FROM " + data.schemaTable + Const.CR;
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.deleteParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
try
{
if (log.isDetailed()) logDetailed("Setting delete preparedStatement to ["+sql+"]");
data.prepStatementDelete=data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch(SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例14: setLookup
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void setLookup(RowMetaInterface rowMeta) throws KettleDatabaseException
{
data.lookupParameterRowMeta = new RowMeta();
data.lookupReturnRowMeta = new RowMeta();
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
String sql = "SELECT ";
for (int i = 0; i < meta.getUpdateLookup().length; i++)
{
if (i != 0) sql += ", ";
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
data.lookupReturnRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]) );
}
sql += " FROM " + data.schemaTable + " WHERE ";
for (int i = 0; i < meta.getKeyLookup().length; i++)
{
if (i != 0){
sql += " AND ";
}
sql += " ( ( ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else
{
if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " " + meta.getKeyCondition()[i] + " ";
}
else if ("= ~NULL".equalsIgnoreCase(meta.getKeyCondition()[i])){
sql += " IS NULL AND ";
if (databaseMeta.requiresCastToVariousForIsNull()) {
sql += "CAST(? AS VARCHAR(256)) IS NULL";
}
else{
sql += "? IS NULL";
}
// null check
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
sql += " ) OR ( "+ databaseMeta.quoteField(meta.getKeyLookup()[i])+" = ?";
// equality check, cloning so auto-rename because of adding same fieldname does not cause problems
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]).clone() );
}
else
{
sql += " " + meta.getKeyCondition()[i] + " ? ";
data.lookupParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
}
sql += " ) ) ";
}
try
{
if(log.isDetailed()) logDetailed("Setting preparedStatement to [" + sql + "]");
data.prepStatementLookup = data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch (SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}
示例15: prepareUpdate
import org.pentaho.di.core.database.DatabaseMeta; //导入方法依赖的package包/类
public void prepareUpdate(RowMetaInterface rowMeta) throws KettleDatabaseException
{
DatabaseMeta databaseMeta = meta.getDatabaseMeta();
data.updateParameterRowMeta = new RowMeta();
String sql = "UPDATE " + data.schemaTable + Const.CR;
sql += "SET ";
for (int i=0;i<meta.getUpdateLookup().length;i++)
{
if (i!=0) sql+= ", ";
sql += databaseMeta.quoteField(meta.getUpdateLookup()[i]);
sql += " = ?" + Const.CR;
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getUpdateStream()[i]) );
}
sql += "WHERE ";
for (int i=0;i<meta.getKeyLookup().length;i++)
{
if (i!=0) sql += "AND ";
sql += " ( ( ";
sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
if ("BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " BETWEEN ? AND ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream2()[i]) );
}
else if ("IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) || "IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]))
{
sql += " "+meta.getKeyCondition()[i]+" ";
}
else if ("= ~NULL".equalsIgnoreCase(meta.getKeyCondition()[i])){
sql += " IS NULL AND ";
if (databaseMeta.requiresCastToVariousForIsNull()) {
sql += "CAST(? AS VARCHAR(256)) IS NULL";
}
else{
sql += "? IS NULL";
}
// null check
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
sql += " ) OR ( "+ databaseMeta.quoteField(meta.getKeyLookup()[i])+" = ?";
// equality check, cloning so auto-rename because of adding same fieldname does not cause problems
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]).clone() );
}
else
{
sql += " "+meta.getKeyCondition()[i]+" ? ";
data.updateParameterRowMeta.addValueMeta( rowMeta.searchValueMeta(meta.getKeyStream()[i]) );
}
sql += " ) ) ";
}
try
{
if(log.isDetailed()) logDetailed("Setting update preparedStatement to ["+sql+"]");
data.prepStatementUpdate=data.db.getConnection().prepareStatement(databaseMeta.stripCR(sql));
}
catch(SQLException ex)
{
throw new KettleDatabaseException("Unable to prepare statement for SQL statement [" + sql + "]", ex);
}
}