Project

General

Profile

Download (2.23 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.test.example;
10

    
11
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
12
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
13
import eu.etaxonomy.cdm.common.AccountStore;
14
import eu.etaxonomy.cdm.database.CdmDataSource;
15
import eu.etaxonomy.cdm.database.DbSchemaValidation;
16
import eu.etaxonomy.cdm.database.ICdmDataSource;
17
import eu.etaxonomy.cdm.model.taxon.Taxon;
18

    
19
/**
20
 * This is an example class to show how to connect to a CDM Database via a
21
 * {@link CdmApplicationController}. Please don't change this file. Rather
22
 * copy&paste it to use it for your own purposes.
23
 *
24
 * @author a.mueller
25
 *
26
 */
27
public class ApplicationExample {
28
	//change to VALIDATE to connect to an existing CDM database
29
	static DbSchemaValidation schemaValidation = DbSchemaValidation.CREATE;
30

    
31

    
32
	private void testH2(){
33

    
34
		//H2
35
		String database = "test";
36
		String username = "sa";
37
		ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa");
38

    
39
		ICdmApplicationConfiguration app = CdmApplicationController.NewInstance(dataSource, schemaValidation);
40
		Taxon taxon = Taxon.NewInstance(null, null);
41
		app.getTaxonService().save(taxon);
42
	}
43

    
44
	private void testMySql(){
45

    
46
		//please adapt the following parameters to your local conditions
47
		String server = "localhost";
48
		String database = "test";
49
		String username = "edit";
50
		//password will be asked for in console and stored in your home directory
51
		ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
52

    
53
		ICdmApplicationConfiguration app = CdmApplicationController.NewInstance(dataSource, schemaValidation);
54
		Taxon taxon = Taxon.NewInstance(null, null);
55
		app.getTaxonService().save(taxon);
56
	}
57

    
58
	/**
59
	 * @param args
60
	 */
61
	public static void main(String[] args) {
62
		new ApplicationExample().testH2();
63
//		new ApplicationExample().testMySql();
64
	}
65

    
66
}
    (1-1/1)