001/**
002 * Copyright 2013 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 javax.inject.Inject;
020import org.eclipse.xtend2.lib.StringConcatenation;
021import org.eclipse.xtext.xbase.lib.Extension;
022import org.sculptor.generator.cartridge.mongodb.MongoDbAccessObjectFactoryTmpl;
023import org.sculptor.generator.chain.ChainOverride;
024import org.sculptor.generator.ext.Properties;
025import org.sculptor.generator.template.repository.RepositoryTmpl;
026import sculptormetamodel.Repository;
027
028@ChainOverride
029@SuppressWarnings("all")
030public class RepositoryTmplExtension extends RepositoryTmpl {
031  @Inject
032  private MongoDbAccessObjectFactoryTmpl mongoDbAccessObjectFactoryTmpl;
033  
034  @Inject
035  @Extension
036  private Properties properties;
037  
038  @Override
039  public String extraRepositoryBaseDependencies(final Repository it) {
040    RepositoryTmpl headObj = getMethodsDispatchHead()[org.sculptor.generator.template.repository.RepositoryTmplMethodIndexes.EXTRAREPOSITORYBASEDEPENDENCIES_REPOSITORY];
041    return headObj._chained_extraRepositoryBaseDependencies(it);
042  }
043  
044  @Override
045  public String accessObjectFactory(final Repository it) {
046    RepositoryTmpl headObj = getMethodsDispatchHead()[org.sculptor.generator.template.repository.RepositoryTmplMethodIndexes.ACCESSOBJECTFACTORY_REPOSITORY];
047    return headObj._chained_accessObjectFactory(it);
048  }
049  
050  private String dbManagerDependency(final Repository it) {
051    StringConcatenation _builder = new StringConcatenation();
052    _builder.append("@org.springframework.beans.factory.annotation.Autowired");
053    _builder.newLine();
054    _builder.append("private ");
055    String _fw = this.properties.fw("accessimpl.mongodb.DbManager");
056    _builder.append(_fw, "");
057    _builder.append(" dbManager;");
058    _builder.newLineIfNotEmpty();
059    _builder.newLine();
060    _builder.append("protected ");
061    String _fw_1 = this.properties.fw("accessimpl.mongodb.DbManager");
062    _builder.append(_fw_1, "");
063    _builder.append(" getDbManager() {");
064    _builder.newLineIfNotEmpty();
065    _builder.append("\t");
066    _builder.append("return dbManager;");
067    _builder.newLine();
068    _builder.append("}");
069    _builder.newLine();
070    return _builder.toString();
071  }
072  
073  public RepositoryTmplExtension(final RepositoryTmpl next, final RepositoryTmpl[] methodsDispatchNext) {
074    super(next);
075  }
076  
077  public String _chained_extraRepositoryBaseDependencies(final Repository it) {
078    StringConcatenation _builder = new StringConcatenation();
079    String _dbManagerDependency = this.dbManagerDependency(it);
080    _builder.append(_dbManagerDependency, "");
081    _builder.newLineIfNotEmpty();
082    RepositoryTmpl _next = this.getNext();
083    String _extraRepositoryBaseDependencies = _next.extraRepositoryBaseDependencies(it);
084    _builder.append(_extraRepositoryBaseDependencies, "");
085    _builder.newLineIfNotEmpty();
086    return _builder.toString();
087  }
088  
089  public String _chained_accessObjectFactory(final Repository it) {
090    StringConcatenation _builder = new StringConcatenation();
091    RepositoryTmpl _next = this.getNext();
092    String _accessObjectFactory = _next.accessObjectFactory(it);
093    _builder.append(_accessObjectFactory, "");
094    _builder.newLineIfNotEmpty();
095    String _additionalDataMappers = this.mongoDbAccessObjectFactoryTmpl.getAdditionalDataMappers(it);
096    _builder.append(_additionalDataMappers, "");
097    _builder.newLineIfNotEmpty();
098    String _ensureIndex = this.mongoDbAccessObjectFactoryTmpl.ensureIndex(it);
099    _builder.append(_ensureIndex, "");
100    _builder.newLineIfNotEmpty();
101    return _builder.toString();
102  }
103  
104  public RepositoryTmpl[] _getOverridesDispatchArray() {
105    org.sculptor.generator.template.repository.RepositoryTmpl[] result = new org.sculptor.generator.template.repository.RepositoryTmpl[org.sculptor.generator.template.repository.RepositoryTmplMethodIndexes.NUM_METHODS];
106    result[org.sculptor.generator.template.repository.RepositoryTmplMethodIndexes.EXTRAREPOSITORYBASEDEPENDENCIES_REPOSITORY] = this; 
107    result[org.sculptor.generator.template.repository.RepositoryTmplMethodIndexes.ACCESSOBJECTFACTORY_REPOSITORY] = this; 
108    return result;
109  }
110}