1   package eu.fbk.knowledgestore.datastore;
2   
3   import eu.fbk.knowledgestore.data.Record;
4   import eu.fbk.knowledgestore.data.Stream;
5   import eu.fbk.knowledgestore.data.XPath;
6   import eu.fbk.knowledgestore.datastore.AbstractDataStoreTest;
7   import eu.fbk.knowledgestore.datastore.DataStore;
8   import eu.fbk.knowledgestore.datastore.MySQLDataStore;
9   import eu.fbk.knowledgestore.vocabulary.KS;
10  import org.junit.Ignore;
11  import org.junit.Test;
12  
13  import java.io.IOException;
14  import java.sql.Connection;
15  import java.sql.PreparedStatement;
16  import java.util.List;
17  import java.util.concurrent.CancellationException;
18  
19  /**
20   * Created with IntelliJ IDEA.
21   * User: alessio
22   * Date: 09/09/14
23   * Time: 11:24
24   * To change this template use File | Settings | File Templates.
25   */
26  
27  public class MySQLDataStoreTest extends AbstractDataStoreTest {
28  	@Override
29  	protected DataStore createDataStore() {
30  		MySQLDataStore s = new MySQLDataStore("localhost", "root", "pippo", "test");
31  		return s;
32  	}
33  
34  	@Test
35  	public void testParseQuery() throws Throwable {
36  		MySQLDataStore ds = (MySQLDataStore) this.createDataStore();
37  		ds.init();
38  
39  		String partialInsertQuery = "(MD5(?), ?)";
40  
41  		Connection con = ds.dataSource.getConnection();
42  		PreparedStatement stmt = con.prepareStatement(partialInsertQuery);
43  		stmt.setString(1, "Pippo");
44  //		stmt.setBytes(2, new String("Pippi Calzelunghe").getBytes());
45  		stmt.setInt(2, 182376);
46  		System.out.println(stmt.toString());
47  	}
48  
49  	@Test
50  	@Ignore
51  	public void testRetrieve() {
52  		DataStore ds = this.createDataStore();
53  		try {
54  			ds.init();
55  			List<Record> records = createRecords(3, KS.RESOURCE);
56  			DataTransaction dataTran = ds.begin(false);
57  			dataTran.store(KS.RESOURCE, records.get(0));
58  			dataTran.store(KS.RESOURCE, records.get(1));
59  			dataTran.delete(KS.RESOURCE, records.get(2).getID());
60  			XPath condition = XPath.parse("'example.org'"); // TODO: I don't thing this will work
61  			//condition.decompose(propertyRanges);
62  			Stream<Record> cur = dataTran.retrieve(KS.RESOURCE, condition, null);
63  			try {
64  				for (Record r : cur) {
65  					System.out.println(r);
66  				}
67  			} finally {
68  				cur.close();
69  			}
70  		} catch (IOException e) {
71  			// TODO Auto-generated catch block
72  			e.printStackTrace();
73  		} catch (CancellationException ex) {
74  			// not our case: ignore
75  		}
76  	}
77  
78  }