Package nexj.core.rpc.file

Examples of nexj.core.rpc.file.FileConnection


      if (s_logger.isDebugEnabled())
      {
         s_logger.debug("Creating new connection");
      }

      FileConnection connection = ((FileStorageConnectionFactory)fragment.getConnectionFactory()
         .getInstance(m_context)).getConnection(this);

      if (!connection.attachToFile(sDataFile))
      {
         throw new PersistenceException("err.persistence.file.io");
      }

      return connection;
View Full Code Here


         s_logger.debug("Executing on file: " + sDataFile);
      }
     
     
      //Get the connection to use
      FileConnection connection = m_adapter.getConnection((FileDataSourceFragment)getFragment(), sDataFile);

      try
      {
         //Check for optimistic lock violation
         if (m_nType == UPDATE || m_nType == DELETE)
         {
            Object lockValue = m_instance.getOldValueDirect(lockAttrib.getOrdinal());
            long lCurrentLockValue = connection.getLastModified();
           
            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("LOCKING " + ( (((Long)lockValue).longValue() < lCurrentLockValue) ? "BAD" : "GOOD") + " instance=" + lockValue + " file=" + lCurrentLockValue);
            }
           
            if (((Long)lockValue).longValue() < lCurrentLockValue)
            {
               throw new OptimisticLockException(m_instance);
            }
         }
        
         Object dataToWrite = null;
        
         if (m_nType == INSERT || m_nType == UPDATE)
         {
            Metaclass metaclass = m_instance.getMetaclass();
           
            for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; i++)
            {
               Attribute attribute = metaclass.getInstanceAttribute(i);
               AttributeMapping attributeMapping = m_mapping.getAttributeMapping(attribute);
              
               if (attributeMapping == null)
               {
                  continue;
               }
              
               FilePrimitiveMapping mapping = (FilePrimitiveMapping)attributeMapping;
              
               if (mapping.getSysId() == FilePrimitiveMapping.SYSID_DATA)
               {
                  dataToWrite = m_instance.getValueDirect(i);
                  break;
               }
            }
           
            if (dataToWrite instanceof String)
            {
               connection.write((String)dataToWrite);
            }
            else if (dataToWrite instanceof Binary)
            {
               connection.write((Binary)dataToWrite);
            }
            else
            {
               throw new IllegalArgumentException("Data being written must be Binary or String");
            }
           
         }
         else if (m_nType == DELETE)
         {
            connection.delete();
         }
         else
         {
            throw new IllegalStateException("Unknown work type");
         }
     
         //Update the instance locking attribute
         if (m_nType == INSERT || m_nType == UPDATE)
         {
            /*
             * Do not modify instance locking attribute in DELETE case because that
             * will immediately set "locking" to zero and replication to fragments
             * will fail because they will see this zero value.
             */
           
            long lNewLockValue = connection.getLastModifiedThisTxn();
           
            m_instance.setValueDirect(lockAttrib.getOrdinal(),
               Primitive.createLong(lNewLockValue)
               );
         }
      }
      catch (IOException ex)
      {
         ObjUtil.rethrow(ex);
      }
      finally
      {
         connection.close();
      }
   }
View Full Code Here

TOP

Related Classes of nexj.core.rpc.file.FileConnection

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.