Hi Nicolas, I think that is not possible with ETL. Attached You can find the java code for what you need.
Regards, Alessandro -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
package Graph;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.naming.spi.DirStateFactory.Result;
import org.apache.commons.collections.CollectionUtils;
import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Banca {
private static String remote="remote:localhost/";
private static String nomeDb="Banca";
private static String currentPath=remote+nomeDb;
@SuppressWarnings("null")
public static void main(String[] args) throws BiffException, IOException {
String [][] array = null;
int colonne=0;
int righe=0;
try{
Workbook wrk1 = Workbook.getWorkbook(new File("C:/Users/Sorint.Lab/Desktop/Banca.xls"));
Sheet sheet1 = wrk1.getSheet(0); // foglio 1
colonne=sheet1.getColumns(); // colonne del foglio
System.out.println("Colonne " + colonne);
righe=sheet1.getRows() - 1; //numero di righe
System.out.println("Righe " + righe);
array=new String[colonne][righe];
for(int i=0;i<colonne;i++){ // leggo 2 colonne
Cell[] celle=sheet1.getColumn(i); // mi da le celle della colonna i
for(int j=1;j<celle.length;j++){
array[i][j-1]=celle[j].getContents();
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException a) {
a.printStackTrace();
}
OServerAdmin serverAdmin;
try {
serverAdmin = new OServerAdmin(currentPath).connect("root", "root");
if(serverAdmin.existsDatabase()){ // se il db già esiste
System.out.println("iL DB ESISTE");
OrientGraph g=new OrientGraph(currentPath);
g.shutdown();
}
else{
serverAdmin.createDatabase(nomeDb, "graph", "plocal");
System.out.println("dB IN CREAZIONE");
OrientGraph g=new OrientGraph(currentPath);
OClass cl=g.createVertexType("Person","V");
cl.createProperty("PersonId", OType.LONG);
cl.createProperty("idType", OType.INTEGER);
cl.createProperty("name", OType.STRING);
cl=g.createVertexType("Transaction","V");
cl.createProperty("TransactionId", OType.INTEGER);
cl.createProperty("date", OType.DATE);
cl.createProperty("value", OType.INTEGER);
cl.createProperty("currency", OType.INTEGER);
cl.createProperty("office", OType.INTEGER);
cl.createProperty("placeCode", OType.LONG);
cl=g.createVertexType("Account","V");
cl.createProperty("AccountId", OType.LONG);
cl.createProperty("idType", OType.INTEGER);
g.createEdgeType("makes");
g.createEdgeType("affects");
g.createEdgeType("ownes");
g.commit();
for(int i=0;i<righe;i++){
String query="select from Person WHERE PersonId = "+Long.parseLong(array[9][i]);
Iterable<Vertex> result=g.command(new OSQLSynchQuery<Vertex>(query)).execute();
List<OrientVertex> listaVertex = new ArrayList<OrientVertex>();
CollectionUtils.addAll(listaVertex, result.iterator());
OrientVertex v1=null;
if(listaVertex.size()==0){
v1=g.addVertex("class:Person");
int idType=Integer.parseInt(array[8][i]);
v1.setProperties("PersonId",Long.parseLong(array[9][i]));
v1.setProperties("idType",idType);
v1.setProperties("name",array[11][i]);
g.commit();
}
else{
v1=listaVertex.get(0);
}
query="select from Person WHERE PersonId = "+Long.parseLong(array[13][i]);
result=g.command(new OSQLSynchQuery<Vertex>(query)).execute();
listaVertex =new ArrayList<OrientVertex>();
CollectionUtils.addAll(listaVertex, result.iterator());
OrientVertex v2=null;
if(listaVertex.size()==0){
v2=g.addVertex("class:Person");
v2.setProperties("PersonId",Long.parseLong(array[13][i]));
v2.setProperties("idType",Integer.parseInt(array[12][i]));
v2.setProperties("name",array[14][i]);
g.commit();
}
else{
v2=listaVertex.get(0);
}
OrientVertex v3=g.addVertex("class:Account");
v3.setProperties("AccountId",Long.parseLong(array[7][i]));
g.commit();
OrientVertex v4=g.addVertex("class:Transaction");
v4.setProperties("TransactionId",Integer.parseInt(array[0][i]));
//v4.setProperties("date",array[1][i]);
v4.setProperties("value",Integer.parseInt(array[2][i]));
v4.setProperties("currency",Integer.parseInt(array[3][i]));
v4.setProperties("office",Integer.parseInt(array[4][i]));
v4.setProperties("placeCode",Long.parseLong(array[10][i]));
g.commit();
v2.addEdge("makes", v4);
v4.addEdge("affects",v3);
v1.addEdge("ownes", v3);
g.commit();
}
g.shutdown();
}
serverAdmin.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Banca.xls
Description: MS-Excel spreadsheet
