001/**
002 * Copyright 2014 The Sculptor Project Team, including the original
003 * author or authors.
004 * 
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 * 
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.sculptor.generator.cartridge.mongodb;
018
019import com.google.common.base.Objects;
020import javax.inject.Inject;
021import org.eclipse.xtext.xbase.lib.Extension;
022import org.sculptor.generator.cartridge.mongodb.MongoDbProperties;
023import org.sculptor.generator.chain.ChainOverride;
024import org.sculptor.generator.ext.DbHelper;
025import sculptormetamodel.NamedElement;
026
027@ChainOverride
028@SuppressWarnings("all")
029public class DbHelperExtension extends DbHelper {
030  @Inject
031  @Extension
032  private MongoDbProperties mongoDbProperties;
033  
034  @Override
035  public String getDefaultDatabaseName(final NamedElement element) {
036    DbHelper headObj = getMethodsDispatchHead()[org.sculptor.generator.ext.DbHelperMethodIndexes.GETDEFAULTDATABASENAME_NAMEDELEMENT];
037    return headObj._chained_getDefaultDatabaseName(element);
038  }
039  
040  public DbHelperExtension(final DbHelper next, final DbHelper[] methodsDispatchNext) {
041    super(next);
042  }
043  
044  public String _chained_getDefaultDatabaseName(final NamedElement element) {
045    String _xifexpression = null;
046    boolean _and = false;
047    boolean _mongoDb = this.mongoDbProperties.mongoDb();
048    if (!_mongoDb) {
049      _and = false;
050    } else {
051      String _name = element.getName();
052      boolean _equals = Objects.equal(_name, "id");
053      _and = _equals;
054    }
055    if (_and) {
056      _xifexpression = "_id";
057    } else {
058      DbHelper _next = this.getNext();
059      _xifexpression = _next.getDefaultDatabaseName(element);
060    }
061    return _xifexpression;
062  }
063  
064  public DbHelper[] _getOverridesDispatchArray() {
065    org.sculptor.generator.ext.DbHelper[] result = new org.sculptor.generator.ext.DbHelper[org.sculptor.generator.ext.DbHelperMethodIndexes.NUM_METHODS];
066    result[org.sculptor.generator.ext.DbHelperMethodIndexes.GETDEFAULTDATABASENAME_NAMEDELEMENT] = this; 
067    return result;
068  }
069}