Skip to content

Commit

Permalink
new version 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
prrvchr committed Jun 26, 2024
1 parent 16e734a commit bdf05d4
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 76 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ Clients using the jdbcDriverOOo driver can access features of the underlying JDB
- New implementation, which I hope is definitive, of bookmarks. It is based on three files and is taken from Sun's implementation of `javax.sql.rowset.CachedRowSet`:
- [ScollableResultSet.class][113]
- [SensitiveResultSet.class][114]
- [CachedResultSet.class][122]
These ResultSets are capable of editing almost all queries created in LibreOffice Base, even views...
- [CachedResultSet.class][122]
- **These ResultSets are capable of editing almost all queries created in LibreOffice Base, even views...** But in order to guarantee good functionality, certain rules must be respected in order to make a result set editable. If the query concerns several tables then it is imperative to include the primary keys of each table in the list of columns of the result set. If the query only concerns a single table then the result set will be modifiable if there is a column that does not contain a duplicate (ie: a natural key). This makes it possible to make the result sets coming from the Trino driver editable.
- Removed the use of generic classes where they were not needed. This made the driver faster...
- Added special parameters in: **Edit -> Database -> Advanced parameters... -> Special parameters** in order to respond to the request for integration of the Trino driver (see [improvement request #8 ][123]). It is necessary to recreate the odb files in order to have access to these new parameters.

Expand Down
6 changes: 3 additions & 3 deletions README_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ Les clients utilisant le pilote jdbcDriverOOo peuvent accéder aux fonctionnalit
- Nouvelle implémentation, que j'espère définitive, des signets (bookmarks). Il est basé sur trois fichiers et est tiré de l'implémentation par Sun de `javax.sql.rowset.CachedRowSet` :
- [ScollableResultSet.class][113]
- [SensitiveResultSet.class][114]
- [CachedResultSet.class][122]
Ces ResultSets sont capables d'éditer presque toutes les requêtes créées dans LibreOffice Base, même les vues...
- [CachedResultSet.class][122]
- **Ces ResultSets sont capables d'éditer presque toutes les requêtes créées dans LibreOffice Base, même les vues...** Mais afin de garantir une bonne fonctionnalité, certaines règles doivent être respectées afin de rendre un jeu de résultats éditable. Si la requête concerne plusieurs tables alors il est impératif d'inclure les clés primaires de chaque table dans la liste des colonnes du jeu de résultats. Si la requête ne concerne qu'une seule table alors le jeu de résultats sera modifiable s'il existe une colonne qui ne contient pas de doublon (ie: une clé naturelle). Cela permet de rendre modifiables les jeux de résultats provenant du pilote Trino.
- Suppression de l'utilisation de classes génériques là où elles n'étaient pas nécessaires. Cela a rendu le pilote plus rapide...
- Ajout de paramètres spéciaux dans : **Edition -> Base de données -> Paramètres avancés... -> Paramètres spéciaux** afin de répondre à la demande d'intégration du pilote Trino (voir [demande d'amélioration n°8][123]). Il est nécessaire de recréer les fichiers odb afin d'avoir accès à ces nouveaux paramètres.
- Ajout de paramètres spéciaux dans: **Edition -> Base de données -> Paramètres avancés... -> Paramètres spéciaux** afin de répondre à la demande d'intégration du pilote Trino (voir [demande d'amélioration n°8][123]). Il est nécessaire de recréer les fichiers odb afin d'avoir accès à ces nouveaux paramètres.

### Que reste-t-il à faire pour la version 1.4.1:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public abstract class CachedResultSet
// XXX: If ResultSet is not updatable then we need to emulate the insert row.
protected InsertRow m_InsertRow = null;

protected boolean m_Insertable = false;
protected boolean m_Updatable = false;
// XXX: We need to know when we are on the insert row
protected boolean m_OnInsert = false;
// XXX: We need to keep the index references of the columns already assigned for insertion
Expand All @@ -108,9 +108,9 @@ public CachedResultSet(DriverProvider provider,
m_IsUpdateVisible = updatable && provider.isUpdateVisible(rstype);
m_FetchSize = result.getFetchSize();
m_ColumnCount = result.getMetaData().getColumnCount();
m_Insertable = updatable;
m_InsertedColumns = new BitSet(m_ColumnCount);
System.out.println("CachedResultSet() Insertable: " + m_Insertable);
m_Updatable = updatable;
System.out.println("CachedResultSet() Updatable: " + m_Updatable);
}


Expand All @@ -130,7 +130,7 @@ public void insertRow()
public void cancelRowUpdates()
throws SQLException
{
if (m_Insertable) {
if (m_Updatable) {
if (isOnInsertRow()) {
moveToCurrentRow();
}
Expand All @@ -147,7 +147,7 @@ public void cancelRowUpdates()
public void moveToInsertRow()
throws SQLException
{
if (m_Insertable) {
if (m_Updatable) {
m_Result.moveToInsertRow();
m_InsertedColumns.clear();
}
Expand All @@ -158,7 +158,7 @@ public void moveToInsertRow()
public void moveToCurrentRow()
throws SQLException
{
if (m_Insertable) {
if (m_Updatable) {
m_Result.moveToCurrentRow();
}
setInsertMode(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class ScrollableResultSet
private boolean m_RowCountFinal = false;
private int m_InsertedRow = 0;
private boolean m_WasNull = false;
private boolean m_Updatable;

// The constructor method:
public ScrollableResultSet(DriverProvider provider,
Expand All @@ -72,19 +71,9 @@ public ScrollableResultSet(DriverProvider provider,
throws SQLException
{
super(provider, result, catalog, query);
try {
m_Insertable = false;
boolean updatable = provider.isResultSetUpdatable(result);
if (!updatable) {
m_Catalog = new RowCatalog(provider, result, query);
updatable = m_Catalog.hasRowIdentifier();
}
m_Updatable = updatable;
loadNextRow();
}
catch (Exception e) {
e.printStackTrace();
}
m_Updatable = false;
System.out.println("ScrollableResultSet() 1");
loadNextRow();
}


Expand All @@ -93,7 +82,7 @@ public ScrollableResultSet(DriverProvider provider,
public int getConcurrency()
throws SQLException
{
return m_Updatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
return ResultSet.CONCUR_UPDATABLE;
}

// XXX: We want to emulate an scollable ResultSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public class SensitiveResultSet
private List<Integer> m_InsertedRows = new ArrayList<>();
private Vector<Row> m_InsertedData = null;
private int m_RowCount = 0;
private boolean m_Updatable = false;
private int m_Inserted = -1;
private boolean m_WasNull = false;
private boolean m_SQLDelete = false;
Expand All @@ -92,14 +91,7 @@ public SensitiveResultSet(DriverProvider provider,
m_SQLInsert = provider.useSQLInsert();
m_SQLUpdate = provider.useSQLUpdate();
m_SQLMode = provider.isSQLMode();
boolean updatable = provider.isResultSetUpdatable(result);
if (!updatable) {
m_Catalog = new RowCatalog(provider, result, query);
updatable = m_Catalog.hasRowIdentifier();
System.out.println("SensitiveResultSet()1 TableCount: " + m_Catalog.getTableCount());
}
System.out.println("SensitiveResultSet() 2 Updatable: " + updatable);
m_Updatable = updatable;
System.out.println("SensitiveResultSet() 1");
loadLastRow();
}

Expand All @@ -109,7 +101,7 @@ public SensitiveResultSet(DriverProvider provider,
public int getConcurrency()
throws SQLException
{
return m_Updatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
return ResultSet.CONCUR_UPDATABLE;
}

// XXX: We want to emulate an scollable ResultSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public RowCatalog(DriverProvider provider,
throws SQLException
{
RowTable table = null;
boolean retrieved = true;
NamedComponents component = null;
m_Statement = provider.getStatement();
Connection connection = provider.getConnection();
Expand All @@ -93,39 +92,23 @@ public RowCatalog(DriverProvider provider,
table = getTable(connection, metadata, index);
}
if (table.isValid()) {
retrieved |= table.setIndexColumn(metadata.getColumnName(index), index);
table.setIndexColumn(metadata.getColumnName(index), index);
}
}
if (table == null) {
throw new SQLException();
}
if (table.isValid() && retrieved) {
setRowIdentifier(table);
}
}

private void setRowIdentifier(RowTable table)
throws SQLException
{
try (ResultSet result = m_Statement.getConnection().getMetaData().getPrimaryKeys(table.getCatalogName(), table.getSchemaName(), table.getName())) {
while (result.next()) {
String key = result.getString(4);
if (!result.wasNull() && table.hasColumn(key)) {
short index = result.getShort(5);
table.addRowIdentifier(key, index - 1);
}
}
}
if (!table.hasRowIdentifier()) {
table.setDefaultRowIdentifier();
}
setTableIdentifier();
}

public boolean hasRowIdentifier()
{
boolean has = true;
boolean multiple = getTableCount() > 1;
for (RowTable table : m_Tables) {
has |= table.hasRowIdentifier();
if (multiple) {
has &= table.hasRowIdentifier() && table.isIdentifierPrimaryKey();
}
else {
has = table.hasRowIdentifier();
}
}
return !m_Tables.isEmpty() && has;
}
Expand Down Expand Up @@ -212,6 +195,35 @@ public List<RowTable> getTables() {
return m_Tables;
}


private void setTableIdentifier()
throws SQLException
{
for (RowTable table : getTables()) {
if (table.isValid()) {
setRowIdentifier(table);
}
}
}

private void setRowIdentifier(RowTable table)
throws SQLException
{
try (ResultSet result = m_Statement.getConnection().getMetaData().getPrimaryKeys(table.getCatalogName(), table.getSchemaName(), table.getName())) {
while (result.next()) {
String key = result.getString(4);
if (!result.wasNull() && table.hasColumn(key)) {
short index = result.getShort(5);
table.addRowIdentifier(key, index - 1);
table.setIdentifierAsPrimaryKey();
}
}
}
if (!table.hasRowIdentifier()) {
table.setDefaultRowIdentifier();
}
}

private RowTable getTable(Connection connection,
ResultSetMetaData metadata,
int index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public static void setWhereParameter(PreparedStatement statement,
for (String key : table.getRowIdentifier()) {
RowColumn column = table.getColumn(key);
Object value = row.getOldColumnObject(column.getIndex());
System.out.println("RowSetWriter.getModifiedColumns() Column: " + column.getName() + " - Value: " + value);
RowHelper.setStatementValue(statement, column.getType(), index, value);
index ++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class RowTable
private RowCatalog m_Catalog;
private Map<String, RowColumn> m_Columns = new LinkedHashMap<>();
private List<String> m_Keys = new ArrayList<>();
private boolean m_IsPrimary = false;
private NamedComponents m_Component;
private String m_Where;

Expand Down Expand Up @@ -96,26 +97,34 @@ public void addColumn(RowColumn column)
m_Columns.put(column.getName(), column);
}

public boolean setIndexColumn(String name, int index)
public void setIndexColumn(String name, int index)
{
if (m_Columns.containsKey(name)) {
RowColumn column = m_Columns.get(name);
column.setIndex(index);
return true;
}
return false;
}

public boolean hasRowIdentifier()
{
return !m_Keys.isEmpty();
}

public boolean isIdentifierPrimaryKey()
{
return m_IsPrimary;
}

public void addRowIdentifier(String column, int index)
{
m_Keys.add(index, column);
}

public void setIdentifierAsPrimaryKey()
{
m_IsPrimary = true;
}

public void setDefaultRowIdentifier()
throws SQLException
{
Expand Down Expand Up @@ -263,17 +272,6 @@ public String getMark()
return m_Catalog.getMark();
}

public boolean equals(Object object)
{
if (!(object instanceof RowTable)) {
return false;
}
RowTable table = (RowTable) object;
return getCatalogName().equals(table.getCatalogName()) &&
getSchemaName().equals(table.getSchemaName()) &&
getName().equals(table.getName());
}

public Collection<RowColumn> getColumns()
{
return m_Columns.values();
Expand Down

0 comments on commit bdf05d4

Please sign in to comment.