use of fr.lirmm.graphik.graal.store.rdbms.util.DBColumn in project graal by graphik-team.
the class AbstractRdbmsDriver method getColumns.
@Override
public List<DBColumn> getColumns(String tableName) throws SQLException {
tableName = this.formatIdentifier(tableName);
ArrayList<DBColumn> list = new ArrayList<DBColumn>();
DatabaseMetaData metaData = this.getConnection().getMetaData();
ResultSet res = metaData.getColumns(null, null, tableName, null);
while (res.next()) {
String name = res.getString("COLUMN_NAME");
int type = res.getInt("DATA_TYPE");
list.add(new DBColumn(name, type));
}
return list;
}
use of fr.lirmm.graphik.graal.store.rdbms.util.DBColumn in project graal by graphik-team.
the class AdHocRdbmsStore method add.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private void add(Statement statement, Term term) throws AtomSetException {
try {
List<DBColumn> cols = TERMS_TABLE.getColumns();
Map<String, String> data = new TreeMap<String, String>();
data.put(cols.get(0).getName(), '\'' + StringUtils.addSlashes(term.getIdentifier().toString()) + '\'');
data.put(cols.get(1).getName(), '\'' + getType(term) + '\'');
String query = this.getDriver().getInsertOrIgnoreQuery(TERMS_TABLE, data);
statement.executeUpdate(query);
} catch (SQLException e) {
throw new AtomSetException("Error during insertion of a term: " + term, e);
}
}
use of fr.lirmm.graphik.graal.store.rdbms.util.DBColumn in project graal by graphik-team.
the class AbstractRdbmsConjunctiveQueryTranslator method translateRemove.
// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
public SQLQuery translateRemove(Atom atom) throws AtomSetException {
DBTable table = this.store.getPredicateTableIfExist(atom.getPredicate());
if (table == null)
return SQLQuery.hasSchemaErrorInstance();
StringBuilder query = new StringBuilder("DELETE FROM ");
query.append(table);
query.append(" WHERE ");
List<DBColumn> columns = table.getColumns();
int termIndex = 0;
for (Term t : atom.getTerms()) {
if (termIndex != 0) {
query.append(" and ");
}
query.append(columns.get(termIndex).getName()).append(" = '").append(t.getLabel()).append("'");
++termIndex;
}
return new SQLQuery(query.toString());
}
use of fr.lirmm.graphik.graal.store.rdbms.util.DBColumn in project graal by graphik-team.
the class AbstractRdbmsConjunctiveQueryTranslator method translateCreateTable.
@Override
public String translateCreateTable(DBTable table) {
StringBuilder primaryKey = new StringBuilder("PRIMARY KEY (");
StringBuilder query = new StringBuilder("CREATE TABLE ");
query.append(table.getName());
query.append(" (");
boolean first = true;
for (DBColumn col : table.getColumns()) {
if (!first) {
query.append(", ");
primaryKey.append(", ");
}
query.append(col.getName()).append(" varchar(" + AbstractRdbmsStore.VARCHAR_SIZE + ")");
primaryKey.append(col.getName());
first = false;
}
primaryKey.append(")");
query.append(',');
query.append(primaryKey);
query.append(");");
return query.toString();
}
use of fr.lirmm.graphik.graal.store.rdbms.util.DBColumn in project graal by graphik-team.
the class NaturalRDBMSStore method add.
// /////////////////////////////////////////////////////////////////////////
// PROTECTED AND PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
@Override
protected Statement add(Statement statement, Atom atom) throws AtomSetException {
if (!this.check(atom)) {
// FIXME say why
throw new UnsupportedAtomTypeException("");
}
try {
DBTable table = this.createPredicateTableIfNotExist(atom.getPredicate());
Iterator<DBColumn> cols = table.getColumns().iterator();
Map<String, String> data = new TreeMap<String, String>();
for (Term t : atom.getTerms()) {
DBColumn col = cols.next();
data.put(col.getName(), this.getConjunctiveQueryTranslator().formatFromColumnType(col, t));
}
String query = this.getDriver().getInsertOrIgnoreQuery(table, data);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(atom.toString() + " : " + query);
}
statement.addBatch(query);
} catch (SQLException e) {
throw new AtomSetException(e);
}
return statement;
}
Aggregations