/** Create the data-service for select data by given key operation. */
  private void addSelectWithKeyOperation(
      DataService dataServiceObject,
      String schema,
      DatabaseMetaData metaData,
      String dbName,
      String tableName,
      String pKey)
      throws SQLException, DataServiceFault, NullPointerException {
    Map<String, WithParam> paramMap = new HashMap<String, WithParam>();
    List<String> paramList = new ArrayList<String>();

    ResultSet columnNames = getColumnNames(metaData, schema, dbName, tableName, null);
    String colomNames = "";
    int i = 0;
    while (columnNames.next()) {
      String name = columnNames.getString(DBConstants.DataServiceGenerator.COLUMN_NAME);
      // get the colomn names for the query
      if (i == 0) {
        colomNames = " " + name;
      } else {
        colomNames = colomNames + ", " + name;
      }
      i++;
      if (pKey.equals(name)) {
        WithParam withParam =
            new WithParam(pKey, pKey, pKey, DBConstants.DataServiceGenerator.QUERY_PARAM);
        paramMap.put(pKey, withParam);
        paramList.add(pKey);
      }
    }
    Set<String> requiredRoles = new HashSet<String>();
    String queryId =
        DBConstants.DataServiceGenerator.SELECT_WITH_KEY
            + tableName
            + DBConstants.DataServiceGenerator._QUERY;
    String OpName =
        DBConstants.DataServiceGenerator.SELECT_WITH_KEY
            + tableName
            + DBConstants.DataServiceGenerator._OPERATION;
    CallQuery callQuery = new CallQuery(dataServiceObject, queryId, paramMap, requiredRoles);
    List<CallQuery> callQueries = new ArrayList<CallQuery>();
    callQueries.add(callQuery);
    CallQueryGroup callQueryGroup = new CallQueryGroup(callQueries);
    // batchRequest=false
    // parentOperation=null
    Operation operation =
        new Operation(dataServiceObject, OpName, null, callQueryGroup, false, null, false, false);
    dataServiceObject.addOperation(operation);
    dataServiceObject.addQuery(
        this.getSelectWithKeyQuery(
            paramList,
            pKey,
            queryId,
            tableName,
            dataServiceObject,
            metaData,
            dbName,
            schema,
            colomNames));
  }
  /** Select all operation. */
  private void addSelectAllOperation(
      DataService dataServiceObject,
      String schema,
      DatabaseMetaData metaData,
      String dbName,
      String tableName,
      String pKey)
      throws SQLException, DataServiceFault, NullPointerException {

    Map<String, WithParam> paramMap = new HashMap<String, WithParam>();
    List<String> paramList = new ArrayList<String>();
    /* get the primary key */
    // ResultSet resultSet = this.metaObject.getColumns(this.dbName, null,
    // this.tableName, null);
    ResultSet columnNames = getColumnNames(metaData, schema, dbName, tableName, null);
    String colomNames = "";
    int i = 0;
    while (columnNames.next()) {
      String name = columnNames.getString(DBConstants.DataServiceGenerator.COLUMN_NAME);
      if (i == 0) {
        colomNames = " " + name;
      } else {
        colomNames = colomNames + ", " + name;
      }
      i++;
    }
    paramMap.clear();
    Set<String> requiredRoles = new HashSet<String>(); // empty set
    String queryId =
        new StringBuilder()
            .append(DBConstants.DataServiceGenerator.SELECT_ALL)
            .append(tableName)
            .append(DBConstants.DataServiceGenerator._QUERY)
            .toString();
    String OpName =
        new StringBuilder()
            .append(DBConstants.DataServiceGenerator.SELECT_ALL)
            .append(tableName)
            .append(DBConstants.DataServiceGenerator._OPERATION)
            .toString();
    CallQuery callQuery = new CallQuery(dataServiceObject, queryId, paramMap, requiredRoles);
    List<CallQuery> callQueries = new ArrayList<CallQuery>();
    callQueries.add(callQuery);
    CallQueryGroup callQueryGroup = new CallQueryGroup(callQueries);
    // batchRequest=false
    // parentOperation=null
    Operation operation =
        new Operation(dataServiceObject, OpName, null, callQueryGroup, false, null, false, false);
    dataServiceObject.addOperation(operation);
    dataServiceObject.addQuery(
        this.getSelectAllQuery(
            paramList,
            queryId,
            tableName,
            dataServiceObject,
            metaData,
            dbName,
            schema,
            colomNames));
  }
  private void makeServices(
      String dbName,
      String[] tableNames,
      DatabaseMetaData metaData,
      List<DataService> dataServiceList,
      String schema,
      String datasourceId,
      String serviceNamespace)
      throws SQLException, DataServiceFault {

    for (String tableName : tableNames) {
      String serviceName = tableName + DBConstants.DataServiceGenerator.SERVICE_NAME_SUFFIX;
      DataService dataService =
          new DataService(
              serviceName,
              DBConstants.DataServiceGenerator.MUTLIPLE_SERVICE_DESCRIPTION,
              null,
              null,
              DBConstants.DataServiceGenerator.ACTIVE,
              false,
              false,
              false,
              null);
      if (DBUtils.isEmptyString(serviceNamespace)) {
        dataService.setServiceNamespace(DBConstants.WSO2_DS_NAMESPACE);
      } else {
        dataService.setServiceNamespace(serviceNamespace);
      }
      this.setConfig(dataService, datasourceId);
      String tablePrimaryKey = this.getPrimaryKey(metaData, dbName, schema, tableName);
      this.addOperations(dataService, schema, metaData, dbName, tableName, tablePrimaryKey);
      dataServiceList.add(dataService);
    }
  }
Exemple #4
0
 public static void populateStandardCustomDSProps(
     Map<String, String> dsProps, DataService dataService, Config config) {
   String dsInfo =
       dataService.getTenantId() + "#" + dataService.getName() + "#" + config.getConfigId();
   dsProps.put(
       DBConstants.CustomDataSource.DATASOURCE_ID,
       UUID.nameUUIDFromBytes(dsInfo.getBytes(Charset.forName(DBConstants.DEFAULT_CHAR_SET_TYPE)))
           .toString());
   if (log.isDebugEnabled()) {
     log.debug(
         "Custom Inline Data Source; ID: "
             + dsInfo
             + " UUID:"
             + dsProps.get(DBConstants.CustomDataSource.DATASOURCE_ID));
   }
 }
  /** Update Operation. */
  private void addUpdateOperation(
      DataService dataServiceObject,
      String schema,
      DatabaseMetaData metaData,
      String dbName,
      String tableName,
      String pKey)
      throws SQLException, DataServiceFault {
    Map<String, WithParam> paramMap = new HashMap<String, WithParam>();
    List<String> paramList = new ArrayList<String>();

    ResultSet columnNames = getColumnNames(metaData, schema, dbName, tableName, null);
    while (columnNames.next()) {
      String name = columnNames.getString(DBConstants.DataServiceGenerator.COLUMN_NAME);
      if (!name.equals(pKey)) {
        WithParam withParam1 =
            new WithParam(name, name, name, DBConstants.DataServiceGenerator.QUERY_PARAM);
        paramMap.put(name, withParam1);
        paramList.add(name); // add to this @param into @param List
      }
    }
    WithParam withParam2 =
        new WithParam(pKey, pKey, pKey, DBConstants.DataServiceGenerator.QUERY_PARAM);
    paramMap.put(pKey, withParam2);
    paramList.add(pKey);
    Set<String> requiredRoles = new HashSet<String>(); // empty set
    String queryId =
        DBConstants.DataServiceGenerator.UPDATE_
            + tableName
            + DBConstants.DataServiceGenerator._QUERY;
    String OpName =
        DBConstants.DataServiceGenerator.UPDATE_
            + tableName
            + DBConstants.DataServiceGenerator._OPERATION;
    CallQuery callQuery = new CallQuery(dataServiceObject, queryId, paramMap, requiredRoles);
    List<CallQuery> callQueries = new ArrayList<CallQuery>();
    callQueries.add(callQuery);
    CallQueryGroup callQueryGroup = new CallQueryGroup(callQueries);
    // batchRequest=false
    // parentOperation=null
    Operation operation =
        new Operation(dataServiceObject, OpName, null, callQueryGroup, false, null, false, false);
    dataServiceObject.addOperation(operation);
    dataServiceObject.addQuery(
        this.getUpdateQuery(
            paramList, pKey, queryId, tableName, dataServiceObject, metaData, dbName, schema));
  }
Exemple #6
0
 /**
  * Check the given password is encrypted or not, if its encrypted resolve the password.
  *
  * @param dataService Data service object
  * @param password Password before resolving
  * @return Resolved password
  */
 public static String resolvePasswordValue(DataService dataService, String password) {
   SecretResolver secretResolver = dataService.getSecretResolver();
   if (secretResolver != null && secretResolver.isTokenProtected(password)) {
     return secretResolver.resolve(password);
   } else {
     return password;
   }
 }
  /** Insert Operation. */
  private void addInsertOperation(
      DataService dataServiceObject,
      String schema,
      DatabaseMetaData metaData,
      String dbName,
      String tableName)
      throws DataServiceFault, SQLException {

    /* do insertion operation */
    Map<String, WithParam> paramMap = new HashMap<String, WithParam>();
    List<String> paramList = new ArrayList<String>();
    ResultSet columnNames = getColumnNames(metaData, schema, dbName, tableName, null);

    while (columnNames.next()) {
      if (this.isAutoIncrementField(columnNames)) {
        continue;
      }
      String name = columnNames.getString(DBConstants.DataServiceGenerator.COLUMN_NAME);
      WithParam withParam =
          new WithParam(name, name, name, DBConstants.DataServiceGenerator.QUERY_PARAM);
      paramMap.put(name, withParam);
      paramList.add(name);
    }
    Set<String> requiredRoles = new HashSet<String>();
    String queryId =
        DBConstants.DataServiceGenerator.INSERT_
            + tableName
            + DBConstants.DataServiceGenerator._QUERY;
    String OpName =
        DBConstants.DataServiceGenerator.INSERT_
            + tableName
            + DBConstants.DataServiceGenerator._OPERATION;
    CallQuery callQuery = new CallQuery(dataServiceObject, queryId, paramMap, requiredRoles);
    List<CallQuery> callQueries = new ArrayList<CallQuery>();
    callQueries.add(callQuery);
    CallQueryGroup callQueryGroup = new CallQueryGroup(callQueries);
    // batchRequest=false
    // parentOperation=null
    Operation op =
        new Operation(dataServiceObject, OpName, null, callQueryGroup, false, null, false, false);
    dataServiceObject.addOperation(op);
    dataServiceObject.addQuery(
        this.getInsertQuery(
            paramList, queryId, tableName, dataServiceObject, metaData, dbName, schema));
  }
 private void setConfig(DataService dataServiceObject, String carbonSourceId)
     throws DataServiceFault {
   Map<String, String> properties = new HashMap<String, String>();
   properties.put(DBConstants.CarbonDatasource.NAME, carbonSourceId);
   Config config =
       new SQLCarbonDataSourceConfig(
           dataServiceObject, DBConstants.DataServiceGenerator.CONFIG_ID, properties);
   dataServiceObject.addConfig(config);
 }
 private DataService generateService(
     String datasourceId,
     String dbName,
     String[] schemas,
     String[] tableNames,
     DatabaseMetaData metaData,
     String serviceNamespace,
     String serviceName)
     throws DataServiceFault, SQLException {
   // String serviceName = dbName + DBConstants.DataServiceGenerator.SERVICE_NAME_SUFFIX;
   DataService dataService =
       new DataService(
           serviceName,
           DBConstants.DataServiceGenerator.SINGLE_SERVICE_DESCRIPTION,
           null,
           null,
           DBConstants.DataServiceGenerator.ACTIVE,
           false,
           false,
           false,
           null);
   this.setConfig(dataService, datasourceId);
   if (DBUtils.isEmptyString(serviceNamespace)) {
     dataService.setServiceNamespace(DBConstants.WSO2_DS_NAMESPACE);
   } else {
     dataService.setServiceNamespace(serviceNamespace);
   }
   if (schemas.length != 0) {
     for (String schema : schemas) {
       makeService(dbName, tableNames, metaData, dataService, schema);
     }
   } else {
     String schema = null;
     makeService(dbName, tableNames, metaData, dataService, schema);
   }
   return dataService;
 }