Java Code Examples for org.pentaho.metadata.model.Domain#setId()

The following examples show how to use org.pentaho.metadata.model.Domain#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PentahoMetaDataTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public IMetadataDomainRepository getMetadataDomainRepository( final String domainId,
                                                              final ResourceManager resourceManager,
                                                              final ResourceKey contextKey,
                                                              final String xmiFile )
  throws ReportDataFactoryException {
  try {
    final InputStream stream = createStream( resourceManager, contextKey, xmiFile );
    try {
      final InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
      final XmiParser parser = new XmiParser();
      final Domain domain = parser.parseXmi( stream );
      // add a couple of agg types to the quantity ordered physical column
      final IPhysicalTable table =
        ( (SqlPhysicalModel) domain.getPhysicalModels().get( 0 ) ).getPhysicalTables().get( 7 );
      final IPhysicalColumn col = table.getPhysicalColumns().get( 3 );
      final List<AggregationType> list = new ArrayList<AggregationType>();
      list.add( AggregationType.SUM );
      list.add( AggregationType.AVERAGE );
      col.setAggregationList( list );
      domain.setId( domainId );
      repo.storeDomain( domain, true );
      return repo;
    } finally {
      stream.close();
    }
  } catch ( final Exception e ) {
    throw new ReportDataFactoryException( "The Specified XMI File is invalid: " + xmiFile, e );
  }
}
 
Example 2
Source File: XmiParserIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testComplexJoinsInXmi() throws Exception {

  // This unit test loads an XMI domain containing
  // a complex join, and also executes a basic query
  // verifying that the complex join is resolved.

  Domain domain = parser.parseXmi( getClass().getResourceAsStream( "/samples/complex_join.xmi" ) );
  domain.setId( "test domain" );
  assertTrue( domain.getLogicalModels().get( 0 ).getLogicalRelationships().get( 0 ).isComplex() );
  assertEquals( "[BT_ORDERS_ORDERS.BC_ORDERS_ORDERNUMBER]=[BT_ORDERFACT_ORDERFACT.BC_ORDERFACT_ORDERNUMBER]",
      domain.getLogicalModels().get( 0 ).getLogicalRelationships().get( 0 ).getComplexJoin() );

  String mql =
      "<mql>" + "<domain_type>relational</domain_type>" + "<domain_id>test domain</domain_id>"
          + "<model_id>BV_MODEL_1</model_id>" + "<model_name>Model 1</model_name>" + "<options>"
          + "  <disable_distinct>false</disable_distinct>" + "</options>" + "<selections>" + "  <selection>"
          + "    <view>BC_ORDERS</view>" + "    <column>BC_ORDERS_STATUS</column>"
          + "    <aggregation>none</aggregation>" + "  </selection>" + "  <selection>"
          + "    <view>BC_ORDERFACT</view>" + "    <column>BC_ORDERFACT_PRODUCTCODE</column>"
          + "    <aggregation>none</aggregation>" + "  </selection>" + "</selections>" + "<constraints/>"
          + "<orders/>" + "</mql>";

  InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  repo.storeDomain( domain, false );
  QueryXmlHelper helper = new QueryXmlHelper();
  Query query = helper.fromXML( repo, mql );

  SqlGenerator generator = new SqlGenerator();
  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
  MappedQuery queryObj = generator.generateSql( query, "en_US", repo, databaseMeta );
  // TestHelper.printOutJava(queryObj.getQuery());
  TestHelper
      .assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n" + "          BT_ORDERS_ORDERS.STATUS AS COL0\n"
      + "         ,BT_ORDERFACT_ORDERFACT.PRODUCTCODE AS COL1\n" + "FROM \n"
      + "          ORDERFACT BT_ORDERFACT_ORDERFACT\n" + "         ,ORDERS BT_ORDERS_ORDERS\n" + "WHERE \n"
          + "          (  BT_ORDERS_ORDERS.ORDERNUMBER  =  BT_ORDERFACT_ORDERFACT.ORDERNUMBER  )\n", queryObj
          .getQuery() );

}
 
Example 3
Source File: SqlOpenFormulaIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testMqlDateParams() throws Exception {
  Domain steelWheelsDomain = new XmiParser().parseXmi( getClass().getResourceAsStream( "/steel-wheels.xmi" ) );

  String mql =
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<mql>" + "<domain_id>Steel-Wheels</domain_id>"
          + "<model_id>BV_ORDERS</model_id>" + "<options>" + "<disable_distinct>false</disable_distinct>"
          + "</options>" + "<parameters>" + "<parameter defaultValue=\"2004-01-01\" name=\"date\" type=\"STRING\"/>"
          + "</parameters>" + "<selections>" + "<selection>" + "<view>BC_CUSTOMER_W_TER_</view>"
          + "<column>BC_CUSTOMER_W_TER_CUSTOMERNUMBER</column>" + "<aggregation>NONE</aggregation>" + "</selection>"
          + "<selection>" + "<view>CAT_ORDERS</view>" + "<column>BC_ORDERS_ORDERDATE</column>"
          + "<aggregation>NONE</aggregation>" + "</selection>" + "</selections>" + "<constraints>" + "<constraint>"
          + "<operator/>" + "<condition>[CAT_ORDERS.BC_ORDERS_ORDERDATE] "
          + "&gt;DATEVALUE([param:date])</condition>" + "</constraint>" + "</constraints>" + "<orders/>" + "</mql>";

  QueryXmlHelper helper = new QueryXmlHelper();
  InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  steelWheelsDomain.setId( "Steel-Wheels" );

  repo.storeDomain( steelWheelsDomain, false );
  Query query = helper.fromXML( repo, mql );

  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$

  SqlGenerator generator = new SqlGenerator();
  MappedQuery mappedQuery = generator.generateSql( query, "en_US", repo, databaseMeta );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n"
      + "          BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER AS COL0\n"
      + "         ,BT_ORDERS_ORDERS.ORDERDATE AS COL1\n" + "FROM \n"
      + "          CUSTOMER_W_TER BT_CUSTOMER_W_TER_CUSTOMER_W01\n" + "         ,ORDERS BT_ORDERS_ORDERS\n"
      + "WHERE \n"
      + "          ( BT_ORDERS_ORDERS.CUSTOMERNUMBER = BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER )\n"
      + "      AND \n" + "        (\n" + "          (\n"
      + "              BT_ORDERS_ORDERS.ORDERDATE  > TO_DATE('2004-01-01','YYYY-MM-DD')\n" + "          )\n"
      + "        )\n", mappedQuery.getQuery() );
}
 
Example 4
Source File: AutoModeler.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Domain generateDomain( final ImportStrategy importStrategy ) throws PentahoMetadataException {
  Domain domain = new Domain();
  domain.setId( modelName );

  List<LocaleType> locales = new ArrayList<LocaleType>();
  locales.add( new LocaleType( "en_US", "English (US)" ) ); //$NON-NLS-1$ //$NON-NLS-2$
  domain.setLocales( locales );

  SqlPhysicalModel physicalModel = new SqlPhysicalModel();
  physicalModel.setId( databaseMeta.getName() );
  physicalModel.setDatasource( ThinModelConverter.convertFromLegacy( databaseMeta ) );

  Database database = database();

  try {
    // Add the database connection to the empty schema...
    //
    domain.addPhysicalModel( physicalModel );

    // Also add a model with the same name as the model name...
    //
    String bmID = Util.getLogicalModelIdPrefix() + "_" + modelName.replaceAll( " ", "_" ).toUpperCase(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    LogicalModel logicalModel = new LogicalModel();
    logicalModel.setId( bmID );
    domain.addLogicalModel( logicalModel );

    // Connect to the database...
    //
    database.connect();

    // clear the cache
    DBCache.getInstance().clear( databaseMeta.getName() );

    for ( int i = 0; i < tableNames.length; i++ ) {
      SchemaTable schemaTable = tableNames[i];

      // Import the specified tables and turn them into PhysicalTable
      // objects...
      //
      SqlPhysicalTable physicalTable =
          PhysicalTableImporter.importTableDefinition( database, schemaTable.getSchemaName(), schemaTable
          .getTableName(), locale, importStrategy );
      physicalModel.addPhysicalTable( physicalTable );

      // At the same time, we will create a business table and add that to the
      // business model...
      //
      LogicalTable businessTable = createBusinessTable( physicalTable, locale );
      logicalModel.addLogicalTable( businessTable );
    }
  } catch ( Exception e ) {
    // For the unexpected stuff, just throw the exception upstairs.
    //
    throw new PentahoMetadataException( e );
  } finally {
    // Make sure to close the connection
    //
    database.disconnect();
  }

  return domain;
}
 
Example 5
Source File: AdvancedQueryIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * this test generates an advanced mqlquery, generates xml, re-reads the xml and then compares the sql of both to
 * verify the serialization / deserialization code works.
 */
@Test
public void testXmlReadingWriting() throws Exception {
  LogicalModel model = getDefaultModel();
  Domain domain = new Domain();
  domain.setId( "test_domain" );
  domain.getLogicalModels().add( model );
  LogicalColumn bc1 = model.findLogicalColumn( "bc1" ); //$NON-NLS-1$
  LogicalColumn bce2 = model.findLogicalColumn( "bce2" ); //$NON-NLS-1$
  Category mainCat = model.findCategory( "cat_01" );
  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
  Query myTest = new Query( domain, model );

  myTest.getSelections().add( new AliasedSelection( mainCat, bce2, null, "alias1" ) );
  myTest.getSelections().add( new AliasedSelection( mainCat, bc1, null, null ) );
  myTest.getSelections().add( new AliasedSelection( mainCat, bce2, null, null ) );

  // myTest.getOrders().add(new Order((new AliasedSelection(null, bc1, null, null), true);
  // myTest.getOrders().add(new Order((new AliasedSelection(null, bce2, null, "alias1"), true);

  myTest.getConstraints().add( new Constraint( CombinationType.OR, "[alias1.bce2] > 10" ) );

  // System.out.println(myTest.getXML().replaceAll(">", ">\n"));
  AdvancedQueryXmlHelper xmlhelper = new AdvancedQueryXmlHelper();
  String xml = xmlhelper.toXML( myTest );
  InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  repo.storeDomain( domain, false );
  Query myReadTest = xmlhelper.fromXML( repo, xml );

  Assert.assertEquals( new AdvancedSqlGenerator().generateSql( myTest, "en_US", null, databaseMeta ).getQuery(),
      new AdvancedSqlGenerator().generateSql( myReadTest, "en_US", null, databaseMeta ).getQuery() );

  xml =
      "<mql><domain_type>relational</domain_type><domain_id>test_domain</domain_id>"
          + "<model_id>model_01</model_id><model_name>Model 1</model_name>"
          + "<options><disable_distinct>false</disable_distinct></options>"
          + "<selections><selection><view>cat_01</view><column>bc1</column></selection>"
          + "<selection><alias>Alias1</alias><view>cat_01</view><column>bc1</column></selection></selections>"
          + "<constraints>   <constraint><operator/> <condition>[cat_01.bc1] =\"1539006\"</condition> </constraint> </constraints></mql>";
  Query myReadTest2 = xmlhelper.fromXML( repo, xml );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT " + "   bt1.pc1 AS COL0," + "   bt1_Alias1.pc1 AS COL1 "
      + "FROM " + "   pt1 bt1," + "   pt1 bt1_Alias1 " + "WHERE" + "   ((bt1.pc1 = '1539006'))",
      new AdvancedSqlGenerator().generateSql( myReadTest2, "en_US", null, databaseMeta ).getQuery() );

  xml =
      "<mql>" + "  <domain_type>relational</domain_type>" + "  <domain_id>test_domain</domain_id>"
          + "  <model_id>model_01</model_id>" + "  <model_name>Model 1</model_name>" + "  <options>"
          + "    <disable_distinct>false</disable_distinct>" + "  </options>" + "  <selections>"
          + "    <selection><view>cat_01</view><column>bc1</column></selection>"
          + "    <selection><view>cat_01</view><column>bc2</column></selection>"
          + "    <selection><view>cat_01</view><column>bc3</column></selection>"
          + "    <selection><formula>[cat_01.bc1] * [cat_01.bc2]</formula></selection>"
          + "    <selection><formula>[cat_01.bc1] / [cat_01.bc2]</formula></selection>"
          + "    <selection><formula>[cat_01.bc1] + [cat_01.bc2]</formula></selection>"
          + "    <selection><formula>[cat_01.bc1] - [cat_01.bc2]</formula></selection>" + "  </selections>"
          + "  <constraints>"
          + "    <constraint><operator/> <condition>[cat_01.bc1] =\"1539006\"</condition> </constraint> "
          + "  </constraints>" + "</mql>";

  Query myReadTest3 = xmlhelper.fromXML( repo, xml );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT " + "  bt1.pc1 AS COL0," + "  bt2.pc2 AS COL1,"
      + "  bt3.pc3 AS COL2," + "  bt1.pc1*bt2.pc2 AS COL3," + "  bt1.pc1/bt2.pc2 AS COL4,"
      + "  bt1.pc1+bt2.pc2 AS COL5," + "  bt1.pc1-bt2.pc2 AS COL6 " + "FROM " + "  pt1 bt1," + "  pt2 bt2,"
      + "  pt3 bt3 " + "WHERE" + "  (bt1.pc1 = bt2.pc2)" + "  AND (bt3.pc3 = bt2.pc2)"
      + "  AND ((bt1.pc1 = '1539006'))", new AdvancedSqlGenerator().generateSql( myReadTest3, "en_US", null,
      databaseMeta ).getQuery() );

}
 
Example 6
Source File: SqlOpenFormulaIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testMqlDateParams_with_Date_object() throws Exception {
  Domain steelWheelsDomain = new XmiParser().parseXmi( getClass().getResourceAsStream( "/steel-wheels.xmi" ) );

  String mql =
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<mql>" + "<domain_id>Steel-Wheels</domain_id>"
          + "<model_id>BV_ORDERS</model_id>" + "<options>" + "<disable_distinct>false</disable_distinct>"
          + "</options>" + "<parameters>" + "<parameter defaultValue=\"2004-01-01\" name=\"date\" type=\"STRING\"/>"
          + "</parameters>" + "<selections>" + "<selection>" + "<view>BC_CUSTOMER_W_TER_</view>"
          + "<column>BC_CUSTOMER_W_TER_CUSTOMERNUMBER</column>" + "<aggregation>NONE</aggregation>" + "</selection>"
          + "<selection>" + "<view>CAT_ORDERS</view>" + "<column>BC_ORDERS_ORDERDATE</column>"
          + "<aggregation>NONE</aggregation>" + "</selection>" + "</selections>" + "<constraints>" + "<constraint>"
          + "<operator/>" + "<condition>[CAT_ORDERS.BC_ORDERS_ORDERDATE] "
          + "&gt;DATEVALUE([param:date])</condition>" + "</constraint>" + "</constraints>" + "<orders/>" + "</mql>";

  QueryXmlHelper helper = new QueryXmlHelper();
  InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  steelWheelsDomain.setId( "Steel-Wheels" );

  repo.storeDomain( steelWheelsDomain, false );
  Query query = helper.fromXML( repo, mql );

  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$

  SqlGenerator generator = new SqlGenerator();
  Map<String, Object> parameters = new HashMap<String, Object>();
  Date now = new Date();
  parameters.put( "date", now );
  MappedQuery mappedQuery = generator.generateSql( query, "en_US", repo, databaseMeta, parameters, false );

  SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
  String nowAsString = sdf.format( now );

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n"
      + "          BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER AS COL0\n"
      + "         ,BT_ORDERS_ORDERS.ORDERDATE AS COL1\n" + "FROM \n"
      + "          CUSTOMER_W_TER BT_CUSTOMER_W_TER_CUSTOMER_W01\n" + "         ,ORDERS BT_ORDERS_ORDERS\n"
      + "WHERE \n"
      + "          ( BT_ORDERS_ORDERS.CUSTOMERNUMBER = BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER )\n"
      + "      AND \n" + "        (\n" + "          (\n" + "              BT_ORDERS_ORDERS.ORDERDATE  > TO_DATE('"
      + nowAsString + "','YYYY-MM-DD')\n" + "          )\n" + "        )\n", mappedQuery.getQuery() );
}
 
Example 7
Source File: SqlOpenFormulaIT.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testMqlConstraints() throws Exception {
  Domain steelWheelsDomain = new XmiParser().parseXmi( getClass().getResourceAsStream( "/steel-wheels.xmi" ));

  String mql =
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<mql>" + "<domain_id>Steel-Wheels</domain_id>"
          + "<model_id>BV_ORDERS</model_id>" + "<options>" + "<disable_distinct>false</disable_distinct>"
          + "</options>" + "<selections>" + "<selection>" + "<view>BC_CUSTOMER_W_TER_</view>"
          + "<column>BC_CUSTOMER_W_TER_CUSTOMERNUMBER</column>" + "<aggregation>NONE</aggregation>" + "</selection>"
          + "<selection>" + "<view>CAT_ORDERS</view>" + "<column>BC_ORDERS_ORDERDATE</column>"
          + "<aggregation>NONE</aggregation>" + "</selection>" + "</selections>" + "<constraints>" + "<constraint>"
          + "<operator/>" + "<condition>[CAT_ORDERS.BC_ORDERS_ORDERDATE] "
          + "&gt;DATEVALUE(\"2009-12-12\")</condition>" + "</constraint>" + "<constraint>"
          + "<operator>AND NOT</operator>" + "<condition>[CAT_ORDERS.BC_ORDERS_ORDERDATE] "
          + "&lt;DATEVALUE(\"2009-12-13\")</condition>" + "</constraint>" + "</constraints>" + "<orders/>" + "</mql>";

  QueryXmlHelper helper = new QueryXmlHelper();
  InMemoryMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  steelWheelsDomain.setId( "Steel-Wheels" );

  repo.storeDomain( steelWheelsDomain, false );
  Query query = helper.fromXML( repo, mql );

  DatabaseMeta databaseMeta = new DatabaseMeta( "", "ORACLE", "Native", "", "", "", "", "" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$

  SqlGenerator generator = new SqlGenerator();
  MappedQuery mappedQuery = generator.generateSql( query, "en_US", repo, databaseMeta );

  // TestHelper.printOutJava(mappedQuery.getQuery());

  TestHelper.assertEqualsIgnoreWhitespaces( "SELECT DISTINCT \n"
      + "          BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER AS COL0\n"
      + "         ,BT_ORDERS_ORDERS.ORDERDATE AS COL1\n" + "FROM \n"
      + "          CUSTOMER_W_TER BT_CUSTOMER_W_TER_CUSTOMER_W01\n" + "         ,ORDERS BT_ORDERS_ORDERS\n"
      + "WHERE \n"
      + "          ( BT_ORDERS_ORDERS.CUSTOMERNUMBER = BT_CUSTOMER_W_TER_CUSTOMER_W01.CUSTOMERNUMBER )\n"
      + "      AND \n" + "        (\n" + "          (\n"
      + "              BT_ORDERS_ORDERS.ORDERDATE  > TO_DATE('2009-12-12','YYYY-MM-DD')\n" + "          )\n"
      + "      AND NOT (\n" + "              BT_ORDERS_ORDERS.ORDERDATE  < TO_DATE('2009-12-13','YYYY-MM-DD')\n"
      + "          )\n" + "        )\n", mappedQuery.getQuery() );
}
 
Example 8
Source File: TestHelper.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Domain getBasicDomain() {

    String locale = LocaleHelper.getLocale().toString();

    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName( "SampleData" );
    model.setDatasource( dataSource );
    SqlPhysicalTable table = new SqlPhysicalTable( model );
    table.setId( "PT1" );
    model.getPhysicalTables().add( table );
    table.setTargetTableType( TargetTableType.INLINE_SQL );
    table.setTargetTable( "select * from customers" );

    SqlPhysicalColumn column = new SqlPhysicalColumn( table );
    column.setId( "PC1" );
    column.setTargetColumn( "customername" );
    column.setName( new LocalizedString( locale, "Customer Name" ) );
    column.setDescription( new LocalizedString( locale, "Customer Name Desc" ) );
    column.setDataType( DataType.STRING );
    table.getPhysicalColumns().add( column );

    LogicalModel logicalModel = new LogicalModel();
    logicalModel.setId( "MODEL" );
    logicalModel.setName( new LocalizedString( locale, "My Model" ) );
    logicalModel.setDescription( new LocalizedString( locale, "A Description of the Model" ) );

    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setId( "LT" );
    logicalTable.setPhysicalTable( table );
    logicalTable.setLogicalModel( logicalModel );

    logicalModel.getLogicalTables().add( logicalTable );

    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId( "LC_CUSTOMERNAME" );
    logicalColumn.setPhysicalColumn( column );
    logicalColumn.setLogicalTable( logicalTable );
    logicalTable.addLogicalColumn( logicalColumn );

    Category mainCategory = new Category( logicalModel );
    mainCategory.setId( "CATEGORY" );
    mainCategory.setName( new LocalizedString( locale, "Category" ) );
    mainCategory.addLogicalColumn( logicalColumn );

    logicalModel.getCategories().add( mainCategory );

    Domain domain = new Domain();
    domain.setId( "DOMAIN" );
    domain.addPhysicalModel( model );
    domain.addLogicalModel( logicalModel );

    return domain;
  }
 
Example 9
Source File: MQLEditorServiceDelegateTest.java    From mql-editor with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test( timeout = 5000 )
public void testConcurrency() throws Exception {
  String domainIdPrefix = "id";
  int repoSize = 100;
  //init repo
  IMetadataDomainRepository repo = new InMemoryMetadataDomainRepository();
  for ( int i = 0; i < repoSize; i++ ) {
    Domain domain = new Domain();
    LocalizedString name = new LocalizedString();
    name.setString( "US", String.valueOf( i + 1 ) );
    domain.setId( domainIdPrefix + String.valueOf( i + 1 ) );
    domain.setName( name );
    repo.storeDomain( domain, false );
  }

  MQLEditorServiceDelegate service = new MQLEditorServiceDelegate( repo );

  int poolSize = repoSize / 2;
  ExecutorService executorService = Executors.newFixedThreadPool( poolSize );

  List<Future<Boolean>> results = new ArrayList<>();
  for ( int i = 0; i < poolSize; i++ ) {
    results.add( executorService.submit( new Callable<Boolean>() {
      public Boolean call() throws Exception {
        for ( int i = 0; i < repoSize; i++ ) {
          try {
            String id = domainIdPrefix + String.valueOf( i + 1 );
            service.getDomainByName( id );
            service.addThinDomain( id );
          } catch ( Exception e ) {
            return false;
          }
        }
        return true;
      }
    } ) );
  }
  for ( Future<Boolean> result : results ) {
    Assert.assertTrue( result.get() );
  }
  executorService.shutdown();
}
 
Example 10
Source File: MetadataGenerator.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Domain generatePhysicalMetadataModel() throws KettleException {

    // First do some checking and lookups...
    //
    String targetDatabaseName = ConceptUtil.getString(logicalDomain, DefaultIDs.DOMAIN_TARGET_DATABASE);
    if (Utils.isEmpty(targetDatabaseName)) {
      throw new KettleException("Please specify a target database!");
    }
    DatabaseMeta targetDatabaseMeta = DatabaseMeta.findDatabase(databases, targetDatabaseName);
    if (targetDatabaseMeta==null) {
      throw new KettleException("Target database with name '"+targetDatabaseName+"' can't be found!");
    }

    // Now start creation of a new domain with physical underpinning.
    //
    Domain domain = new Domain();

    // Copy the domain information...
    //
    domain.setId( createId("DOMAIN", null, domain) );
    domain.setName(logicalDomain.getName());
    domain.setDescription(logicalDomain.getDescription());

    // Now copy all the models...
    //
    for (LogicalModel logicalModel : logicalDomain.getLogicalModels()) {
      // Copy model information...
      //
      LogicalModel model = new LogicalModel();
      model.setId( createId("MODEL", domain, model));
      model.setName(logicalModel.getName());
      model.setDescription(logicalModel.getDescription());

      // Create a physical model...
      //
      SqlPhysicalModel sqlModel = new SqlPhysicalModel();
      sqlModel.setDatasource(createSqlDataSource(targetDatabaseMeta));
      model.setPhysicalModel(sqlModel);

      for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
        LogicalTable table = new LogicalTable();
        table.setId( createId("LOGICAL_TABLE", logicalModel, logicalTable) );
        table.setName(logicalTable.getName());
        table.setDescription(logicalTable.getDescription());

        String targetTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);

        SqlPhysicalTable sqlTable = new SqlPhysicalTable(sqlModel);
        table.setPhysicalTable(sqlTable);

        // Copy name & description from physical level...
        //
        sqlTable.setId( createId("PHYSICAL_TABLE", logicalModel, logicalTable));
        sqlTable.setName(logicalTable.getName());
        sqlTable.setDescription(logicalTable.getDescription());
        sqlTable.setTableType(ConceptUtil.getTableType(logicalTable));
        sqlTable.setTargetSchema(targetDatabaseMeta.getPreferredSchemaName());
        sqlTable.setTargetTable(targetTable);


      }
    }

    return domain;
  }