Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/robfrank/orientdb-jdbc
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 10, 2012
2 parents 08bdf20 + f526f0d commit 4cbc791
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 222 deletions.
9 changes: 7 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ Do a

<pre>mvn assembly:assembly</pre>

to obtain a jar with dependency included.
to obtain a jar with dependency included under target directory.

It is very usefull to include under applications such as DBvisualizer.
Just copy orientdb-jdbc-1.0-SNAPSHOT-all.jar to your classpath.

It is very usefull to include under applications such as DBVisualizer.

*How can be used in my code?*

The driver is registerd to the Java sql DriverManager and can be used to work with all the OrientDB database types: memory, local or remote.
The driver's class is com.orientechnologies.orient.jdbc.OrientJdbcDriver.

Use your knowledge of JDBC API to work against OrientDB.

First get a connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@
import java.util.Properties;
import java.util.concurrent.Executor;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.graph.OGraphDatabase;
import com.orientechnologies.orient.core.db.graph.OGraphDatabasePool;

/**
* TODO Add authors name
*
* @author Roberto Franchini()
* @author Roberto Franchini (CELI Srl - franchini@celi.it)
* @author Salvatore Piccione (TXT e-solutions SpA - salvo.picci@gmail.com)
*/
public class OrientJdbcConnection implements Connection {

private final String dbUrl;
private final Properties info;
private ODatabaseDocumentTx database;
private OGraphDatabase database;
private boolean readOnly = false;
private boolean autoCommit;

Expand All @@ -62,7 +61,7 @@ public OrientJdbcConnection(String iUrl, Properties iInfo) {
String username = iInfo.getProperty("user", "admin");
String password = iInfo.getProperty("password", "admin");

database = ODatabaseDocumentPool.global().acquire(dbUrl, username, password);
database = OGraphDatabasePool.global().acquire(dbUrl, username, password);

}

Expand Down Expand Up @@ -278,33 +277,27 @@ public String getUrl() {
return dbUrl;
}

public ODatabaseDocumentTx getDatabase() {

public OGraphDatabase getDatabase() {
return database;
}

public void abort(Executor arg0) throws SQLException {
// TODO Auto-generated method stub

}

public int getNetworkTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}

public String getSchema() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public void setNetworkTimeout(Executor arg0, int arg1) throws SQLException {
// TODO Auto-generated method stub

}

public void setSchema(String arg0) throws SQLException {
// TODO Auto-generated method stub

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ public boolean absolute(int iRowNumber) throws SQLException {
}

cursor = iRowNumber;
// ODatabaseRecordThreadLocal.INSTANCE.set(document.getDatabase());
document = records.get(cursor);

// fieldNames = document.fieldNames();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import com.orientechnologies.orient.core.command.OCommandRequest;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.graph.OGraphDatabase;
import com.orientechnologies.orient.core.exception.OQueryParsingException;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
Expand All @@ -42,7 +42,7 @@
public class OrientJdbcStatement implements Statement {

protected final OrientJdbcConnection connection;
protected final ODatabaseDocumentTx database;
protected final OGraphDatabase database;

// protected OCommandSQL query;
protected OCommandRequest query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,25 @@

import org.junit.Test;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class OrientDataSourceTest {

@Test
public void shouldConnect() throws SQLException {
String dbUrl = "memory:test";

String username = "admin";
String password = "admin";

ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
if (db.exists()) {
db.open(username, password);
db.drop();
db.close();
}
public class OrientDataSourceTest extends OrientJdbcBaseTest {

db.create();
@Test
public void shouldConnect() throws SQLException {

OrientDataSource ds = new OrientDataSource();
ds.setUrl("jdbc:orient:memory:test");
ds.setUsername(username);
ds.setPassword(password);
OrientDataSource ds = new OrientDataSource();
ds.setUrl("jdbc:orient:memory:test");
ds.setUsername("admin");
ds.setPassword("admin");

Connection conn = ds.getConnection();
Connection conn = ds.getConnection();

assertNotNull(conn);
conn.close();
assertTrue(conn.isClosed());
assertNotNull(conn);
conn.close();
assertTrue(conn.isClosed());

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,94 +14,95 @@

public class OrientDbCreationHelper {

public static void loadDB(ODatabaseDocumentTx db, int documents) {
public static void loadDB(ODatabaseDocumentTx db, int documents) {

db.declareIntent(new OIntentMassiveInsert());
db.declareIntent(new OIntentMassiveInsert());

for (int i = 1; i <= documents; i++) {
ODocument doc = new ODocument();
doc.setClassName("Item");
doc = createItem(i, doc);
db.save(doc, "Item");
for (int i = 1; i <= documents; i++) {
ODocument doc = new ODocument();
doc.setClassName("Item");
doc = createItem(i, doc);
db.save(doc, "Item");

}
}

db.declareIntent(null);
db.declareIntent(null);

}
}

public static void createSchemaDB(ODatabaseDocumentTx db) {
public static void createSchemaDB(ODatabaseDocumentTx db) {

OSchema schema = db.getMetadata().getSchema();
OSchema schema = db.getMetadata().getSchema();

// item
OClass item = schema.createClass("Item");
// item
OClass item = schema.createClass("Item");

item.createProperty("stringKey", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
item.createProperty("intKey", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
item.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("time", OType.DATETIME).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("text", OType.STRING);
item.createProperty("length", OType.LONG).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("published", OType.BOOLEAN).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("title", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("author", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("tags", OType.EMBEDDEDLIST);
item.createProperty("stringKey", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
item.createProperty("intKey", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
item.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("time", OType.DATETIME).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("text", OType.STRING);
item.createProperty("length", OType.LONG).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("published", OType.BOOLEAN).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("title", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("author", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
item.createProperty("tags", OType.EMBEDDEDLIST);

// class Article
OClass article = schema.createClass("Article");
// class Article
OClass article = schema.createClass("Article");

article.createProperty("uuid", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
article.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
article.createProperty("title", OType.STRING);
article.createProperty("content", OType.STRING);
article.createProperty("uuid", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
article.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
article.createProperty("title", OType.STRING);
article.createProperty("content", OType.STRING);
article.createProperty("attachment", OType.BINARY);

// author
OClass author = schema.createClass("Author");
// author
OClass author = schema.createClass("Author");

author.createProperty("uuid", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
author.createProperty("name", OType.STRING).setMin("3");
author.createProperty("articles", OType.LINKLIST, article);
author.createProperty("uuid", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
author.createProperty("name", OType.STRING).setMin("3");
author.createProperty("articles", OType.LINKLIST, article);

// link article-->author
article.createProperty("author", OType.LINK, author);
// link article-->author
article.createProperty("author", OType.LINK, author);

schema.save();
schema.save();

schema.reload();
schema.reload();

}
}

public static ODocument createItem(int id, ODocument doc) {
String itemKey = Integer.valueOf(id).toString();
public static ODocument createItem(int id, ODocument doc) {
String itemKey = Integer.valueOf(id).toString();

doc.setClassName("Item");
doc.field("stringKey", itemKey);
doc.field("intKey", id);
String contents =
"OrientDB is a deeply scalable Document-Graph DBMS with the flexibility of the Document databases and the power to manage links of the Graph databases. "
+ "It can work in schema-less mode, schema-full or a mix of both. Supports advanced features such as ACID Transactions, Fast Indexes, Native and SQL queries."
+ " It imports and exports documents in JSON."
+ " Graphs of hundreads of linked documents can be retrieved all in memory in few milliseconds without executing costly JOIN such as the Relational DBMSs do. "
+ "OrientDB uses a new indexing algorithm called MVRB-Tree, derived from the Red-Black Tree and from the B+Tree with benefits of both: fast insertion and ultra fast lookup. "
+ "The transactional engine can run in distributed systems supporting up to 9.223.372.036 Billions of records for the maximum capacity of 19.807.040.628.566.084 Terabytes of data distributed on multiple disks in multiple nodes. "
+ "OrientDB is FREE for any use. Open Source License Apache 2.0. ";
doc.field("text", contents);
doc.field("title", "orientDB");
doc.field("length", contents.length());
doc.field("published", (id % 2 > 0));
doc.field("author", "anAuthor" + id);
// doc.field("tags", asList("java", "orient", "nosql"),
// OType.EMBEDDEDLIST);
Calendar instance = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
doc.setClassName("Item");
doc.field("stringKey", itemKey);
doc.field("intKey", id);
String contents =
"OrientDB is a deeply scalable Document-Graph DBMS with the flexibility of the Document databases and the power to manage links of the Graph databases. "
+ "It can work in schema-less mode, schema-full or a mix of both. Supports advanced features such as ACID Transactions, Fast Indexes, Native and SQL queries."
+ " It imports and exports documents in JSON."
+ " Graphs of hundreads of linked documents can be retrieved all in memory in few milliseconds without executing costly JOIN such as the Relational DBMSs do. "
+ "OrientDB uses a new indexing algorithm called MVRB-Tree, derived from the Red-Black Tree and from the B+Tree with benefits of both: fast insertion and ultra fast lookup. "
+ "The transactional engine can run in distributed systems supporting up to 9.223.372.036 Billions of records for the maximum capacity of 19.807.040.628.566.084 Terabytes of data distributed on multiple disks in multiple nodes. "
+ "OrientDB is FREE for any use. Open Source License Apache 2.0. ";
doc.field("text", contents);
doc.field("title", "orientDB");
doc.field("length", contents.length());
doc.field("published", (id % 2 > 0));
doc.field("author", "anAuthor" + id);
// doc.field("tags", asList("java", "orient", "nosql"),
// OType.EMBEDDEDLIST);
Calendar instance = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

instance.add(Calendar.HOUR_OF_DAY, -id);
Date time = instance.getTime();
doc.field("date", time, OType.DATE);
doc.field("time", time, OType.DATETIME);
instance.add(Calendar.HOUR_OF_DAY, -id);
Date time = instance.getTime();
doc.field("date", time, OType.DATE);
doc.field("time", time, OType.DATETIME);

return doc;
return doc;

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public static void loadDriver() throws ClassNotFoundException {

@Before
public void prepareDatabase() throws Exception {
String dbUrl = "local:./working/db/test";
dbUrl = "memory:test";

String dbUrl = "memory:test";
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);

String username = "admin";
Expand Down
Loading

0 comments on commit 4cbc791

Please sign in to comment.