Ejemplo n.º 1
0
 public void setString(PreparedStatement ps, int param, String value) {
   try {
     if (getDatastoreAdapter().supportsOption(DatastoreAdapter.BLOB_SET_USING_SETSTRING)) {
       if (value == null) {
         if (column.isDefaultable() && column.getDefaultValue() != null) {
           ps.setString(param, column.getDefaultValue().toString().trim());
         } else {
           ps.setNull(param, getTypeInfo().getDataType());
         }
       } else {
         ps.setString(param, value);
       }
     } else {
       if (value == null) {
         if (column != null && column.isDefaultable() && column.getDefaultValue() != null) {
           ps.setBlob(param, new BlobImpl(column.getDefaultValue().toString().trim()));
         } else {
           ps.setNull(param, getTypeInfo().getDataType());
         }
       } else {
         ps.setBlob(param, new BlobImpl(value));
       }
     }
   } catch (SQLException e) {
     throw new NucleusDataStoreException(
         LOCALISER_RDBMS.msg("055001", "String", "" + value, column, e.getMessage()), e);
   } catch (IOException e) {
     throw new NucleusDataStoreException(
         LOCALISER_RDBMS.msg("055001", "String", "" + value, column, e.getMessage()), e);
   }
 }
Ejemplo n.º 2
0
  /* (non-Javadoc)
   * @see org.datanucleus.store.rdbms.mapping.AbstractLargeBinaryRDBMSMapping#getObject(java.lang.Object, int)
   */
  @Override
  public Object getObject(ResultSet rs, int param) {
    byte[] bytes = null;
    try {
      // Retrieve the bytes of the object directly
      bytes = rs.getBytes(param);
      if (bytes == null) {
        return null;
      }
    } catch (SQLException sqle) {
      try {
        // Retrieve the bytes using the Blob (if getBytes not supported e.g HSQLDB 2.0)
        Blob blob = rs.getBlob(param);
        if (blob == null) {
          return null;
        }
        bytes = blob.getBytes(1, (int) blob.length());
        if (bytes == null) {
          return null;
        }
      } catch (SQLException sqle2) {
        throw new NucleusDataStoreException(
            LOCALISER_RDBMS.msg("055002", "Object", "" + param, column, sqle2.getMessage()), sqle2);
      }
    }

    return getObjectForBytes(bytes, param);
  }
Ejemplo n.º 3
0
  /**
   * Method to reserve a block of "size" identities.
   *
   * @param size Block size
   * @return The reserved block
   */
  public ValueGenerationBlock reserveBlock(long size) {
    if (size < 1) {
      return null;
    }

    // search for an ID in the database
    List oid = new ArrayList();
    try {
      if (sequenceTable == null) {
        initialiseSequenceTable();
      }

      DatastoreIdentifier sourceTableIdentifier = null;
      if (properties.getProperty("table-name") != null) {
        sourceTableIdentifier =
            ((RDBMSStoreManager) storeMgr)
                .getIdentifierFactory()
                .newTableIdentifier(properties.getProperty("table-name"));
        // TODO Apply passed in catalog/schema to this identifier rather than the default for the
        // factory
      }
      Long nextId =
          sequenceTable.getNextVal(
              sequenceName,
              connection,
              (int) size,
              sourceTableIdentifier,
              properties.getProperty("column-name"),
              initialValue);
      for (int i = 0; i < size; i++) {
        oid.add(nextId);
        nextId = Long.valueOf(nextId.longValue() + 1);
      }
      if (NucleusLogger.VALUEGENERATION.isDebugEnabled()) {
        NucleusLogger.VALUEGENERATION.debug(LOCALISER.msg("040004", "" + size));
      }
      return new ValueGenerationBlock(oid);
    } catch (SQLException e) {
      throw new ValueGenerationException(LOCALISER_RDBMS.msg("061001", e.getMessage()));
    }
  }
Ejemplo n.º 4
0
  public String getString(ResultSet rs, int param) {
    String value;

    try {
      if (getDatastoreAdapter().supportsOption(DatastoreAdapter.BLOB_SET_USING_SETSTRING)) {
        value = rs.getString(param);
      } else {
        byte[] bytes = rs.getBytes(param);
        if (bytes == null) {
          value = null;
        } else {
          BlobImpl blob = new BlobImpl(bytes);
          value = (String) blob.getObject();
        }
      }
    } catch (SQLException e) {
      throw new NucleusDataStoreException(
          LOCALISER_RDBMS.msg("055002", "String", "" + param, column, e.getMessage()), e);
    }

    return value;
  }