Package org.apache.gora.sql.store

Examples of org.apache.gora.sql.store.Column


    StringBuilder buf = new StringBuilder("MERGE INTO ");
    buf.append(tableName).append(" USING (VALUES(");

    i = 0;
    for (Entry<String, ColumnData> e : columnMap.entrySet()) {
      Column column = e.getValue().column;
      if (i != 0) buf.append(",");
      buf.append("CAST(? AS ");
      buf.append(column.getJdbcType().toString());
      if (column.getScaleOrLength() > 0) {
        buf.append("(").append(column.getScaleOrLength()).append(")");
      }
      buf.append(")");
      i++;
    }
    buf.append(")) AS vals(");

    i = 0;
    for (String columnName : columnMap.keySet()) {
      if (i != 0) buf.append(",");
      buf.append(getVariable(columnName));
      i++;
    }

    buf.append(") ON ").append(tableName).append(".").append(mapping.getPrimaryColumnName()).append("=vals.");
    buf.append(getVariable(mapping.getPrimaryColumnName()));

    buf.append(" WHEN MATCHED THEN UPDATE SET ");
    i = 0;
    for (String columnName : columnMap.keySet()) {
      if (columnName.equals(mapping.getPrimaryColumnName())) {
        continue;
      }
      if (i != 0) { buf.append(","); }
      buf.append(tableName).append(".").append(columnName).append("=vals.");
      buf.append(getVariable(columnName));
      i++;
    }

    buf.append(" WHEN NOT MATCHED THEN INSERT (");
    i = 0;
    for (String columnName : columnMap.keySet()) {
      if (i != 0) { buf.append(","); }
      buf.append(columnName);
      i++;
    }
    i = 0;
    buf.append(") VALUES ");
    for (String columnName : columnMap.keySet()) {
      if (i != 0) { buf.append(","); }
      buf.append("vals.").append(getVariable(columnName));
      i++;
    }

    Column primaryColumn = mapping.getPrimaryColumn();
    PreparedStatement insert = connection.prepareStatement(buf.toString());
    int psIndex = 1;
    for (Entry<String, ColumnData> e : columnMap.entrySet()) {
      ColumnData cd = e.getValue();
      Column column = cd.column;
      if (column.getName().equals(primaryColumn.getName())) {
        Object key = columnMap.get(primaryColumn.getName()).object;
        if (primaryColumn.getScaleOrLength() > 0) {
          insert.setObject(psIndex++, key,
              primaryColumn.getJdbcType().getOrder(), primaryColumn.getScaleOrLength());
        } else {
View Full Code Here


    builder.append(") ON DUPLICATE KEY UPDATE ");

    // TODO: Fix this stupid code. We need to make sure primary key field
    // is not in UPDATE part of sql query. This desperately needs a
    // better solution
    Column primaryColumn = mapping.getPrimaryColumn();
    Object key = columnMap.get(primaryColumn.getName()).object;
    i = 0;
    for(String s : columnMap.keySet()) {
      if (s.equals(primaryColumn.getName())) {
        continue;
      }
      if (i != 0) builder.append(",");
      builder.append(s).append("=").append("?");
      i++;
    }
    builder.append(";");

    PreparedStatement insert = connection.prepareStatement(builder.toString());

    int psIndex = 1;
    for (int count = 0; count < 2; count++) {
      for (Entry<String, ColumnData> e : columnMap.entrySet()) {
        ColumnData columnData = e.getValue();
        Column column = columnData.column;
        Schema fieldSchema = columnData.schema;
        Object fieldValue = columnData.object;

        // check if primary key
        if (column.getName().equals(primaryColumn.getName())) {
          if (count == 1) {
            continue;
          }
          if (primaryColumn.getScaleOrLength() > 0) {
            insert.setObject(psIndex++, key,
View Full Code Here

    StringBuilder buf = new StringBuilder("MERGE INTO ");
    buf.append(tableName).append(" USING (VALUES(");

    i = 0;
    for (Entry<String, ColumnData> e : columnMap.entrySet()) {
      Column column = e.getValue().column;
      if (i != 0) buf.append(",");
      buf.append("CAST(? AS ");
      buf.append(column.getJdbcType().toString());
      if (column.getScaleOrLength() > 0) {
        buf.append("(").append(column.getScaleOrLength()).append(")");
      }
      buf.append(")");
      i++;
    }
    buf.append(")) AS vals(");

    i = 0;
    for (String columnName : columnMap.keySet()) {
      if (i != 0) buf.append(",");
      buf.append(getVariable(columnName));
      i++;
    }

    buf.append(") ON ").append(tableName).append(".").append(mapping.getPrimaryColumnName()).append("=vals.");
    buf.append(getVariable(mapping.getPrimaryColumnName()));

    buf.append(" WHEN MATCHED THEN UPDATE SET ");
    i = 0;
    for (String columnName : columnMap.keySet()) {
      if (columnName.equals(mapping.getPrimaryColumnName())) {
        continue;
      }
      if (i != 0) { buf.append(","); }
      buf.append(tableName).append(".").append(columnName).append("=vals.");
      buf.append(getVariable(columnName));
      i++;
    }

    buf.append(" WHEN NOT MATCHED THEN INSERT (");
    i = 0;
    for (String columnName : columnMap.keySet()) {
      if (i != 0) { buf.append(","); }
      buf.append(columnName);
      i++;
    }
    i = 0;
    buf.append(") VALUES ");
    for (String columnName : columnMap.keySet()) {
      if (i != 0) { buf.append(","); }
      buf.append("vals.").append(getVariable(columnName));
      i++;
    }

    Column primaryColumn = mapping.getPrimaryColumn();
    PreparedStatement insert = connection.prepareStatement(buf.toString());
    int psIndex = 1;
    for (Entry<String, ColumnData> e : columnMap.entrySet()) {
      ColumnData cd = e.getValue();
      Column column = cd.column;
      if (column.getName().equals(primaryColumn.getName())) {
        Object key = columnMap.get(primaryColumn.getName()).object;
        if (primaryColumn.getScaleOrLength() > 0) {
          insert.setObject(psIndex++, key,
              primaryColumn.getJdbcType().getOrder(), primaryColumn.getScaleOrLength());
        } else {
View Full Code Here

    builder.append(") ON DUPLICATE KEY UPDATE ");

    // TODO: Fix this stupid code. We need to make sure primary key field
    // is not in UPDATE part of sql query. This desperately needs a
    // better solution
    Column primaryColumn = mapping.getPrimaryColumn();
    Object key = columnMap.get(primaryColumn.getName()).object;
    i = 0;
    for(String s : columnMap.keySet()) {
      if (s.equals(primaryColumn.getName())) {
        continue;
      }
      if (i != 0) builder.append(",");
      builder.append(s).append("=").append("?");
      i++;
    }
    builder.append(";");

    PreparedStatement insert = connection.prepareStatement(builder.toString());

    int psIndex = 1;
    for (int count = 0; count < 2; count++) {
      for (Entry<String, ColumnData> e : columnMap.entrySet()) {
        ColumnData columnData = e.getValue();
        Column column = columnData.column;
        Schema fieldSchema = columnData.schema;
        Object fieldValue = columnData.object;

        // check if primary key
        if (column.getName().equals(primaryColumn.getName())) {
          if (count == 1) {
            continue;
          }
          if (primaryColumn.getScaleOrLength() > 0) {
            insert.setObject(psIndex++, key,
View Full Code Here

TOP

Related Classes of org.apache.gora.sql.store.Column

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.