Examples of ProtectionManager


Examples of org.conserve.tools.protection.ProtectionManager

    arrayLoader.loadArray(databaseId);
    String ownerTable = arrayLoader.getRelationalTableName();
    Class<?> componentType = arrayLoader.getArray().getClass()
        .getComponentType();
    // List all members of the existing array
    ProtectionManager protecter = adapter.getPersist()
        .getProtectionManager();
    for (int x = 0; x < arrayLoader.getLength(); x++)
    {
      Object component = arrayLoader.getEntry(x);
      // if they are non-primitive
      if (!ObjectTools.isPrimitive(component.getClass()))
      {
        // unprotect them
        Long ownerId = arrayLoader.getRelationalIds().get(x);
        String propertyTable = NameGenerator.getTableName(component,
            adapter);
        Long propertyId = adapter.getPersist().getId(component);
        protecter.unprotectObjectInternal(ownerTable, ownerId,
            propertyTable, propertyId, cw);
        if (!protecter.isProtected(propertyTable, propertyId, cw)
            && !nuIds.contains(new TableId(propertyTable,
                propertyId)))
        {
          // Delete them if they have no other protection
          adapter.getPersist().deleteObject(component.getClass(),
View Full Code Here

Examples of org.conserve.tools.protection.ProtectionManager

    adapter = selectAdapter(connectionstring);
    LOGGER.fine("Selected adapter: "
        + ObjectTools.getSystemicName(adapter.getClass())
        + " for connection " + connectionstring);
    // set up a new protection manager
    protectionManager = new ProtectionManager();
    // set up the object responsible for updating objects
    updater = new Updater(adapter);

    arrayEntryWriter = new ArrayEntryWriter(adapter);
View Full Code Here

Examples of org.conserve.tools.protection.ProtectionManager

    PreparedStatement ps = cw.prepareStatement(statement.toString());
    ps.setString(1, tableName);
    ps.setString(2, colName);
    Tools.logFine(ps);
    ResultSet rs = ps.executeQuery();
    ProtectionManager pm = adapter.getPersist().getProtectionManager();
    while (rs.next())
    {
      // get data on one instance
      Long ownerId = rs.getLong(1);
      String propertyTable = rs.getString(2);
      Long propertyId = rs.getLong(3);
      String propertyClassName = rs.getString(4);
      // check compability
      if (!ObjectTools.isA(ObjectTools.lookUpClass(propertyClassName), returnType))
      {
        // remove protection
        pm.unprotectObjectInternal(tableName, ownerId, propertyTable, propertyId, cw);
        // if entity is unprotected,
        if (!pm.isProtected(propertyClassName, propertyId, cw))
        {
          // then delete the entity
          adapter.getPersist().deleteObject(ObjectTools.lookUpClass(propertyClassName), propertyId, cw);
        }
      }
View Full Code Here

Examples of org.conserve.tools.protection.ProtectionManager

    PreparedStatement ps = cw.prepareStatement(statement.toString());
    ps.setString(1, tableName);
    ps.setString(2, column);
    Tools.logFine(ps);
    ResultSet rs = ps.executeQuery();
    ProtectionManager pm = adapter.getPersist().getProtectionManager();
    while (rs.next())
    {
      // get data on one instance
      Long ownerId = rs.getLong(1);
      String propertyTable = rs.getString(2);
      Long propertyId = rs.getLong(3);
      String propertyClassName = rs.getString(4);
      // remove protection
      pm.unprotectObjectInternal(tableName, ownerId, propertyTable, propertyId, cw);
      // if entity is unprotected,
      if (!pm.isProtected(propertyClassName, propertyId, cw))
      {
        // then delete the entity
        adapter.getPersist().deleteObject(propertyTable, propertyId, cw);
      }
    }
View Full Code Here

Examples of org.conserve.tools.protection.ProtectionManager

   */
  public void addArrayEntries(ConnectionWrapper cw, Long arrayId,
      Object array, DelayedInsertionBuffer delayBuffer)
      throws SQLException
  {
    ProtectionManager protectionManager = adapter.getPersist()
        .getProtectionManager();
    Class<?> compType = array.getClass().getComponentType();
    // the table name for the relation entries
    String tableName = NameGenerator.getArrayMemberTableName(compType,
        adapter);
    // create the statement
    StringBuilder builder = new StringBuilder("INSERT INTO ");
    builder.append(tableName);
    builder.append("(");
    builder.append(Defaults.ARRAY_MEMBER_ID);
    builder.append(",");
    builder.append(Defaults.ARRAY_POSITION);
    builder.append(",");
    builder.append(Defaults.VALUE_COL);
    builder.append(",");
    builder.append(Defaults.COMPONENT_CLASS_COL);
    builder.append(")values(?,?,?,?)");
    String statement = builder.toString();
    int length = Array.getLength(array);
    // iterate over all the elements
    for (int x = 0; x < length; x++)
    {
      PreparedStatement ps = cw.prepareStatement(statement);
      ps.setLong(1, arrayId);
      ps.setInt(2, x);
      Object value = Array.get(array, x);
      if (ObjectTools.isPrimitive(compType))
      {
        // The array entry is a primitive type, add it directly
        Tools.setParameter(ps, compType, 3, value);
        ps.setString(4, ObjectTools.getSystemicName(compType));
        Tools.logFine(ps);
        ps.execute();
        ps.close();
        // get the new id of the __ARRAY_MEMBER entry
        long memberId = adapter.getPersist().getLastId(cw, tableName);
        // add a protection entry for the __ARRAY table
        protectionManager.protectObjectInternal(
            Defaults.ARRAY_TABLE_NAME, arrayId,null, NameGenerator
                .getArrayMemberTableName(compType, adapter),
            memberId, ObjectTools.getSystemicName(Array.get(array,
                x).getClass()), cw);

      }
      else
      {
        // this is another type of object, insert a reference
        ps.setString(4, ObjectTools.getSystemicName(value.getClass()));
        Long valueId = adapter.getPersist().saveObjectUnprotected(cw,
            value, delayBuffer);
        long memberId = 0;
        if (valueId == null)
        {
          // This means the object exists, either independently
          // or as part of another array.
          ps.setNull(3, java.sql.Types.BIGINT);
          Tools.logFine(ps);
          // save the object
          ps.execute();
          ps.close();
          // get the new id of the __ARRAY_MEMBER entry
          memberId = adapter.getPersist().getLastId(cw, tableName);
          // this is a circularly referenced object
          // mark it for later insertion
          delayBuffer.add(tableName, Defaults.VALUE_COL, memberId,
              value, compType,System.identityHashCode(array));
        }
        else
        {
          ps.setLong(
              3,
              adapter.getPersist().getCastId(compType,
                  value.getClass(), valueId, cw));
          Tools.logFine(ps);

          // save the object
          ps.execute();
          ps.close();
          // get the new id of the __ARRAY_MEMBER entry
          memberId = adapter.getPersist().getLastId(cw, tableName);
        }

        String valueClassName = null;
        String propertyName = Defaults.ARRAY_TABLE_NAME;
        // add a protection entry for the __ARRAY table
        if (!compType.isArray())
        {
          valueClassName = ObjectTools.getSystemicName(value
              .getClass());
          propertyName = NameGenerator
              .getTableName(compType, adapter);
        }
        if (valueId != null)
        {
          // protect the object with array-member table as owner
          protectionManager
              .protectObjectInternal(tableName, memberId,null,
                  propertyName, valueId, valueClassName, cw);
        }
        // protect the array-member with array as owner
        protectionManager.protectObjectInternal(
            Defaults.ARRAY_TABLE_NAME, arrayId, null,tableName,
            memberId, valueClassName, cw);

      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.