Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 Erik Bengtson and others. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Contributors: ... /
 
 package org.datanucleus.store.json.fieldmanager;
 
 import java.util.Date;
 
FieldManager for inserting data into JSON.
 
 public class InsertFieldManager implements FieldManager
 {
     StateManager sm;
     JSONObject jsonobj;
 
     public InsertFieldManager(StateManager smJSONObject jsonobj)
     {
         this. = sm;
         this. = jsonobj;
         try
         {
             jsonobj.put("class"sm.getClassMetaData().getFullClassName());
         }
         catch (JSONException e)
         {
             throw new NucleusException(e.getMessage(), e);
         }
     }
 
     public String fetchStringField(int fieldNumber)
     {
         return null;
     }
 
     public short fetchShortField(int fieldNumber)
     {
         return 0;
     }
 
     public Object fetchObjectField(int fieldNumber)
     {
         return null;
     }
 
     public long fetchLongField(int fieldNumber)
     {
         return 0;
     }
 
     public int fetchIntField(int fieldNumber)
     {
         return 0;
     }
 
     public float fetchFloatField(int fieldNumber)
     {
         return 0;
     }
 
     public double fetchDoubleField(int fieldNumber)
     {
         return 0;
     }
 
     public char fetchCharField(int fieldNumber)
     {
         return 0;
     }
 
     public byte fetchByteField(int fieldNumber)
     {
         return 0;
     }
 
     public boolean fetchBooleanField(int fieldNumber)
    {
        return false;
    }
    public void storeStringField(int fieldNumberString value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            if(value==null)
            {
                .put(name.);
            }
            else
            {
                .put(namevalue);
            }
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeShortField(int fieldNumbershort value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(name, (int)value);
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeObjectField(int fieldNumberObject value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            if (value==null)
            {
                .put(name.);
            }
            else
            {
                if (value instanceof Date)
                {
                    .put(name, ((Date)value).getTime());
                }
                else if (value instanceof Calendar)
                {
                    .put(name, ((Calendar)value).getTimeInMillis());
                }
                else if (value instanceof BigDecimal)
                {
                    .put(namevalue);
                }
                else if (value instanceof BigInteger)
                {
                    .put(namevalue);
                }
                else
                {
                    JSONObject jsonobjfield = new JSONObject(value);
                    jsonobjfield.put("class"value.getClass().getName());
                    .put(namejsonobjfield);
                }
            }
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeLongField(int fieldNumberlong value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(name, (long)value);
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeIntField(int fieldNumberint value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(name, (int)value);
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeFloatField(int fieldNumberfloat value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(name, (double)value);
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeDoubleField(int fieldNumberdouble value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(name, (double)value);
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeCharField(int fieldNumberchar value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(namenew Character(value));
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeByteField(int fieldNumberbyte value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(name, (int)value);
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
    public void storeBooleanField(int fieldNumberboolean value)
    {
        String name = mmd.getName();
        if (mmd.hasExtension("member-name"))
        {
            name = mmd.getValueForExtension("member-name");
        }
        try
        {
            .put(name, (boolean)value);
        }
        catch (JSONException e)
        {
            throw new NucleusException(e.getMessage(), e);
        }
    }
New to GrepCode? Check out our FAQ X