Search in sources :

Example 41 with Table

use of com.servoy.j2db.persistence.Table in project servoy-client by Servoy.

the class EditRecordList method getRecordUpdateInfo.

/*
	 * _____________________________________________________________ Methods for data manipulation
	 */
private RowUpdateInfo getRecordUpdateInfo(IRecordInternal state) throws ServoyException {
    Table table = state.getParentFoundSet().getSQLSheet().getTable();
    RowManager rowManager = fsm.getRowManager(fsm.getDataSource(table));
    Row rowData = state.getRawData();
    boolean doesExistInDB = rowData.existInDB();
    if (doesExistInDB && !hasAccess(table, IRepository.UPDATE)) {
        throw new ApplicationException(ServoyException.NO_MODIFY_ACCESS, new Object[] { table.getName() });
    }
    GlobalTransaction gt = fsm.getGlobalTransaction();
    if (gt != null) {
        gt.addRecord(table.getServerName(), state);
    }
    RowUpdateInfo rowUpdateInfo = rowManager.getRowUpdateInfo(rowData, hasAccess(table, IRepository.TRACKING));
    return rowUpdateInfo;
}
Also used : ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) ApplicationException(com.servoy.j2db.ApplicationException)

Example 42 with Table

use of com.servoy.j2db.persistence.Table in project servoy-client by Servoy.

the class DBValueList method getShowDataproviders.

public static List<String> getShowDataproviders(ValueList valueList, Table callingTable, String dataProviderID, IFoundSetManagerInternal foundSetManager) throws RepositoryException {
    if (valueList == null) {
        return null;
    }
    FlattenedSolution flattenedSolution = foundSetManager.getApplication().getFlattenedSolution();
    // Find destination table in case dataProviderID is related
    String[] split = dataProviderID.split("\\.");
    String dataSource = callingTable.getDataSource();
    for (// first parts are relation names, last part is column name
    int i = 0; // first parts are relation names, last part is column name
    i < split.length - 1; // first parts are relation names, last part is column name
    i++) {
        Relation relation = flattenedSolution.getRelation(split[i]);
        if (relation == null || !relation.getPrimaryDataSource().equals(dataSource)) {
            return null;
        }
        dataSource = relation.getForeignDataSource();
    }
    Table table = (Table) foundSetManager.getTable(dataSource);
    String columnName = split[split.length - 1];
    String prefix = dataProviderID.substring(0, dataProviderID.length() - columnName.length());
    // first try fallback value list,
    ValueList usedValueList = flattenedSolution.getValueList(valueList.getFallbackValueListID());
    Relation valuelistSortRelation = flattenedSolution.getValuelistSortRelation(usedValueList, table, columnName, foundSetManager);
    if (valuelistSortRelation == null) {
        // then try regular value list
        usedValueList = valueList;
        valuelistSortRelation = flattenedSolution.getValuelistSortRelation(usedValueList, table, columnName, foundSetManager);
    }
    if (valuelistSortRelation == null) {
        return null;
    }
    List<String> showDataproviders = new ArrayList<String>(3);
    int showValues = usedValueList.getShowDataProviders();
    if ((showValues & 1) != 0) {
        showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID1());
    }
    if ((showValues & 2) != 0) {
        showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID2());
    }
    if ((showValues & 4) != 0) {
        showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID3());
    }
    return showDataproviders;
}
Also used : Relation(com.servoy.j2db.persistence.Relation) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) ValueList(com.servoy.j2db.persistence.ValueList) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Example 43 with Table

use of com.servoy.j2db.persistence.Table in project servoy-client by Servoy.

the class FoundSetManager method getFoundSetCount.

public int getFoundSetCount(IFoundSetInternal fs) {
    if (fs instanceof FoundSet && fs.getTable() != null) {
        FoundSet foundset = (FoundSet) fs;
        try {
            // optimize
            if (foundset.isInitialized() && !foundset.hadMoreRows()) {
                return foundset.getSize();
            }
            long time = System.currentTimeMillis();
            IDataServer ds = application.getDataServer();
            Table t = (Table) foundset.getTable();
            String transaction_id = getTransactionID(t.getServerName());
            QuerySelect sqlString = foundset.getQuerySelectForReading();
            // $NON-NLS-1$
            QuerySelect selectCountSQLString = sqlString.getSelectCount("n", true);
            IDataSet set = ds.performQuery(application.getClientID(), t.getServerName(), transaction_id, selectCountSQLString, null, getTableFilterParams(t.getServerName(), selectCountSQLString), false, 0, 10, IDataServer.FOUNDSET_LOAD_QUERY);
            if (Debug.tracing()) {
                Debug.trace(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                "Foundset count time: " + (System.currentTimeMillis() - time) + " thread: " + Thread.currentThread().getName() + ", SQL: " + selectCountSQLString.toString());
            }
            if (set.getRowCount() > 0) {
                Object[] row = set.getRow(0);
                if (row.length > 0) {
                    return Utils.getAsInteger(row[0]);
                }
            }
        } catch (Exception e) {
            Debug.error(e);
        }
    }
    return -1;
}
Also used : BaseQueryTable(com.servoy.base.query.BaseQueryTable) Table(com.servoy.j2db.persistence.Table) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) QuerySelect(com.servoy.j2db.query.QuerySelect) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) MarshallException(org.jabsorb.serializer.MarshallException) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

Table (com.servoy.j2db.persistence.Table)43 ITable (com.servoy.j2db.persistence.ITable)27 QueryTable (com.servoy.j2db.query.QueryTable)26 RepositoryException (com.servoy.j2db.persistence.RepositoryException)23 BaseQueryTable (com.servoy.base.query.BaseQueryTable)22 Column (com.servoy.j2db.persistence.Column)21 ServoyException (com.servoy.j2db.util.ServoyException)17 QueryColumn (com.servoy.j2db.query.QueryColumn)16 QuerySelect (com.servoy.j2db.query.QuerySelect)16 ArrayList (java.util.ArrayList)16 RemoteException (java.rmi.RemoteException)14 ApplicationException (com.servoy.j2db.ApplicationException)13 IColumn (com.servoy.j2db.persistence.IColumn)10 IBaseColumn (com.servoy.base.persistence.IBaseColumn)9 IServer (com.servoy.j2db.persistence.IServer)7 Relation (com.servoy.j2db.persistence.Relation)7 HashMap (java.util.HashMap)7 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)6 SafeArrayList (com.servoy.j2db.util.SafeArrayList)6 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)5