Package org.xorm.datastore

Examples of org.xorm.datastore.Table


        List tables = root.getChildren("table");
        Iterator i = tables.iterator();
        while (i.hasNext()) {
            Element element = (Element) i.next();
            String tableName = element.getAttributeValue("name");
            Table table = new Table(tableName);
            nameToTable.put(tableName, table);
            List columns = element.getChildren("column");
            Iterator j = columns.iterator();
            while (j.hasNext()) {
                Element colElement = (Element) j.next();
                Column column = new Column(table, colElement.getAttributeValue("name"));
                if ("true".equalsIgnoreCase(colElement.getAttributeValue("primary-key"))) {
                    table.setPrimaryKey(column);
                }
                if ("true".equalsIgnoreCase(colElement.getAttributeValue("read-only"))) {
                    column.setReadOnly(true);
                }
                if ("true".equalsIgnoreCase(colElement.getAttributeValue("non-null"))) {
View Full Code Here


    }

    // CRUD methods
    public void create(Row row)  {
  onlyDidReads = false;
  Table table = row.getTable();
  Column primaryKey = table.getPrimaryKey();

  Element element = new Element(table.getName());
  row.setValue(primaryKey, element);

  Iterator it = table.getColumns().iterator();
  while (it.hasNext()) {
      Column c = (Column) it.next();
      setValue(element, c, row.getValue(c), true);
  }
  // If the newly created element is unattached at this point,
View Full Code Here

        System.out.println("HeapDriver: select " + selector);
        // Assumes we're dealing with a PK selector, not fully implemented.
        ArrayList list = new ArrayList();
        if (selector.getCondition() instanceof SimpleCondition) {
            SimpleCondition condition = (SimpleCondition) selector.getCondition();
            Table table = selector.getTable();
            Object primaryKey = condition.getValue();
            Row found = factory.getCache().get(table, primaryKey);
            if (found != null) {
                list.add((Row) found.clone());
            }
View Full Code Here

  }
    }

    public void update(Row row) {
  onlyDidReads = false;
  Table table = row.getTable();
  Column primaryKey = table.getPrimaryKey();

  Element element = (Element) row.getValue(primaryKey);
  Iterator it = table.getColumns().iterator();
  while (it.hasNext()) {
      Column c = (Column) it.next();
      if (row.isDirty(c)) {
    setValue(element, c, row.getValue(c), false);
      }
View Full Code Here

  }
    }

    public void delete(Row row) {
  onlyDidReads = false;
  Table table = row.getTable();
  Column primaryKey = table.getPrimaryKey();

  Element element = (Element) row.getValue(primaryKey);
  element.detach();
  // TODO: deal with cascaded delete ramifications on the cache
    }
View Full Code Here

  // TODO: deal with cascaded delete ramifications on the cache
    }

    public Collection select(Selector selector, Set extraRows) {
  Condition condition = selector.getCondition();
  Table table = selector.getTable();
  Collection xmlResults = null;
  if (condition == null) {
      xmlResults = new ArrayList();
      xmlResults.add(deriveValue(document.getRootElement(), table.getName()));
  } else if (condition instanceof SimpleCondition) {
      SimpleCondition sc = (SimpleCondition) condition;
      Column column = sc.getColumn();
      Object value = sc.getValue();

      // ".." == (Element) means get all children of an element
      // with an element name matching the table name.

      if ("..".equals(column.getName()) && (value instanceof Element)) {
    Element parent = (Element) value;
    xmlResults =  parent.getChildren(table.getName());
      }
  }

  // Populate the rows
  ArrayList rows = new ArrayList();
View Full Code Here

     * DatastoreDriver.read().  If no matching row is found,
     * JDOObjectNotFoundException is thrown.  Called from lookup() and from
     * InterfaceInvocationHandler.refresh().
     */
    Row lookupRow(ClassMapping classMapping, Object primaryKey) {
        Table table = classMapping.getTable();

        boolean useNontrans = useNontransactionalRead();

        // 1. Look in cache
        Row row = getFromCache(table, primaryKey);
        if (row == null) {

            // 2. Look in datastore

            // Get the DataFetchGroup to use.
            DataFetchGroup dfg = factory.getFetchGroupManager()
                .getDataFetchGroup(classMapping);
            Selector selector = new Selector
                (table,
                 new SimpleCondition(table.getPrimaryKey(),
                                     Operator.EQUAL,
                                     primaryKey));
            selector.require(dfg);
            Collection rows = selectRows(selector);
            if (!rows.isEmpty()) {
View Full Code Here

    /**
     * Refreshes particular fields of a Row from the datastore.
     * This method does not affect the cache.
     */
    void refreshColumns(Row row, DataFetchGroup dfg) {
        Table table = row.getTable();
        boolean useNontrans = useNontransactionalRead();

        Collection rows = null;
        try {
            if (useNontrans) {
                ((TransactionImpl) currentTransaction()).begin(true);
            }
            Object primaryKey = row.getPrimaryKeyValue();
            Selector selector = new Selector
                (table,
                 new SimpleCondition(table.getPrimaryKey(),
                                     Operator.EQUAL,
                                     primaryKey));
            selector.require(dfg);
            Set extraRows = new HashSet();
            rows = ((TransactionImpl) currentTransaction()).getDriver()
View Full Code Here

            Set extraRows = new HashSet();
            rows = ((TransactionImpl) currentTransaction()).getDriver()
                .select(selector, extraRows);

            // Put rows in the 2nd-level cache
            Table table = selector.getTable();
            addToCache(rows);

            // Put extraRows in the cache too
            addToCache(extraRows);
        } catch (DriverException e) {
View Full Code Here

        // Look up the backing row in the datastore
        InterfaceInvocationHandler handler = InterfaceInvocationHandler.getHandler(object);
 
        ClassMapping mapping = handler.getClassMapping();
        Table table = mapping.getTable();

        // Look in datastore
        Row row = null;

        DataFetchGroup dfg = new DataFetchGroup(table.getColumns());
        Selector selector = new Selector
            (table,
             new SimpleCondition(table.getPrimaryKey(),
                                 Operator.EQUAL,
                                 handler.getObjectId()));
        selector.require(dfg);
        Collection rows = selectRows(selector);
        if (!rows.isEmpty()) {
View Full Code Here

TOP

Related Classes of org.xorm.datastore.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.