Ejemplo n.º 1
0
 /**
  * Constructor creates and initializes the meta data object create DS object per table
  *
  * @param tableNames - String array of database table names ,It can be zero element array
  * @param singleService - select the service generation mode true one service for whole database
  *     when it false services per table wise
  * @param dataSourceId - carbon datasource id it can be null
  *     <p>When create the connection there are 3 away to do it , First way is provide the relevant
  *     information(url, driver, username, password) which need to create connection that time
  *     other fields(connection, datasourceId) should be null
  *     <p>Second way directly you can provide connection instance
  *     <p>final way is you can provide carbon datasource id(name)
  *     <p>if you wish to use all the tables of database you can provide zero element array
  */
 public DSGenerator(
     String dataSourceId,
     String dbName,
     String[] schemas,
     String[] tableNames,
     boolean singleService,
     String nameSpace,
     String serviceName) {
   this.DSErrorList = new ArrayList<String>();
   try {
     Connection connection;
     String[] tableNameList = tableNames;
     if (dataSourceId != null) {
       connection = createConnection(dataSourceId);
       DatabaseMetaData metaObject = connection.getMetaData();
       if (tableNameList.length == 0) {
         tableNameList = DSGenerator.getTableList(connection, dbName, schemas);
       }
       if (singleService) {
         this.generatedService =
             generateService(
                 dataSourceId, dbName, schemas, tableNameList, metaObject, nameSpace, serviceName);
       } else {
         this.generatedServiceList =
             generateServices(dataSourceId, dbName, schemas, tableNameList, metaObject, nameSpace);
       }
       connection.close();
     }
   } catch (Exception e) {
     log.error("Meta Object initialization failed due to ", e);
   }
 }
Ejemplo n.º 2
0
 public static String[] getSchemas(String datasourceId) throws Exception {
   if (datasourceId != null) {
     Connection connection = createConnection(datasourceId);
     String schemas[] = DSGenerator.getSchemas(connection);
     connection.close();
     return schemas;
   } else {
     return null;
   }
 }
Ejemplo n.º 3
0
 public static String[] getTableList(String datasourceId, String dbName, String[] schemas)
     throws SQLException, DataServiceFault {
   if (datasourceId != null) {
     Connection connection = createConnection(datasourceId);
     String tableList[] = DSGenerator.getTableList(connection, dbName, schemas);
     connection.close();
     return tableList;
   } else {
     return null;
   }
 }
Ejemplo n.º 4
0
 public static String[] getSchemas(Connection connection) throws Exception {
   if (connection != null) {
     List<String> schemaList = new ArrayList<String>();
     DatabaseMetaData mObject = connection.getMetaData();
     ResultSet schemas = mObject.getSchemas();
     while (schemas.next()) {
       schemaList.add(schemas.getString(DBConstants.DataServiceGenerator.TABLE_SCHEM));
     }
     String str[] = schemaList.toArray(new String[schemaList.size()]);
     return str;
   } else {
     return null;
   }
 }
Ejemplo n.º 5
0
 public static String[] getTableList(Connection connection, String dbName, String[] schemas)
     throws SQLException {
   if (connection != null) {
     List<String> tableList = new ArrayList<String>();
     // String dbName = connection.getCatalog();
     DatabaseMetaData mObject = connection.getMetaData();
     if (schemas.length != 0) {
       tableList = getTableNamesList(mObject, dbName, schemas[0]);
       if (tableList.size()
           == 0) { // for some drivers catalog is not same as the dbname (eg: DB2). In that case
         // search tables only using schema.
         tableList = getTableNamesList(mObject, null, schemas[0]);
       }
     } else {
       tableList = getTableNamesList(mObject, dbName, null);
     }
     String str[] = tableList.toArray(new String[tableList.size()]);
     return str;
   } else {
     return null;
   }
 }