Home | History | Annotate | Download | only in indexeddb
      1 /*
      2  * Copyright (C) 2012 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  * 1.  Redistributions of source code must retain the above copyright
      9  *     notice, this list of conditions and the following disclaimer.
     10  * 2.  Redistributions in binary form must reproduce the above copyright
     11  *     notice, this list of conditions and the following disclaimer in the
     12  *     documentation and/or other materials provided with the distribution.
     13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     14  *     its contributors may be used to endorse or promote products derived
     15  *     from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef IDBMetadata_h
     30 #define IDBMetadata_h
     31 
     32 #include "modules/indexeddb/IDBKeyPath.h"
     33 #include "wtf/HashMap.h"
     34 #include "wtf/text/StringHash.h"
     35 #include "wtf/text/WTFString.h"
     36 
     37 namespace WebCore {
     38 
     39 struct IDBIndexMetadata {
     40     IDBIndexMetadata() { }
     41     IDBIndexMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
     42         : name(name)
     43         , id(id)
     44         , keyPath(keyPath)
     45         , unique(unique)
     46         , multiEntry(multiEntry) { }
     47     String name;
     48     int64_t id;
     49     IDBKeyPath keyPath;
     50     bool unique;
     51     bool multiEntry;
     52 
     53     static const int64_t InvalidId = -1;
     54 };
     55 
     56 struct IDBObjectStoreMetadata {
     57     IDBObjectStoreMetadata() { }
     58     IDBObjectStoreMetadata(const String& name, int64_t id, const IDBKeyPath& keyPath, bool autoIncrement, int64_t maxIndexId)
     59         : name(name)
     60         , id(id)
     61         , keyPath(keyPath)
     62         , autoIncrement(autoIncrement)
     63         , maxIndexId(maxIndexId)
     64     {
     65     }
     66     String name;
     67     int64_t id;
     68     IDBKeyPath keyPath;
     69     bool autoIncrement;
     70     int64_t maxIndexId;
     71 
     72     static const int64_t InvalidId = -1;
     73 
     74     typedef HashMap<int64_t, IDBIndexMetadata> IndexMap;
     75     IndexMap indexes;
     76 
     77 };
     78 
     79 struct IDBDatabaseMetadata {
     80     // FIXME: These can probably be collapsed into 0.
     81     enum {
     82         NoIntVersion = -1,
     83         DefaultIntVersion = 0
     84     };
     85 
     86     typedef HashMap<int64_t, IDBObjectStoreMetadata> ObjectStoreMap;
     87 
     88     IDBDatabaseMetadata()
     89         : intVersion(NoIntVersion)
     90     {
     91     }
     92     IDBDatabaseMetadata(const String& name, int64_t id, const String& version, int64_t intVersion, int64_t maxObjectStoreId)
     93         : name(name)
     94         , id(id)
     95         , version(version)
     96         , intVersion(intVersion)
     97         , maxObjectStoreId(maxObjectStoreId)
     98     {
     99     }
    100 
    101     String name;
    102     int64_t id;
    103     String version;
    104     int64_t intVersion;
    105     int64_t maxObjectStoreId;
    106 
    107     ObjectStoreMap objectStores;
    108 };
    109 
    110 }
    111 
    112 #endif // IDBMetadata_h
    113